EVP_PKEY_GET_SIZE(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… EVP_PKEY_GET_SIZE πŸ’…

okay bestie, welcome to the EVP_PKEY information functions β€” this is the 3ossl page from the OpenSSL manual, and it's literally all about asking your key "hey, how big are you?" πŸŽ€


✨ NAME ✨

EVP_PKEY_get_size, EVP_PKEY_get_bits, EVP_PKEY_get_security_bits, EVP_PKEY_bits, EVP_PKEY_security_bits, EVP_PKEY_size β€” the EVP_PKEY information functions. it's giving "tell me about yourself" energy 🫢


🌸 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);

#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

πŸ¦‹ DESCRIPTION πŸ¦‹

so EVP_PKEY_get_size() returns the maximum suitable size for your output buffers β€” like, for almost all the operations you can do with pkey. it maps to the provider parameter OSSL_PKEY_PARAM_MAX_SIZE. the primary documented use is with EVP_SignFinal(3) and EVP_SealInit(3), but it's so not limited to those. 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). slay πŸ’…

⚠️ okay this part is important, no cap: unless the documentation for the operation you're doing says otherwise, the size from EVP_PKEY_get_size() is only preliminary, not exact β€” so the final contents of your target buffer may end up smaller. it's therefore crucial to take note of the size given back by the function that actually performs the operation, like EVP_PKEY_sign(3) (the siglen argument receives that length), to avoid bugs. don't skip this, fr fr 😭

EVP_PKEY_get_bits() returns the cryptographic length of the cryptosystem that the key in pkey belongs to, in bits. note that the definition of cryptographic length is specific to the key cryptosystem β€” iykyk. this length corresponds to the provider parameter OSSL_PKEY_PARAM_BITS. πŸ”₯

EVP_PKEY_get_security_bits() 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. iconic ⭐


πŸ’– 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. that's the whole vibe check πŸ™ˆ


🧚 NOTES 🧚

most functions that have an output buffer and are mentioned with EVP_PKEY_get_size() have a little trick: you can pass NULL for the buffer and still pass a pointer to an integer, and you'll get the exact size that this function call delivers in the context it's called in. bestie, this means you can call those functions twice β€” once to find out the exact buffer size, then allocate the buffer in between, then call the function again to actually output the data. sooo convenient πŸ“

for those functions, it isn't strictly necessary to call EVP_PKEY_get_size() to find out the buffer size, but it may be useful in cases where you want to know the upper limit in advance. lowkey handy πŸ’œ

🚨 also especially note: EVP_PKEY_get_size() shouldn't be used to get the output size for EVP_DigestSignFinal(), according to "NOTES" in EVP_DigestSignFinal(3). not me warning you twice πŸ’€

🌈 SEE ALSO 🌈


πŸ‘‘ HISTORY πŸ‘‘

the EVP_PKEY_bits(), EVP_PKEY_security_bits(), and EVP_PKEY_size() functions were renamed to include "get" in their names in OpenSSL 3.0, respectively. the old names are kept as non-deprecated alias macros β€” so your old code still works, we love a glow-up that doesn't break anything 🫢✨


Copyright 2020-2021 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 page, bestie πŸ’– this was OpenSSL 3.5.0, dated 2026-09-25 β€” EVP_PKEY_GET_SIZE(3ossl), signing off πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from