EVP_PKEY_SIZE(3)
okay bestie, welcome to EVP_PKEY_SIZE(3) from the Library Functions Manual β the page where we learn how big your buffers need to be so nothing gets messy π
β¨
β¨ NAME β¨
EVP_PKEY_size, EVP_PKEY_bits, EVP_PKEY_security_bits β the EVP_PKEY information functions, periodt. Thatβs the name vibe, and itβs iconic.
β¨ SYNOPSIS β¨
library βlibcryptoβ #include <openssl/evp.h>
int
EVP_PKEY_size(const EVP_PKEY *pkey);
int
EVP_PKEY_bits(const EVP_PKEY *pkey);
int
EVP_PKEY_security_bits(const EVP_PKEY *pkey);
β¨ DESCRIPTION β¨
okay so first up: EVP_PKEY_size() returns the maximum size in bytes needed for the output buffer for almost any operation that can be done with pkey. The primary use is with EVP_SignFinal(3) and EVP_SealInit(3). The returned size is also large enough for the output buffer of EVP_PKEY_sign(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3), and EVP_PKEY_derive(3).
Unless the documentation for the operation says otherwise, the size returned by EVP_PKEY_size() is only an upper limit and the final content of the target buffer may be smaller. It is therefore crucial to take note of the size given back by the function that performs the operation. For example, EVP_PKEY_sign(3) returns that length in the *siglen argument. bestie, do not ignore that returned length, fr fr π
lowkey important: usingEVP_PKEY_size()is discouraged withEVP_DigestSignFinal(3). Thatβs the fact, no cap.
Most functions using an output buffer support passing NULL for the buffer and a pointer to an integer to get the exact size that this function call delivers in the context that it is called in. This allows those functions to be called twice, once to find out the exact buffer size, then allocate the buffer in between, and call that function again to actually output the data. For those functions, it isnβt strictly necessary to call EVP_PKEY_size() to find out the buffer size, but it may still be useful in cases where itβs desirable to know the upper limit in advance. itβs giving βmeasure twice, allocate onceβ π
EVP_PKEY_size() is supported for the following algorithms β and yes, hereβs every single one, because we donβt skip details in this group chat:
CMACβ same result as from:EVP_MAX_BLOCK_LENGTH = 32DHβ same result as from:DH_size(3)DSAβ same result as from:DSA_size(3)ECβ same result as from:ECDSA_size(3)ED25519β64, but see belowHMACβ same result as from:EVP_MAX_MD_SIZE = 64RSAβ same result as from:RSA_size(3)X25519β same result as from:X25519_KEYLEN = 32
For EVP_PKEY_ED25519, the situation is special: while the key size is ED25519_KEYLEN = 32 bytes, EVP_PKEY_size() returns 64 because the signature is longer than the keys. not me getting emotional over a longer signature πβ¨
EVP_PKEY_bits() returns the cryptographic length of the cryptosystem to which the key in pkey belongs, in bits. The definition of cryptographic length is specific to the key cryptosystem. The following algorithms are supported:
DHβ cryptographic length = significant bits in the public domain parameterp; same result as from:DH_bits(3)DSAβ cryptographic length = significant bits in the public domain parameterp; same result as from:DSA_bits(3)ECβ cryptographic length = the order of the group; same result as from:EC_GROUP_order_bits(3)ED25519β cryptographic length =253; same result as from:βRSAβ cryptographic length = the public modulus; same result as from:RSA_bits(3)X25519β cryptographic length =253; same result as from:β
EVP_PKEY_security_bits() returns the security strength measured in bits of the given pkey as defined in NIST SP800-57. The following algorithms are supported:
DHβ same result as from:DH_security_bits(3)DSAβ same result as from:DSA_security_bits(3)ECβ same result as from:EC_GROUP_order_bits(3)divided by2ED25519β128RSAβ same result as from:RSA_security_bits(3)X25519β128
For EC keys, if the result is greater than 80, it is rounded down to 256, 192, 128, 112, or 80. rounding down but make it secure π
β¨ RETURN VALUES β¨
EVP_PKEY_size() and EVP_PKEY_bits() return a positive number or 0 if this size isnβt available.
EVP_PKEY_security_bits() returns a number in the range from 0 to 256 inclusive or -2 if this function is unsupported for the algorithm used by pkey. It returns 0 if pkey is NULL.
β¨ SEE ALSO β¨
EVP_PKEY_decrypt(3), EVP_PKEY_derive(3), EVP_PKEY_encrypt(3), EVP_PKEY_new(3), EVP_PKEY_sign(3), EVP_SealInit(3), EVP_SignFinal(3)
β¨ HISTORY β¨
EVP_PKEY_size() first appeared in SSLeay 0.6.0 and EVP_PKEY_bits() in SSLeay 0.9.0. Both functions have been available since OpenBSD 2.4.
EVP_PKEY_security_bits() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 7.2.
okay thatβs the whole page, bestie β source/version: Debian; date: June 8, 2025. byeee from the EVP_PKEY_SIZE(3) page, mwah πππ«Ά
π¦ 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) 2022, 2023 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2020 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms