EVP_PKEY_ASN1_GET_COUNT(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… EVP_PKEY_ASN1_GET_COUNT(3) β€” like, the whole ASN.1 method roster

okay so bestie, this is a page from the Library Functions Manual and it's all about the libcrypto girlies who keep track of public key ASN.1 methods β€” the little descriptor objects (EVP_PKEY_ASN1_METHOD, aka ameth) that tell OpenSSL how each key type does its ASN.1 thing. We're literally just enumerating them, looking them up, and peeking inside. No cap, that's the whole vibe. πŸ¦‹


✨ NAME ✨

EVP_PKEY_asn1_get_count, EVP_PKEY_asn1_get0, EVP_PKEY_get0_asn1, EVP_PKEY_asn1_find, EVP_PKEY_asn1_find_str, EVP_PKEY_asn1_get0_info β€” enumerate public key ASN.1 methods πŸŽ€

🌸 SYNOPSIS 🌸

library β€œlibcrypto”

#include <openssl/evp.h>

int
EVP_PKEY_asn1_get_count(void);

const EVP_PKEY_ASN1_METHOD *
EVP_PKEY_asn1_get0(int idx);

const EVP_PKEY_ASN1_METHOD *
EVP_PKEY_get0_asn1(const EVP_PKEY *pkey);

const EVP_PKEY_ASN1_METHOD *
EVP_PKEY_asn1_find(ENGINE **engine, int type);

const EVP_PKEY_ASN1_METHOD *
EVP_PKEY_asn1_find_str(ENGINE **engine, const char *str, int len);

int
EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id,
    int *ppkey_flags, const char **pinfo, const char **ppem_str,
    const EVP_PKEY_ASN1_METHOD *ameth);

πŸ’– DESCRIPTION πŸ’–

So here's the tea on each one, mwah:

  • EVP_PKEY_asn1_get_count() β€” returns the number of public key ASN.1 methods available. Like a headcount for the group chat. πŸ‘‘
  • EVP_PKEY_asn1_get0() β€” returns the public key ASN.1 method at index idx. Btw the value of idx must be in the range from zero to EVP_PKEY_asn1_get_count() - 1. Stay in your lane, bestie, or it's not gonna go how you want. πŸ™ˆ
  • EVP_PKEY_asn1_find() β€” looks up the method with NID type, which can be any of the values that EVP_PKEY_base_id(3) and EVP_PKEY_id(3) may return. And listen: if engine is not NULL, then *engine is set to NULL. That's it, that's the whole engine situation. 🫢
  • EVP_PKEY_asn1_find_str() β€” looks up the method with the PEM type string given by the first len bytes of str. If len is -1, the strlen(3) of str is used instead (convenient, honestly πŸ’…). The PEM type strings supported by default are listed in the EVP_PKEY_base_id(3) manual page β€” go look, iykyk. Just like EVP_PKEY_asn1_find(), if engine is not NULL, *engine is set to NULL. Same energy. ✨
  • EVP_PKEY_asn1_get0_info() β€” retrieves the public key ID as returned by EVP_PKEY_id(3), the base public key ID as returned by EVP_PKEY_base_id(3) (both NIDs, fyi), any flags, and internal pointers owned by ameth pointing to its method description string and its PEM type string. It's giving "tell me everything about yourself." πŸ”₯

πŸŽ€ the flags bits πŸŽ€

The following flags bits can occur, OR'ed together in *ppkey_flags:

  • ASN1_PKEY_ALIAS β€” this ameth object serves as an alias for another EVP_PKEY_ASN1_METHOD object and will never be returned from EVP_PKEY_asn1_find() or EVP_PKEY_asn1_find_str(). It's the understudy, not the main character. πŸ’€
  • ASN1_PKEY_DYNAMIC β€” this flag is unused. It could formerly be used to mark an ameth object as dynamically allocated. So yeah, retired icon, we still respect it. 🌈
  • ASN1_PKEY_SIGPARAM_NULL β€” okay this one's a little more involved, stay with me: if the signing ctx uses an EVP_PKEY private key associated with this ameth, it instructs ASN1_item_sign_ctx(3) to use a parameter type of V_ASN1_NULL instead of the default V_ASN1_UNDEF when encoding the ASN.1 AlgorithmIdentifier objects with X509_ALGOR_set0(3). In particular, this is used for EVP_PKEY_RSA. Slay, RSA, we see you. πŸ‘‘

🌟 RETURN VALUES 🌟

  • EVP_PKEY_asn1_get_count() returns the number of available public key methods.
  • EVP_PKEY_asn1_get0() returns a public key method or NULL if idx is out of range.
  • EVP_PKEY_get0_asn1() returns the public key method used by pkey.
  • EVP_PKEY_asn1_find() and EVP_PKEY_asn1_find_str() return a matching public key method or NULL if no match is found.
  • EVP_PKEY_asn1_get0_info() returns 1 on success or 0 on failure.
ngl, NULL shows up a lot in these return values. That's not a bug, that's just what "didn't find it" looks like. 😭

πŸ¦‹ SEE ALSO πŸ¦‹

EVP_PKEY_base_id(3), EVP_PKEY_new(3)

⭐ HISTORY ⭐

These functions first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9. Vintage but make it iconic. πŸ’œ


and that's the whole page, bestie β€” sourced from Debian, dated June 8, 2025, filed under EVP_PKEY_ASN1_GET_COUNT(3). go forth and enumerate responsibly πŸ§šβ€β™€οΈπŸ’–

πŸ“¦ where this page comes from