Cryptography

Signer key

The 64 bytes private signer key is a concatination whose last 32 bytes is the public key. A convenience function crypto_sign_ed25519_sk_to_pk() can also be used to extract this public key.

#included <sodium.h>

unsigned char skpk[crypto_sign_SECRETKEYBYTES]; // 64
unsigned char pk[crypto_sign_PUBLICKEYBYTES];   // 32
crypto_sign_keypair(pk, skpk);

unsigned char pubkey[crypto_sign_PUBLICKEYBYTES];
crypto_sign_ed25519_sk_to_pk(pubkey, skpk);

The value of the two arrays pubkey and pk should match.


Hash

We decide the hash h to be of size 13 bytes, and then compute the hash of the file.

#included <sodium.h>

std::ifstream f("c:/stuff/buf-64.dat", std::ios::binary);
std::vector<unsigned char> buf(std::istreambuf_iterator<char> {f}, {});

unsigned char h[13];
crypto_generichash(h, sizeof h, buf.data(), buf.size(), nullptr, 0);