EVP_PKEY_GET_SIZE(3ossl)
π EVP_PKEY_GET_SIZE π
okay so bestie, welcome to the OpenSSL manual, page EVP_PKEY_GET_SIZE(3ossl). This is where we talk about the little squad of EVP_PKEY information functions: EVP_PKEY_get_size, EVP_PKEY_get_bits, EVP_PKEY_get_security_bits, and their alias twins EVP_PKEY_bits, EVP_PKEY_security_bits, EVP_PKEY_size. They're like the β¨ vibe check β¨ for your key β how big is it, how strong is it, how much buffer do you need. let's go π¦
β¨ 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 πΈ
π
EVP_PKEY_get_size()
okay so this one returns the maximum suitable size for the output buffers of almost all operations you can do with pkey. like, it's giving "how much room should I set aside" energy. π
It corresponds to the provider parameter OSSL_PKEY_PARAM_MAX_SIZE.
The primary documented use is with EVP_SignFinal(3) and EVP_SealInit(3), but bestie it is 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). she's versatile, she ate. π
π¨ okay important, no cap: unless the documentation for the operation you're doing says otherwise, the size returned byEVP_PKEY_get_size()is only preliminary and not exact. so the final contents of the target buffer may be smaller. it is therefore crucial to take note of the size given back by the function that actually performs the operation β likeEVP_PKEY_sign(3), where thesiglenargument receives that length β to avoid bugs. literally do not skip this step, i'm begging π
β EVP_PKEY_get_bits()
returns the cryptographic length of the cryptosystem that the key in pkey belongs to, in bits. lowkey important note: the definition of cryptographic length is specific to the key cryptosystem. so don't go comparing across families like they're the same thing, they're not. π
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.
π«Ά 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 it, that's the whole vibe check. β¨
π NOTES π
Most functions that have an output buffer and are mentioned with EVP_PKEY_get_size() have a whole little trick where you can pass NULL for the buffer and still pass a pointer to an integer, and get the exact size that this function call delivers in the context it's called in. π€―
This lets those functions be called twice: once to find out the exact buffer size, then allocate the buffer in between, then call that function again to actually output the data. the two-call glow-up. π
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 it's desirable to know the upper limit in advance. like pre-gaming your allocation, iykyk.
β οΈ also, especially noted:EVP_PKEY_get_size()shouldn't be used to get the output size forEVP_DigestSignFinal(), according to "NOTES" inEVP_DigestSignFinal(3). so don't do it bestie, that's not the move π
π SEE ALSO π
provider-keymgmt(7)EVP_SignFinal(3)EVP_SealInit(3)EVP_PKEY_sign(3)EVP_PKEY_encrypt(3)EVP_PKEY_decrypt(3)EVP_PKEY_derive(3)
π°οΈ 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. so EVP_PKEY_bits β EVP_PKEY_get_bits, etc. β¨
The old names are kept as non-deprecated alias macros, so your old code still slays, no cap. π«Ά
π COPYRIGHT π
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 whole page, bestie!! π this was version 3.5.9, dated 2026-09-29, straight from the OpenSSL crew. go forth and allocate your buffers correctly, periodt. πβ¨π¦
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms