EVP_PKEY_IS_A(3ossl)

πŸ’– EVP_PKEY_IS_A(3ossl) πŸ’–

okay bestie, this is the <openssl/evp.h> girlies page β€” the one about key type and capabilities functions ✨. It's part of the OpenSSL fam, and it's literally all about asking your EVP_PKEY "who are you" and "can you even sign tho".


🌸 SYNOPSIS 🌸

#include <openssl/evp.h>

int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name);
int EVP_PKEY_can_sign(const EVP_PKEY *pkey);
int EVP_PKEY_type_names_do_all(const EVP_PKEY *pkey,
                               void (*fn)(const char *name, void *data),
                               void *data);
const char *EVP_PKEY_get0_type_name(const EVP_PKEY *key);
const char *EVP_PKEY_get0_description(const EVP_PKEY *key);
const OSSL_PROVIDER *EVP_PKEY_get0_provider(const EVP_PKEY *key);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the whole vibe check on each one, bestie:

  • EVP_PKEY_is_a() β€” checks if the key type of pkey is name. that's it. that's the whole function πŸ’…
  • EVP_PKEY_can_sign() β€” checks if the functionality for the key type of pkey supports signing. and like… no other check is done, okay? not even whether pkey contains a private key. so don't get it twisted πŸ™ˆ
  • EVP_PKEY_type_names_do_all() β€” traverses all names for pkey's key type, and calls fn with each name and data. for example, an RSA EVP_PKEY may be named both "RSA" and "rsaEncryption". the order of the names depends on the provider implementation that holds the key. so it's giving "alphabetical? no. provider's choice? yes."
  • EVP_PKEY_get0_type_name() β€” returns the first key type name that is found for the given pkey. note that the pkey may have multiple synonyms associated with it β€” in this case it depends on the provider implementation that holds the key which one will be returned. πŸ‘‘ also important: ownership of the returned string is retained by the pkey object and should not be freed by the caller. do NOT free it. put the free() down. 🫢
  • EVP_PKEY_get0_description() β€” returns a description of the type of EVP_PKEY, meant for display and human consumption. the description is at the discretion of the key type implementation. so it's a vibe, not a contract.
  • EVP_PKEY_get0_provider() β€” returns the provider of the EVP_PKEY's EVP_KEYMGMT(3). yep, the whole keymgmt situation.

⭐ RETURN VALUES ⭐

  • EVP_PKEY_is_a() returns 1 if pkey has the key type name, otherwise 0.
  • EVP_PKEY_can_sign() returns 1 if the pkey key type functionality supports signing, otherwise 0.
  • EVP_PKEY_get0_type_name() returns the name that is found or NULL on error.
  • EVP_PKEY_get0_description() returns the description if found or NULL if not.
  • EVP_PKEY_get0_provider() returns the provider if found or NULL if not.
  • EVP_PKEY_type_names_do_all() returns 1 if the callback was called for all names. a return value of 0 means that the callback was not called for any names.

πŸ”₯ EXAMPLES πŸ”₯

✨ EVP_PKEY_is_a() ✨

the loaded providers and what key types they support will ultimately determine what name is possible to use with EVP_PKEY_is_a(). we do know that the default provider supports RSA, DH, DSA and EC keys, so we can use this as an crude example:

#include <openssl/evp.h>

...
    /* |pkey| is an EVP_PKEY* */
    if (EVP_PKEY_is_a(pkey, "RSA")) {
        BIGNUM *modulus = NULL;
        if (EVP_PKEY_get_bn_param(pkey, "n", &modulus))
            /* do whatever with the modulus */
        BN_free(modulus);
    }

πŸ’œ EVP_PKEY_can_sign() πŸ’œ

#include <openssl/evp.h>

...
    /* |pkey| is an EVP_PKEY* */
    if (!EVP_PKEY_can_sign(pkey)) {
        fprintf(stderr, "Not a signing key!");
        exit(1);
    }
    /* Sign something... */

🌈 HISTORY 🌈

the functions described here were added in OpenSSL 3.0. so if you're on something older… yeah, no. not available. πŸ’€


Copyright 2020-2021 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! this was OpenSSL 3.5.9, dated 2026-09-29, and yes the manual page really is named EVP_PKEY_IS_A(3ossl) πŸ¦‹πŸ’– slay, go check your key types, periodt βœ¨πŸ‘‘

πŸ“¦ where this page comes from