EVP_PKEY_GET_SIZE(3SSL)

πŸ’– EVP_PKEY_GET_SIZE(3SSL) β€” the girlies' guide to pkey info functions πŸ’–

okay bestie, pull up a chair, because the manual page EVP_PKEY_GET_SIZE(3SSL) from the OpenSSL squad is here to answer the one question every key has been dying to be asked: "how big are you, actually?" πŸŽ€


✨ NAME ✨

EVP_PKEY_get_size, EVP_PKEY_get_bits, EVP_PKEY_get_security_bits, EVP_PKEY_bits, EVP_PKEY_security_bits, EVP_PKEY_get_security_category, EVP_PKEY_size β€” these are the EVP_PKEY information functions. literally just vibes-checking your key. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <openssl/evp.h>

int EVP_PKEY_get_size(const EVP_PKEY *pkey);
int EVP_PKEY_get_bits(const EVP_PKEY *pkey);
int EVP_PKEY_get_security_bits(const EVP_PKEY *pkey);
int EVP_PKEY_get_security_category(const EVP_PKEY *pkey);

#define EVP_PKEY_bits EVP_PKEY_get_bits
#define EVP_PKEY_security_bits EVP_PKEY_get_security_bits
#define EVP_PKEY_size EVP_PKEY_get_size

those last three? alias macros. same girl, different name. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

πŸ’« EVP_PKEY_get_size()

she returns the maximum suitable size for your output buffers β€” for almost all the operations you can do with pkey. this maps to the provider parameter OSSL_PKEY_PARAM_MAX_SIZE. the main documented usage is with EVP_SignFinal(3) and EVP_SealInit(3), but she is not limited to just those two. the returned size is also big enough for the output buffer of EVP_PKEY_sign(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3), and EVP_PKEY_derive(3). multi-talented. ate.

⚠️ okay this is the important part, no skipping: unless the docs for the operation you're actually performing say otherwise, the size EVP_PKEY_get_size() gives you is only preliminary and not exact. so the final contents of your target buffer may be smaller than that. which means it is crucial that you take note of the size handed back by the function that performs the operation β€” like EVP_PKEY_sign(3), where the siglen argument receives that length β€” or you're gonna get bugs. fr fr. 😭

πŸ’« EVP_PKEY_get_bits()

she returns the cryptographic length of the cryptosystem that the key in pkey belongs to, in bits. heads up: the definition of "cryptographic length" is specific to the key cryptosystem, so don't go assuming it means the same thing everywhere. this corresponds to the provider parameter OSSL_PKEY_PARAM_BITS. ✨

πŸ’« EVP_PKEY_get_security_bits()

she returns the number of security bits of the given pkey. "bits of security" is defined in NIST SP800-57. this corresponds to the provider parameter OSSL_PKEY_PARAM_SECURITY_BITS. iykyk. πŸ’œ

πŸ’« EVP_PKEY_get_security_category()

she returns the post-quantum security category as defined by NIST, over at <https://nvlpubs.nist.gov/nistpubs/ir/2024/NIST.IR.8547.ipd.pdf>. this category is an integer value from 0 to 5 that's based on an algorithm's classification on the range of security strengths offered by the existing standards in symmetric cryptography:

  • 0 β€” Weak
  • 1 β€” Key search on a block cipher with a 128-bit key
  • 2 β€” Collision search on a 256-bit hash function
  • 3 β€” Key search on a block cipher with a 192-bit key
  • 4 β€” Collision search on a 384-bit hash function
  • 5 β€” Key search on a block cipher with a 256-bit key

⭐ there's your attack-type cheat sheet, bestie. screenshot it. πŸ“Έ


πŸ”₯ RETURN VALUES πŸ”₯

  • EVP_PKEY_get_size(), EVP_PKEY_get_bits() and EVP_PKEY_get_security_bits() return a positive number, or 0 if this size isn't available. (yes, girl, sometimes she just doesn't have the info. it's not you.)
  • EVP_PKEY_get_security_category() returns the post-quantum security category, an integer in the range zero to five inclusive. she returns -1 if the security category information isn't available. and for all classical algorithms, 0 is returned β€” meaning they are not considered to be quantum safe. πŸ’€

🧚 NOTES 🧚

most functions that have an output buffer and get mentioned alongside EVP_PKEY_get_size() have this little superpower: you can pass NULL for the buffer, still pass a pointer to an integer, and get the exact size that this function call delivers in the context it's called in. which means you can call those functions twice:

  1. once to find out the exact buffer size πŸ•΅οΈ
  2. allocate the buffer in between πŸ› οΈ
  3. call that function again and actually output the data ✨

for those functions, calling EVP_PKEY_get_size() isn't strictly necessary to find out the buffer size β€” but it may be useful when you want to know the upper limit in advance. planning ahead? main character behaviour. πŸ‘‘

🚨 EXTRA IMPORTANT, do NOT skip this: EVP_PKEY_get_size() shouldn't be used to get the output size for EVP_DigestSignFinal(), according to "NOTES" in EVP_DigestSignFinal(3). read that one, bestie. i'm serious. 😀

🌈 SEE ALSO 🌈

go read all seven. yes, all of them. πŸ’–


πŸ‘‘ HISTORY πŸ‘‘

EVP_PKEY_bits(), EVP_PKEY_security_bits(), and EVP_PKEY_size() were renamed to include "get" in their names in OpenSSL 3.0, respectively. the old names are kept as non-deprecated alias macros β€” so they're not gone, they're just going by their government names now. 🫢

EVP_PKEY_get_security_category() was added in OpenSSL 3.6 β€” the newest baby of the family. 🍼


Copyright 2020-2026 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page, bestie!! πŸŽ€πŸ’…βœ¨

sign-off time: this was 4.0.3, dated 2026-09-29, and the page you just read is EVP_PKEY_GET_SIZE(3SSL). go forth and get yourself some correct buffer sizes. mwah. πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from