EVP_PKEY_METH_NEW(3ossl)

✨ NAME ✨

okay so this is the OpenSSL manual page EVP_PKEY_METH_NEW(3ossl), and it's literally all about manipulating the EVP_PKEY_METHOD structure β€” that's the whole vibe πŸ’…

the star of the show is EVP_PKEY_METHOD, plus the whole squad of functions that build it, copy it, find it, register it, un-register it, and poke at every single callback inside it:

  • EVP_PKEY_meth_new, EVP_PKEY_meth_free, EVP_PKEY_meth_copy
  • EVP_PKEY_meth_find, EVP_PKEY_meth_add0, EVP_PKEY_meth_remove
  • EVP_PKEY_METHOD
  • EVP_PKEY_meth_set_init, EVP_PKEY_meth_set_copy, EVP_PKEY_meth_set_cleanup
  • EVP_PKEY_meth_set_paramgen, EVP_PKEY_meth_set_keygen
  • EVP_PKEY_meth_set_sign, EVP_PKEY_meth_set_verify, EVP_PKEY_meth_set_verify_recover
  • EVP_PKEY_meth_set_signctx, EVP_PKEY_meth_set_verifyctx
  • EVP_PKEY_meth_set_encrypt, EVP_PKEY_meth_set_decrypt, EVP_PKEY_meth_set_derive
  • EVP_PKEY_meth_set_ctrl
  • EVP_PKEY_meth_set_digestsign, EVP_PKEY_meth_set_digestverify
  • EVP_PKEY_meth_set_check, EVP_PKEY_meth_set_public_check, EVP_PKEY_meth_set_param_check
  • EVP_PKEY_meth_set_digest_custom
  • EVP_PKEY_meth_get_init, EVP_PKEY_meth_get_copy, EVP_PKEY_meth_get_cleanup
  • EVP_PKEY_meth_get_paramgen, EVP_PKEY_meth_get_keygen
  • EVP_PKEY_meth_get_sign, EVP_PKEY_meth_get_verify, EVP_PKEY_meth_get_verify_recover
  • EVP_PKEY_meth_get_signctx, EVP_PKEY_meth_get_verifyctx
  • EVP_PKEY_meth_get_encrypt, EVP_PKEY_meth_get_decrypt, EVP_PKEY_meth_get_derive
  • EVP_PKEY_meth_get_ctrl
  • EVP_PKEY_meth_get_digestsign, EVP_PKEY_meth_get_digestverify
  • EVP_PKEY_meth_get_check, EVP_PKEY_meth_get_public_check, EVP_PKEY_meth_get_param_check
  • EVP_PKEY_meth_get_digest_custom

🌸 SYNOPSIS 🌸

first thing you gotta do, always, is pull in the header:

#include <openssl/evp.h>
⚠️ bestie, huge heads-up: everything on this page has been deprecated since OpenSSL 3.0. you can hide the whole lot entirely by defining OPENSSL_API_COMPAT with a suitable version value β€” peep openssl_user_macros(7) for the deets πŸ™ˆ

so here's the typedef, the struct hiding behind the scenes:

typedef struct evp_pkey_method_st EVP_PKEY_METHOD;

and here's the life-cycle + registry crew β€” new, free, copy, find, add, remove:

EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags);
void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth);
void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src);
const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type);
int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth);
int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth);

now the setters, aka the "glow-up" half of the API ✨

void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
                            int (*init) (EVP_PKEY_CTX *ctx));
void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
                            int (*copy) (EVP_PKEY_CTX *dst,
                                         const EVP_PKEY_CTX *src));
void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
                               void (*cleanup) (EVP_PKEY_CTX *ctx));
void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
                                int (*paramgen_init) (EVP_PKEY_CTX *ctx),
                                int (*paramgen) (EVP_PKEY_CTX *ctx,
                                                 EVP_PKEY *pkey));
void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
                              int (*keygen_init) (EVP_PKEY_CTX *ctx),
                              int (*keygen) (EVP_PKEY_CTX *ctx,
                                             EVP_PKEY *pkey));
void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
                            int (*sign_init) (EVP_PKEY_CTX *ctx),
                            int (*sign) (EVP_PKEY_CTX *ctx,
                                         unsigned char *sig, size_t *siglen,
                                         const unsigned char *tbs,
                                         size_t tbslen));
void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
                              int (*verify_init) (EVP_PKEY_CTX *ctx),
                              int (*verify) (EVP_PKEY_CTX *ctx,
                                             const unsigned char *sig,
                                             size_t siglen,
                                             const unsigned char *tbs,
                                             size_t tbslen));
void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
                                      int (*verify_recover_init) (EVP_PKEY_CTX
                                                                  *ctx),
                                      int (*verify_recover) (EVP_PKEY_CTX
                                                             *ctx,
                                                             unsigned char
                                                             *sig,
                                                             size_t *siglen,
                                                             const unsigned
                                                             char *tbs,
                                                             size_t tbslen));
void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
                               int (*signctx_init) (EVP_PKEY_CTX *ctx,
                                                    EVP_MD_CTX *mctx),
                               int (*signctx) (EVP_PKEY_CTX *ctx,
                                               unsigned char *sig,
                                               size_t *siglen,
                                               EVP_MD_CTX *mctx));
void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
                                 int (*verifyctx_init) (EVP_PKEY_CTX *ctx,
                                                        EVP_MD_CTX *mctx),
                                 int (*verifyctx) (EVP_PKEY_CTX *ctx,
                                                   const unsigned char *sig,
                                                   int siglen,
                                                   EVP_MD_CTX *mctx));
void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
                               int (*encrypt_init) (EVP_PKEY_CTX *ctx),
                               int (*encryptfn) (EVP_PKEY_CTX *ctx,
                                                 unsigned char *out,
                                                 size_t *outlen,
                                                 const unsigned char *in,
                                                 size_t inlen));
void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
                               int (*decrypt_init) (EVP_PKEY_CTX *ctx),
                               int (*decrypt) (EVP_PKEY_CTX *ctx,
                                               unsigned char *out,
                                               size_t *outlen,
                                               const unsigned char *in,
                                               size_t inlen));
void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
                              int (*derive_init) (EVP_PKEY_CTX *ctx),
                              int (*derive) (EVP_PKEY_CTX *ctx,
                                             unsigned char *key,
                                             size_t *keylen));
void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
                            int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
                                         void *p2),
                            int (*ctrl_str) (EVP_PKEY_CTX *ctx,
                                             const char *type,
                                             const char *value));
void EVP_PKEY_meth_set_digestsign(EVP_PKEY_METHOD *pmeth,
                                  int (*digestsign) (EVP_MD_CTX *ctx,
                                                     unsigned char *sig,
                                                     size_t *siglen,
                                                     const unsigned char *tbs,
                                                     size_t tbslen));
void EVP_PKEY_meth_set_digestverify(EVP_PKEY_METHOD *pmeth,
                                    int (*digestverify) (EVP_MD_CTX *ctx,
                                                         const unsigned char *sig,
                                                         size_t siglen,
                                                         const unsigned char *tbs,
                                                         size_t tbslen));
void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth,
                             int (*check) (EVP_PKEY *pkey));
void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth,
                                    int (*check) (EVP_PKEY *pkey));
void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth,
                                   int (*check) (EVP_PKEY *pkey));
void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD *pmeth,
                                    int (*digest_custom) (EVP_PKEY_CTX *ctx,
                                                          EVP_MD_CTX *mctx));

...and the getter squad continues πŸ’– because bestie, the setters got their moment and now it's their turn to shine. Every single one of these bad boys takes a const EVP_PKEY_METHOD *pmeth and hands you back a pointer-to-a-function-pointer so you can yoink the actual callback right out of the method. It's giving "reverse uno card" energy, and there are a lot of them, so buckle up πŸŽ€

void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD *pmeth,
                            int (**pinit) (EVP_PKEY_CTX *ctx));
void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD *pmeth,
                            int (**pcopy) (EVP_PKEY_CTX *dst,
                                           EVP_PKEY_CTX *src));
void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD *pmeth,
                               void (**pcleanup) (EVP_PKEY_CTX *ctx));
void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD *pmeth,
                                int (**pparamgen_init) (EVP_PKEY_CTX *ctx),
                                int (**pparamgen) (EVP_PKEY_CTX *ctx,
                                                   EVP_PKEY *pkey));
void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD *pmeth,
                              int (**pkeygen_init) (EVP_PKEY_CTX *ctx),
                              int (**pkeygen) (EVP_PKEY_CTX *ctx,
                                               EVP_PKEY *pkey));
void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD *pmeth,
                            int (**psign_init) (EVP_PKEY_CTX *ctx),
                            int (**psign) (EVP_PKEY_CTX *ctx,
                                           unsigned char *sig, size_t *siglen,
                                           const unsigned char *tbs,
                                           size_t tbslen));
void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD *pmeth,
                              int (**pverify_init) (EVP_PKEY_CTX *ctx),
                              int (**pverify) (EVP_PKEY_CTX *ctx,
                                               const unsigned char *sig,
                                               size_t siglen,
                                               const unsigned char *tbs,
                                               size_t tbslen));
void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD *pmeth,
                                      int (**pverify_recover_init) (EVP_PKEY_CTX
                                                                    *ctx),
                                      int (**pverify_recover) (EVP_PKEY_CTX
                                                               *ctx,
                                                               unsigned char
                                                               *sig,
                                                               size_t *siglen,
                                                               const unsigned
                                                               char *tbs,
                                                               size_t tbslen));
void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD *pmeth,
                               int (**psignctx_init) (EVP_PKEY_CTX *ctx,
                                                      EVP_MD_CTX *mctx),
                               int (**psignctx) (EVP_PKEY_CTX *ctx,
                                                 unsigned char *sig,
                                                 size_t *siglen,
                                                 EVP_MD_CTX *mctx));
void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD *pmeth,
                                 int (**pverifyctx_init) (EVP_PKEY_CTX *ctx,
                                                          EVP_MD_CTX *mctx),
                                 int (**pverifyctx) (EVP_PKEY_CTX *ctx,
                                                     const unsigned char *sig,
                                                     int siglen,
                                                     EVP_MD_CTX *mctx));
void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD *pmeth,
                               int (**pencrypt_init) (EVP_PKEY_CTX *ctx),
                               int (**pencryptfn) (EVP_PKEY_CTX *ctx,
                                                   unsigned char *out,
                                                   size_t *outlen,
                                                   const unsigned char *in,
                                                   size_t inlen));
void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD *pmeth,
                               int (**pdecrypt_init) (EVP_PKEY_CTX *ctx),
                               int (**pdecrypt) (EVP_PKEY_CTX *ctx,
                                                 unsigned char *out,
                                                 size_t *outlen,
                                                 const unsigned char *in,
                                                 size_t inlen));
void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD *pmeth,
                              int (**pderive_init) (EVP_PKEY_CTX *ctx),
                              int (**pderive) (EVP_PKEY_CTX *ctx,
                                               unsigned char *key,
                                               size_t *keylen));
void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD *pmeth,
                            int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
                                           void *p2),
                            int (**pctrl_str) (EVP_PKEY_CTX *ctx,
                                               const char *type,
                                               const char *value));
void EVP_PKEY_meth_get_digestsign(const EVP_PKEY_METHOD *pmeth,
                                  int (**digestsign) (EVP_MD_CTX *ctx,
                                                      unsigned char *sig,
                                                      size_t *siglen,
                                                      const unsigned char *tbs,
                                                      size_t tbslen));
void EVP_PKEY_meth_get_digestverify(const EVP_PKEY_METHOD *pmeth,
                                    int (**digestverify) (EVP_MD_CTX *ctx,
                                                          const unsigned char *sig,
                                                          size_t siglen,
                                                          const unsigned char *tbs,
                                                          size_t tbslen));
void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD *pmeth,
                             int (**pcheck) (EVP_PKEY *pkey));
void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD *pmeth,
                                    int (**pcheck) (EVP_PKEY *pkey));
void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD *pmeth,
                                   int (**pcheck) (EVP_PKEY *pkey));
void EVP_PKEY_meth_get_digest_custom(const EVP_PKEY_METHOD *pmeth,
                                    int (**pdigest_custom) (EVP_PKEY_CTX *ctx,
                                                            EVP_MD_CTX *mctx));

πŸ¦‹ vibe check: who does what

Okay so lowkey the names tell the whole story here β€” each getter is the mirror twin of a setter, pulling one specific callback out of pmeth. Let's run through the roster ✨

  • EVP_PKEY_meth_get_init β€” grabs the init callback (pinit).
  • EVP_PKEY_meth_get_copy β€” grabs the copy callback (pcopy), which takes a dst and a src EVP_PKEY_CTX *.
  • EVP_PKEY_meth_get_cleanup β€” grabs the cleanup callback (pcleanup). Note it's void, not int, so it's the chill one that returns nothing πŸ’…
  • EVP_PKEY_meth_get_paramgen β€” grabs two things: pparamgen_init and pparamgen.
  • EVP_PKEY_meth_get_keygen β€” same deal, a duo: pkeygen_init and pkeygen.
  • EVP_PKEY_meth_get_sign β€” grabs psign_init and psign.
  • EVP_PKEY_meth_get_verify β€” grabs pverify_init and pverify.
  • EVP_PKEY_meth_get_verify_recover β€” grabs pverify_recover_init and pverify_recover.
  • EVP_PKEY_meth_get_signctx β€” grabs psignctx_init and psignctx (these ones get an EVP_MD_CTX *mctx in the mix too).
  • EVP_PKEY_meth_get_verifyctx β€” grabs pverifyctx_init and pverifyctx.
  • EVP_PKEY_meth_get_encrypt β€” grabs pencrypt_init and... pencryptfn πŸ‘€ yes bestie, that one's named fn, not pencrypt. We don't make the rules.
  • EVP_PKEY_meth_get_decrypt β€” grabs pdecrypt_init and pdecrypt.
  • EVP_PKEY_meth_get_derive β€” grabs pderive_init and pderive.
  • EVP_PKEY_meth_get_ctrl β€” grabs pctrl and pctrl_str, because there's a string-flavoured ctrl too.
  • EVP_PKEY_meth_get_digestsign β€” grabs digestsign.
  • EVP_PKEY_meth_get_digestverify β€” grabs digestverify.
  • EVP_PKEY_meth_get_check β€” grabs pcheck.
  • EVP_PKEY_meth_get_public_check β€” grabs another pcheck.
  • EVP_PKEY_meth_get_param_check β€” and yet another pcheck. Three different ones, three different names. iykyk 🌸
  • EVP_PKEY_meth_get_digest_custom β€” grabs pdigest_custom.
Heads up bestie: watch the argument types, because they are not all the same vibe. Some getters take one output pointer, some take two. And notice the sneaky asymmetries: pverifyctx takes an int siglen while its cousin pverify takes a size_t siglen, and pencryptfn breaks the p-prefix naming pattern. Copy the signatures exactly β€” no improvising, no cap 😭

So yeah β€” that's the getter lineup, and it is long. But we're not done yet, keep scrolling, there's more coming 🫢

πŸ’– DESCRIPTION πŸ’–

Okay bestie, real talk before we get into the cute stuff: all of the functions described on this page are deprecated. 😭 The glow-up is that applications should instead use the OSSL_PROVIDER APIs. Periodt.

EVP_PKEY_METHOD is a struct that holds a whole set of methods for one specific public key crypto algorithm. Those methods are the little workers that do all the different jobs β€” generating a key, signing or verifying, encrypting or decrypting, etc. πŸ’…

There are two places where the EVP_PKEY_METHOD objects live:

  • one is a built-in static array representing the standard methods for different algorithms 🌸
  • the other one is a stack of user-defined application-specific methods, which you can manipulate using EVP_PKEY_meth_add0(3) ✨

And the EVP_PKEY_METHOD objects are usually referenced by EVP_PKEY_CTX objects. iykyk.


πŸ¦‹ Methods πŸ¦‹

These methods are the underlying implementations of a particular public key algorithm that's present by the EVP_PKEY_CTX object. Here we go, one by one 🫢

init, copy, cleanup

int (*init) (EVP_PKEY_CTX *ctx);
int (*copy) (EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src);
void (*cleanup) (EVP_PKEY_CTX *ctx);

The init() method gets called to initialize algorithm-specific data whenever a new EVP_PKEY_CTX is created. And unlike init(), the cleanup() method is called when an EVP_PKEY_CTX is freed (so it's the goodbye kiss πŸ‘‹). The copy() method is called when an EVP_PKEY_CTX is being duplicated. Go read EVP_PKEY_CTX_new(3), EVP_PKEY_CTX_new_id(3), EVP_PKEY_CTX_free(3) and EVP_PKEY_CTX_dup(3) for the tea.

paramgen_init, paramgen

int (*paramgen_init) (EVP_PKEY_CTX *ctx);
int (*paramgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);

The paramgen_init() and paramgen() methods are the key parameter generation girlies. They get called by EVP_PKEY_paramgen_init(3) and EVP_PKEY_paramgen(3) to handle the whole parameter generation process. ✨

keygen_init, keygen

int (*keygen_init) (EVP_PKEY_CTX *ctx);
int (*keygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);

The keygen_init() and keygen() methods are used to generate the actual key for the specified algorithm β€” yes, the real one, not just the parameters. They're called by EVP_PKEY_keygen_init(3) and EVP_PKEY_keygen(3). πŸ”‘

sign_init, sign

int (*sign_init) (EVP_PKEY_CTX *ctx);
int (*sign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
             const unsigned char *tbs, size_t tbslen);

The sign_init() and sign() methods generate the signature of a piece of data using a private key. They're called by EVP_PKEY_sign_init(3) and EVP_PKEY_sign(3). πŸ’…

verify_init, verify

int (*verify_init) (EVP_PKEY_CTX *ctx);
int (*verify) (EVP_PKEY_CTX *ctx,
               const unsigned char *sig, size_t siglen,
               const unsigned char *tbs, size_t tbslen);

The verify_init() and verify() methods check whether a signature is actually valid (the vibe check, but cryptographic 🌈). They're called by EVP_PKEY_verify_init(3) and EVP_PKEY_verify(3).

verify_recover_init, verify_recover

int (*verify_recover_init) (EVP_PKEY_CTX *ctx);
int (*verify_recover) (EVP_PKEY_CTX *ctx,
                       unsigned char *rout, size_t *routlen,
                       const unsigned char *sig, size_t siglen);

The verify_recover_init() and verify_recover() methods verify a signature and then recover the digest from the signature β€” for instance, a signature that was generated by the RSA signing algorithm. They're called by EVP_PKEY_verify_recover_init(3) and EVP_PKEY_verify_recover(3). It's giving "un-signing" energy. 😭

signctx_init, signctx

int (*signctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
int (*signctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
                EVP_MD_CTX *mctx);

The signctx_init() and signctx() methods sign a digest that's present by an EVP_MD_CTX object. They get called by the EVP_DigestSign functions. See EVP_DigestSignInit(3) for details. πŸŽ€

verifyctx_init, verifyctx

int (*verifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
int (*verifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen,
                  EVP_MD_CTX *mctx);

The verifyctx_init() and verifyctx() methods verify a signature against the data sitting in an EVP_MD_CTX object. They're called by the various EVP_DigestVerify functions. See EVP_DigestVerifyInit(3) for details. ✨

encrypt_init, encrypt

int (*encrypt_init) (EVP_PKEY_CTX *ctx);
int (*encrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
                const unsigned char *in, size_t inlen);

The encrypt_init() and encrypt() methods encrypt a piece of data. They're called by EVP_PKEY_encrypt_init(3) and EVP_PKEY_encrypt(3). πŸ”’

decrypt_init, decrypt

int (*decrypt_init) (EVP_PKEY_CTX *ctx);
int (*decrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
                const unsigned char *in, size_t inlen);

The decrypt_init() and decrypt() methods decrypt a piece of data. They're called by EVP_PKEY_decrypt_init(3) and EVP_PKEY_decrypt(3). πŸ”“

derive_init, derive

int (*derive_init) (EVP_PKEY_CTX *ctx);
int (*derive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);

The derive_init() and derive() methods derive the shared secret from a public key algorithm β€” for instance, the DH algorithm. They're called by EVP_PKEY_derive_init(3) and EVP_PKEY_derive(3). 🀝

ctrl, ctrl_str

int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2);
int (*ctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value);

The ctrl() and ctrl_str() methods adjust algorithm-specific settings. See EVP_PKEY_CTX_ctrl(3) and related functions for details. πŸŽ›οΈ

digestsign, digestverify

int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
                   const unsigned char *tbs, size_t tbslen);
int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
                     size_t siglen, const unsigned char *tbs,
                     size_t tbslen);

The digestsign() and digestverify() methods generate or verify a signature in a one-shot mode (no multi-step drama, just do it in one go πŸ’…). They could be called by EVP_DigestSign(3) and EVP_DigestVerify(3).

check, public_check, param_check

int (*check) (EVP_PKEY *pkey);
int (*public_check) (EVP_PKEY *pkey);
int (*param_check) (EVP_PKEY *pkey);

The check(), public_check() and param_check() methods validate a key-pair, the public component and parameters respectively for a given pkey. They could be called by EVP_PKEY_check(3), EVP_PKEY_public_check(3) and EVP_PKEY_param_check(3) respectively. βœ…

digest_custom

int (*digest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);

The digest_custom() method generates customized digest content before the real message is passed to functions like EVP_DigestSignUpdate(3) or EVP_DigestVerifyInit(3). This is usually required by some public key signature algorithms like SM2, which needs a hashed prefix to the message being signed. The digest_custom() function will be called by EVP_DigestSignInit(3) and EVP_DigestVerifyInit(3). 🧚


🌈 Functions 🌈

EVP_PKEY_meth_new() creates and returns a new EVP_PKEY_METHOD object, and associates the given id and flags. The following flags are supported:

  • EVP_PKEY_FLAG_AUTOARGLEN
  • EVP_PKEY_FLAG_SIGCTX_CUSTOM

If an EVP_PKEY_METHOD is set with the EVP_PKEY_FLAG_AUTOARGLEN flag, the maximum size of the output buffer will be automatically calculated or checked in corresponding EVP methods by the EVP framework. So the implementations of these methods don't need to care about handling the case of returning output buffer size by themselves β€” the framework handles it, main character energy for the framework honestly. For details on the output buffer size, refer to EVP_PKEY_sign(3). ✨

The EVP_PKEY_FLAG_SIGCTX_CUSTOM flag is used to indicate the signctx() method of an EVP_PKEY_METHOD is always called by the EVP framework while doing a digest signing operation by calling EVP_DigestSignFinal(3).

EVP_PKEY_meth_free() frees an existing EVP_PKEY_METHOD pointed by pmeth. If the argument is NULL, nothing is done. (Iconic minimal-effort behaviour honestly πŸ’…)

EVP_PKEY_meth_copy() copies an EVP_PKEY_METHOD object from src to dst.

EVP_PKEY_meth_find() finds an EVP_PKEY_METHOD object with the id. This function first searches through the user-defined method objects and then the built-in objects. πŸ”

EVP_PKEY_meth_add0() adds pmeth to the user defined stack of methods.

EVP_PKEY_meth_remove() removes an EVP_PKEY_METHOD object added by EVP_PKEY_meth_add0().

The EVP_PKEY_meth_set functions set the corresponding fields of EVP_PKEY_METHOD structure with the arguments passed. 🫢

The EVP_PKEY_meth_get functions get the corresponding fields of EVP_PKEY_METHOD structure to the arguments provided.


πŸŽ€ RETURN VALUES πŸŽ€

  • EVP_PKEY_meth_new() returns a pointer to a new EVP_PKEY_METHOD object, or returns NULL on error. 😭
  • EVP_PKEY_meth_free() and EVP_PKEY_meth_copy() do not return values.
  • EVP_PKEY_meth_find() returns a pointer to the found EVP_PKEY_METHOD object, or returns NULL if not found.
  • EVP_PKEY_meth_add0() returns 1 if method is added successfully, or 0 if an error occurred.
  • EVP_PKEY_meth_remove() returns 1 if method is removed successfully, or 0 if an error occurred.
  • All EVP_PKEY_meth_set and EVP_PKEY_meth_get functions have no return values. For the 'get' functions, function pointers are returned by arguments. ✨

πŸ’œ HISTORY πŸ’œ

All of these functions were deprecated in OpenSSL 3.0. πŸ’€

The signature of the copy functional argument of EVP_PKEY_meth_set_copy() has changed in OpenSSL 3.0, so its src parameter is now constified. (A lil glow-up, a lil const, we love to see it 🌸)


Copyright 2017-2024 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>.


okay that's the whole page bestie, we did it πŸ«ΆπŸ’– this was OpenSSL 3.5.9, dated 2026-09-29, and you just read EVP_PKEY_METH_NEW(3ossl) β€” go forth and be iconic with your deprecated-but-beloved method structs πŸ‘‘βœ¨

πŸ“¦ where this page comes from