return ossl_namemap_num2name(namemap, name_id, 0);
}
+
+int evp_is_a(OSSL_PROVIDER *prov, int number, const char *name)
+{
+ OPENSSL_CTX *libctx = ossl_provider_library_context(prov);
+ OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
+
+ return ossl_namemap_name2num(namemap, name) == number;
+}
return ctx->cipher->nid;
}
+int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name)
+{
+ return evp_is_a(cipher->prov, cipher->name_id, name);
+}
+
const char *EVP_CIPHER_name(const EVP_CIPHER *cipher)
{
if (cipher->prov != NULL)
/* OSSL_PROVIDER * is only used to get the library context */
const char *evp_first_name(OSSL_PROVIDER *prov, int name_id);
+int evp_is_a(OSSL_PROVIDER *prov, int number, const char *name);
evp_mac_free(mac);
}
+int EVP_MAC_is_a(const EVP_MAC *mac, const char *name)
+{
+ return evp_is_a(mac->prov, mac->name_id, name);
+}
+
const char *EVP_MAC_name(const EVP_MAC *mac)
{
return evp_first_name(mac->prov, mac->name_id);
&& (ctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) != 0;
if (set_key) {
- if (strcmp(OBJ_nid2sn(EVP_PKEY_id(EVP_PKEY_CTX_get0_pkey(ctx))),
- EVP_MAC_name(EVP_MAC_CTX_mac(hctx->ctx))) != 0)
+ if (!EVP_MAC_is_a(EVP_MAC_CTX_mac(hctx->ctx),
+ OBJ_nid2sn(EVP_PKEY_id(EVP_PKEY_CTX_get0_pkey(ctx)))))
return 0;
key = EVP_PKEY_get0(EVP_PKEY_CTX_get0_pkey(ctx));
if (key == NULL)
EVP_get_cipherbyname,
EVP_get_cipherbynid,
EVP_get_cipherbyobj,
+EVP_CIPHER_is_a,
EVP_CIPHER_name,
EVP_CIPHER_provider,
EVP_CIPHER_nid,
const EVP_CIPHER *EVP_get_cipherbyobj(const ASN1_OBJECT *a);
int EVP_CIPHER_nid(const EVP_CIPHER *e);
+ int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name);
const char *EVP_CIPHER_name(const EVP_CIPHER *cipher);
const OSSL_PROVIDER *EVP_CIPHER_provider(const EVP_CIPHER *cipher);
int EVP_CIPHER_block_size(const EVP_CIPHER *e);
identifier or does not have ASN1 support this function will return
B<NID_undef>.
+EVP_CIPHER_is_a() returns 1 if the given I<cipher> is an implementation of an
+algorithm that's identifiable with I<name>, otherwise 0.
+
EVP_CIPHER_name() and EVP_CIPHER_CTX_name() return the name of the passed
cipher or context.
=head1 NAME
-EVP_MAC, EVP_MAC_fetch, EVP_MAC_up_ref, EVP_MAC_free, EVP_MAC_name,
+EVP_MAC, EVP_MAC_fetch, EVP_MAC_up_ref, EVP_MAC_free,
+EVP_MAC_is_a, EVP_MAC_name,
EVP_MAC_provider, EVP_MAC_get_params, EVP_MAC_gettable_params,
EVP_MAC_CTX, EVP_MAC_CTX_new, EVP_MAC_CTX_free, EVP_MAC_CTX_dup,
EVP_MAC_CTX_mac, EVP_MAC_CTX_get_params, EVP_MAC_CTX_set_params,
const char *properties);
int EVP_MAC_up_ref(EVP_MAC *mac);
void EVP_MAC_free(EVP_MAC *mac);
+ int EVP_MAC_is_a(const EVP_MAC *mac, const char *name);
const char *EVP_MAC_name(const EVP_MAC *mac);
const OSSL_PROVIDER *EVP_MAC_provider(const EVP_MAC *mac);
int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]);
EVP_MAC_name() returns the name of the given MAC implementation.
+EVP_MAC_is_a() checks if the given I<mac> is an implementation of an
+algorithm that's identifiable with I<name>.
+
EVP_MAC_provider() returns the provider that holds the implementation
of the given I<mac>.
EVP_MAC_name() returns the name of the MAC, or NULL if NULL was
passed.
+EVP_MAC_is_a() returns 1 if the given method can be identified with
+the given name, otherwise 0.
+
EVP_MAC_provider() returns a pointer to the provider for the MAC, or
NULL on error.
int EVP_CIPHER_nid(const EVP_CIPHER *cipher);
const char *EVP_CIPHER_name(const EVP_CIPHER *cipher);
+int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name);
const OSSL_PROVIDER *EVP_CIPHER_provider(const EVP_CIPHER *cipher);
int EVP_CIPHER_block_size(const EVP_CIPHER *cipher);
int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *cipher);
int EVP_MAC_up_ref(EVP_MAC *mac);
void EVP_MAC_free(EVP_MAC *mac);
const char *EVP_MAC_name(const EVP_MAC *mac);
+int EVP_MAC_is_a(const EVP_MAC *mac, const char *name);
const OSSL_PROVIDER *EVP_MAC_provider(const EVP_MAC *mac);
int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]);
/* Conditions for legacy EVP_CIPHER uses */
ENGINE *engine; /* cipher engine */
+
+ /* Name this was fetched by */
+ char name[51]; /* A longer name would be unexpected */
} PROV_CIPHER;
typedef struct {
/* Conditions for legacy EVP_MD uses */
ENGINE *engine; /* digest engine */
+
+ /* Name this was fetched by */
+ char name[51]; /* A longer name would be unexpected */
} PROV_DIGEST;
/* Cipher functions */
* implementation used. If a provider cannot be found, it falls back to trying
* non-provider based implementations.
*/
-int ossl_prov_cipher_load_from_params(PROV_CIPHER *pd,
+int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
const OSSL_PARAM params[],
OPENSSL_CTX *ctx);
/* Reset the PROV_CIPHER fields and free any allocated cipher reference */
-void ossl_prov_cipher_reset(PROV_CIPHER *pd);
+void ossl_prov_cipher_reset(PROV_CIPHER *pc);
/* Clone a PROV_CIPHER structure into a second */
int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src);
/* Query the cipher and associated engine (if any) */
-const EVP_CIPHER *ossl_prov_cipher_cipher(const PROV_CIPHER *pd);
-ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pd);
+const EVP_CIPHER *ossl_prov_cipher_cipher(const PROV_CIPHER *pc);
+ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pc);
+const char *ossl_prov_cipher_name(const PROV_CIPHER *pc);
/* Digest functions */
/*
/* Query the digest and associated engine (if any) */
const EVP_MD *ossl_prov_digest_md(const PROV_DIGEST *pd);
ENGINE *ossl_prov_digest_engine(const PROV_DIGEST *pd);
+const char *ossl_prov_digest_name(const PROV_DIGEST *pd);
int ret;
const unsigned char *custom = NULL;
size_t custom_len = 0;
- const char *macname;
int default_salt_len;
/*
* Why does KMAC require a salt length that's shorter than the MD
* block size?
*/
- macname = EVP_MAC_name(ctx->mac);
- if (strcmp(macname, OSSL_MAC_NAME_HMAC) == 0) {
+ if (EVP_MAC_is_a(ctx->mac, OSSL_MAC_NAME_HMAC)) {
/* H(x) = HMAC(x, salt, hash) */
if (md == NULL) {
ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
default_salt_len = EVP_MD_block_size(md);
if (default_salt_len <= 0)
return 0;
- } else if (strcmp(macname, OSSL_MAC_NAME_KMAC128) == 0
- || strcmp(macname, OSSL_MAC_NAME_KMAC256) == 0) {
+ } else if (EVP_MAC_is_a(ctx->mac, OSSL_MAC_NAME_KMAC128)
+ || EVP_MAC_is_a(ctx->mac, OSSL_MAC_NAME_KMAC256)) {
/* H(x) = KMACzzz(x, salt, custom) */
custom = kmac_custom_str;
custom_len = sizeof(kmac_custom_str);
- if (strcmp(macname, OSSL_MAC_NAME_KMAC128) == 0)
+ if (EVP_MAC_is_a(ctx->mac, OSSL_MAC_NAME_KMAC128))
default_salt_len = SSKDF_KMAC128_DEFAULT_SALT_SIZE;
else
default_salt_len = SSKDF_KMAC256_DEFAULT_SALT_SIZE;
pc->alloc_cipher = NULL;
pc->cipher = NULL;
pc->engine = NULL;
+ pc->name[0] = '\0';
}
int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src)
dst->engine = src->engine;
dst->cipher = src->cipher;
dst->alloc_cipher = src->alloc_cipher;
+ OPENSSL_strlcpy(dst->name, src->name, sizeof(dst->name));
return 1;
}
EVP_CIPHER_free(pc->alloc_cipher);
pc->cipher = pc->alloc_cipher = EVP_CIPHER_fetch(ctx, p->data, propquery);
+ OPENSSL_strlcpy(pc->name, p->data, sizeof(pc->name));
/* TODO legacy stuff, to be removed */
#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy ciphers */
if (pc->cipher == NULL)
return pc->engine;
}
+const char *ossl_prov_cipher_name(const PROV_CIPHER *pc)
+{
+ return pc->name;
+}
+
void ossl_prov_digest_reset(PROV_DIGEST *pd)
{
EVP_MD_free(pd->alloc_md);
pd->alloc_md = NULL;
pd->md = NULL;
pd->engine = NULL;
+ pd->name[0] = '\0';
}
int ossl_prov_digest_copy(PROV_DIGEST *dst, const PROV_DIGEST *src)
dst->engine = src->engine;
dst->md = src->md;
dst->alloc_md = src->alloc_md;
+ OPENSSL_strlcpy(dst->name, src->name, sizeof(dst->name));
return 1;
}
EVP_MD_free(pd->alloc_md);
pd->md = pd->alloc_md = EVP_MD_fetch(ctx, p->data, propquery);
+ OPENSSL_strlcpy(pd->name, p->data, sizeof(pd->name));
/* TODO legacy stuff, to be removed */
#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy digests */
if (pd->md == NULL)
return pd->engine;
}
+const char *ossl_prov_digest_name(const PROV_DIGEST *pd)
+{
+ return pd->name;
+}
ERR_peek_last_error_func 4879 3_0_0 EXIST::FUNCTION:
ERR_peek_last_error_data 4880 3_0_0 EXIST::FUNCTION:
ERR_peek_last_error_all 4881 3_0_0 EXIST::FUNCTION:
+EVP_CIPHER_is_a 4882 3_0_0 EXIST::FUNCTION:
+EVP_MAC_is_a 4883 3_0_0 EXIST::FUNCTION: