Why is the private signing key in lib sodium 64 bytes?

124 views Asked by At

To generate a keypair for signing in libsodium one can use (copied from documentation):

unsigned char pk[crypto_sign_PUBLICKEYBYTES];
unsigned char sk[crypto_sign_SECRETKEYBYTES];
crypto_sign_keypair(pk, sk);

crypto_sign_SECRETKEYBYTES resolves to crypto_sign_ed25519_SECRETKEYBYTES and the latter resolves to (32U + 32U).

When searching the internet for ed25519 private key length, it appears that the length should be 32 bytes.

Where does this discrepancy come from?

1

There are 1 answers

1
bohr On

It appears that the public key is attached to the private key.

For example the following code (using lazysodium in Kotlin):

    val ls = LazySodiumJava(SodiumJava())
    val keypair = ls.cryptoSignKeypair()

    println("pub: ${keypair.publicKey.asHexString}")
    println("pri: ${keypair.secretKey.asHexString}")

gives:

pub: 23C26D24834E1B83D529AB907AB1C85CE8FCAA91627E9FD189CBBF86DD390BBF
pri: 3914ECBF9E52F85DB05394D668B8E0D50B0F6424FAB80E182EBF481CE4FC4D3D23C26D24834E1B83D529AB907AB1C85CE8FCAA91627E9FD189CBBF86DD390BBF

The second part of the private key is exactly the public key.