Search code examples
encryptionlibsodiumnacl-cryptography

How does libsodium generate a keypair


For public key encryption and diffie-hellman in libsodium, I typically make private keys simply by generating 32 random bytes with randombytes_buf and then derive the public key (when needed) using crypto_scalarmult_base.

Is there any benefit to using crypto_box_keypair to generate a keypair (other than syntax)? Or does this function basically do exactly that?


Solution

  • This is exactly what the crypto_box_keypair() function does.

    The benefits of this function are clarity, and guarantee that the secret key is properly generated.