EVP_CIPHER_DO_ALL(3)

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

πŸ’… EVP_CIPHER_DO_ALL(3) β€” Library Functions Manual, bestie edition πŸ’…

okay so welcome to the EVP_CIPHER_DO_ALL(3) page β€” yes, that’s the manual name, and it’s literally the Library Functions Manual’s whole guide to iterating over lookup tables for ciphers and digests. No cap. 🫢

NAME 🌸

The squad is 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. They iterate over lookup tables for ciphers and digests. Periodt. πŸ’–

SYNOPSIS ✨

#include <openssl/evp.h>

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 πŸ¦‹

okay so first up: the cipher table. EVP_CIPHER_do_all() calls fn on every entry of the global table of cipher names and aliases. For a cipher name entry, fn is called with a non-NULL cipher, its non-NULL cipher name from, a NULL to, and the arg pointer. For an alias entry, fn is called with a NULL cipher, its alias from, the cipher name that alias points to, and the arg pointer. πŸ’…

EVP_CIPHER_do_all_sorted() is similar, except that it processes the cipher names and aliases in lexicographic order of their from names as determined by strcmp(3). So if you need that alphabetical from-name vibe, this is your girl. iykyk. ✨

Next: the digest table. EVP_MD_do_all() calls fn on every entry of the global table of digest names and aliases. For a digest name entry, fn is called with a non-NULL md, its non-NULL digest name from, a NULL to, and the arg pointer. For an alias entry, fn is called with a NULL md, its alias from, the digest name that alias points to, and the arg pointer. slay. πŸ¦‹

EVP_MD_do_all_sorted() is similar, except that it processes the digest names and aliases in lexicographic order of their from names as determined by strcmp(3). same sorted energy, but for digests. πŸ’œ

Now OBJ_NAME: it is an abstraction of the types underlying the lookup tables for ciphers and their aliases, and digests and their aliases, respectively. 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. Digests representing an EVP_MD object and their aliases are represented similarly, except that 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. OBJ_NAME_do_all_sorted() is similar except that it processes the obj_name in lexicographic order of their names as determined by strcmp(3). cute. 🌸

SEE ALSO πŸŽ€

HISTORY 🧚

These functions first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9. iconic. πŸ‘‘

CAVEATS πŸ’€

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. So like, not me relying on these for error handling, bestie. 😭


xoxo, source/version: Debian β€” March 14, 2024 πŸ’–βœ¨

πŸ“¦ where this page comes from