EVP_PKEY_GET...LT_DIGEST_NID(3ossl)
π EVP_PKEY_GET...LT_DIGEST_NID π
okay bestie, so this is a page from the OpenSSL manual, section 3ossl, and the whole vibe is: how do I find out which digest a key wants for signing? β¨ There's two functions here, EVP_PKEY_get_default_digest_nid and EVP_PKEY_get_default_digest_name, and they are literally the "what's your default signature digest, babe?" girlies. Let's get into it π
πΈ NAME πΈ
EVP_PKEY_get_default_digest_nid, EVP_PKEY_get_default_digest_name β get the default signature digest π«Ά
β¨ SYNOPSIS β¨
#include <openssl/evp.h>
int EVP_PKEY_get_default_digest_name(EVP_PKEY *pkey,
char *mdname, size_t mdname_sz);
int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid);
π¦ DESCRIPTION π¦
So EVP_PKEY_get_default_digest_name() is the one that fills in the default message digest name for the public key signature operations that go with the key pkey, and it drops that name into mdname β up to at most mdname_sz bytes, NUL terminator included, no cap π
And the name it gives you could literally be "UNDEF", which is the little code for "a digest must be left unspecified (that's return value 2) or may be left unspecified (that's return value 1)". Yes, it's giving cryptic. We love her anyway π
Then EVP_PKEY_get_default_digest_nid() sets pnid to the default message digest NID for the public key signature operations tied to key pkey. Okay so important heads-up bestie: some signature algorithms β I'm talking Ed25519 and Ed448 β do not use a digest during signing at all, no cap. In that case pnid gets set to NID_undef. π
Also this function is only reliable for legacy keys, which are keys that have an EVP_PKEY_ASN1_METHOD. Those keys have typically been loaded from engines, or created with EVP_PKEY_assign_RSA(3) or similar. So like, if you're on the new-school key types, don't come for her, she's not built for that π
π NOTES π
For all current standard OpenSSL public key algorithms, SHA256 is returned. Every single one. Periodt. π
π₯ RETURN VALUES π₯
Both EVP_PKEY_get_default_digest_name() and EVP_PKEY_get_default_digest_nid() return:
1β if the message digest is advisory, meaning other digests can still be used π«2β if the message digest is mandatory, meaning other digests can not be used, it's giving strict queen energy π
And for the fail girlies: they return 0 or a negative value for failure. In particular, a return value of -2 means the operation is not supported by the public key algorithm π
not me getting a -2 and being like "what did I do" π it's literally just unsupported bestie, it's not you
π«Ά SEE ALSO π«Ά
EVP_PKEY_CTX_new(3)EVP_PKEY_sign(3)EVP_PKEY_digestsign_supports_digest(3)EVP_PKEY_verify(3)EVP_PKEY_verify_recover(3)
π HISTORY π
This function was added in OpenSSL 1.0.0. She's been here since the olden days, an absolute icon of longevity π
β COPYRIGHT β
Copyright 2006-2023 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, ty for reading my little hyperfixation β¨ this was OpenSSL 3.5.9, dated 2026-09-2, and yeah the date is formatted like that, I don't make the rules π mwah π
π¦ 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