EVP_CIPHER_DO_ALL(3)

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

πŸ’… EVP_CIPHER_DO_ALL β€” bestie's guide to iterating lookup tables

okay so this is a libcrypto manpage, and honestly? it's giving "backstage tour of the cipher and digest closet." we're talking EVP_CIPHER_do_all, EVP_CIPHER_do_all_sorted, EVP_MD_do_all, EVP_MD_do_all_sorted, OBJ_NAME_do_all, and OBJ_NAME_do_all_sorted β€” the whole squad whose entire job is to walk over the lookup tables for ciphers and digests and call your callback on every single entry. no cap, that's it. πŸ¦‹


✨ SYNOPSIS ✨

you'll want the libcrypto library and this header, periodt:

#include <openssl/evp.h>

and here are the icons themselves, verbatim:

void
EVP_CIPHER_do_all(void (*fn)(const EVP_CIPHER *cipher, const char *from, const char *to, void *arg),
    void *arg);

void
EVP_CIPHER_do_all_sorted(void (*fn)(const EVP_CIPHER *cipher, const char *from, const char *to, void *arg),
    void *arg);

void
EVP_MD_do_all(void (*fn)(const EVP_MD *md, const char *from, const char *to, void *arg),
    void *arg);

void
EVP_MD_do_all_sorted(void (*fn)(const EVP_MD *md, const char *from, const char *to, void *arg),
    void *arg);

typedef struct {
        int         type;
        int         alias;
        const char *name;
        const char *data;
} OBJ_NAME;

void
OBJ_NAME_do_all(int type,
    void (*fn)(const OBJ_NAME *obj_name, void *arg), void *arg);

void
OBJ_NAME_do_all_sorted(int type,
    void (*fn)(const OBJ_NAME *obj_name, void *arg), void *arg);

🌸 DESCRIPTION 🌸

πŸŽ€ the cipher ones

EVP_CIPHER_do_all() calls fn on every entry of the global table of cipher names and aliases. and the way it does it is kind of specific, so listen up bestie:

  • for a cipher name entry, fn gets called with a non-NULL cipher, its non-NULL cipher name as from, a NULL to, and your arg pointer πŸ’–
  • for an alias entry, fn gets called with a NULL cipher, its alias as from, the cipher name that alias points to as to, and the arg pointer

EVP_CIPHER_do_all_sorted() is literally the same vibe, except it processes the cipher names and aliases in lexicographic order of their from names as determined by strcmp(3). sorted > chaos, iykyk ✨

🧚 the digest ones

EVP_MD_do_all() calls fn on every entry of the global table of digest names and aliases:

  • for a digest name entry, fn gets a non-NULL md, its non-NULL digest name as from, a NULL to, and the arg pointer
  • for an alias entry, fn gets a NULL md, its alias as from, the digest name that alias points to, and the arg pointer

EVP_MD_do_all_sorted() β€” same deal, except again it goes in lexicographic order of their from names, as determined by strcmp(3). consistent queen πŸ’…

πŸ‘‘ the OBJ_NAME ones

OBJ_NAME is basically an abstraction of the types underlying those lookup tables β€” ciphers and their aliases, and digests and their aliases, respectively. here's the mapping, no guessing:

  • for a cipher: type is OBJ_NAME_TYPE_CIPHER_METH, alias is 0, name is its lookup name, and data is the EVP_CIPHER object it represents, cast to const char *
  • for a cipher alias: type is OBJ_NAME_TYPE_CIPHER_METH, alias is OBJ_NAME_ALIAS, name is its lookup name, and data is the name it aliases
  • for digests representing an EVP_MD object and their aliases: represented similarly, except their type is OBJ_NAME_TYPE_MD_METH 🫢

OBJ_NAME_do_all() calls fn on every obj_name in the table that has the given type (either OBJ_NAME_TYPE_CIPHER_METH or OBJ_NAME_TYPE_MD_METH), also passing the arg pointer. and OBJ_NAME_do_all_sorted() is similar β€” except it processes the obj_name in lexicographic order of their names, as determined by strcmp(3). the sorted versions really said "alphabetize or die" 😭


πŸ¦‹ SEE ALSO πŸ¦‹


πŸ’€ HISTORY πŸ’€

these functions first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9. vintage, honestly. iconic legacy behavior πŸ‘‘


πŸ™ˆ CAVEATS πŸ™ˆ

okay so this is the part where we get serious for a sec, because it actually matters:

EVP_CIPHER_do_all_sorted(), EVP_MD_do_all_sorted(), and OBJ_NAME_do_all_sorted() cannot report errors. in some implementations they need to allocate internally, and if memory allocation fails they do nothing at all, without telling the caller about the problem. like, they'll just ghost you. 🫠

so yeah β€” sorted versions, love them, but know that silence is not always consent, sometimes it's a failed malloc.


this page is from the Debian build, dated June 8, 2025 β€” stay slaying, and remember: every flag, every signature, every caveat is exactly as written, fr fr πŸ’–πŸŒˆβ­

πŸ“¦ where this page comes from