EVP_BYTESTOKEY(3)
okay so this is the EVP_BYTESTOKEY(3) page from the Library Functions Manual, and we're about to make key-and-IV derivation make sense, bestie π Buckle up π
π NAME π
EVP_BytesToKey β password based encryption routine β¨
β¨ SYNOPSIS β¨
library βlibcryptoβ
#include <openssl/evp.h>
int
EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
const unsigned char *salt, const unsigned char *data, int datal,
int count, unsigned char *key, unsigned char *iv);
π¦ DESCRIPTION π¦
EVP_BytesToKey() is literally the βderive a key and IV from these parametersβ situation. Here's the cast, bestie:
typeβ the cipher to derive the key and IV for πmdβ the message digest to use π§saltβ used as a salt in the derivation. It should point to a buffer containingPKCS5_SALT_LEN = 8 bytes, or beNULLif no salt is used πΈdataβ a buffer containingdatalbytes, and it's used to derive the keying data πcountβ the iteration count to use πkeyandivβ the derived key and IV get written here, respectively π
A typical application of this function is deriving keying material for an encryption algorithm from a password in the data parameter. Password-to-key pipeline, iconic π
Increasing the count parameter slows down the algorithm, which makes it harder for an attacker to perform a brute force attack using a large number of candidate passwords. Slow it down so the attackers have a worse time, periodt π₯
Compatibility tea β: if the total key and IV length is less than the digest length and MD5 is used, then the derivation algorithm is compatible with PKCS#5 v1.5. Otherwise, a non-standard extension is used to derive the extra data. Yeah, it's giving legacy behavior.
π¨ Bestie, newer applications should use more standard algorithms such asPBKDF2as defined inPKCS#5v2.1for key derivation. Don't make this your main character unless you have to.
π KEY DERIVATION ALGORITHM π
The key and IV are derived by concatenating D_1, D_2, etc. until enough data is available for the key and IV. D_i is defined recursively as:
D_i = HASH^count(D_(i-1) || data || salt)
where || denotes concatenation, D_0 is empty, HASH is the digest algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data) is HASH(HASH(data)), and so on. Recursive little icon π
The initial bytes are used for the key and the subsequent bytes for the IV. That's the split, bestie βοΈ
π RETURN VALUES π
If data is NULL, EVP_BytesToKey() returns the number of bytes needed to store the derived key. Otherwise, EVP_BytesToKey() returns the size of the derived key in bytes or 0 on error. So: NULL data = βhow much room do I need?β vibe; normal data = actual derived-key size, or 0 if something went wrong π
π SEE ALSO π
π«Ά HISTORY π«Ά
EVP_BytesToKey() first appeared in SSLeay 0.5.1 and has been available since OpenBSD 2.4. Ancestor energy π
k bye β this page is from Debian, dated June 8, 2025. Stay hydrated and keep your keys cute, bestie πβ¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2001, 2011, 2013, 2014, 2015 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms