Deriving a key from a password programmatically
We are going to implement the kdf
program, which will derive a key from a password.
Our key derivation program will take two command-line arguments:
- Password
- Hex-encoded salt
We are not going to take the N
, r
, and brute-force-resistant Scrypt
parameters because because we want to simplify our example program and its usage. Instead, we are going to use OWASP-recommended settings.
OpenSSL 3.0 provides the following APIs for key derivation:
- The
PKCS5_PBKDF2_HMAC()
,PKCS5_PBKDF2_HMAC_SHA1()
, andEVP_PBE_scrypt()
legacy functions, specific to particular KDFs. - The
EVP_PKEY
API. This API is intended for use with asymmetric cryptography and contains theEVP_PKEY_derive()
function. That function is mostly intended for non-password-based key derivation during key exchange operations in secure network protocols, such as Diffie-Hellman key exchange, but also supports password-based key derivation using the Scrypt...