In evp.h, BytesToKey()
generates the key from the passhphrase, IV and the MD5 digest in order to decrypt information used by the public/private keypair generation using AES-256-CBC. I am trying to isolate all the EVP_* functions into a standalone implementation for an embedded system. Does anyone have the actual function or what exactly it does?
KEY DERIVATION ALGORITHM The key and IV is derived by concatenating D_1, D_2, etc until enough data is available for the key and IV. D_i is defined as:
D_i = HASH^count(D_(i-1) || data || salt)
openssl enc
are incompatible in how they convert password to key, and unless it's a new version and an option is given the hash is not even iterated. See this, which also links to the actual code. In other news, iterated SHA-256 (including PBKDF2 and whateveropenssl enc
does) is a poor way to use CPU time for password-to-key derivation, because GPUs, FPGAs and ASICs are so much better at it; so the way to go is a memory-hard key stretching function, like Argon2. $\endgroup$EVP_BytesToKey
externally (just a c program), using the IV from my private key and of course my passphrase and the same key was returned using MD5 as the digest. I am just looking for a function that does whatBytesToKey
does without actually using it because it depends on all these EVP functions and can't be implemented independently $\endgroup$enc
changed in 1.1.0 (up), but BytesToKey remains compatible if you specify the hash (and don't use pbkdf2 option); see my crypto.stackexchange.com/questions/3298/#35614 . But it sounds like this OP might want the encryption OpenSSL uses on 'traditional' (i.e. not PKCS8) privatekey files, which also uses BytesToKey but always with MD5 (no choice) and 1 iteration, and derives only the key whileenc
does both key and IV, and never uses PBKDF2. $\endgroup$OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
$\endgroup$