From: Matt Caswell Date: Mon, 10 Aug 2020 08:16:01 +0000 (+0100) Subject: Convert EVP_PKEY_CTX_set_mac_key() into a function X-Git-Tag: openssl-3.0.0-alpha7~456 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5d51925a90734226f804a7b928326f8ba4bd0434;p=thirdparty%2Fopenssl.git Convert EVP_PKEY_CTX_set_mac_key() into a function Previously it was a macro. We now make it into a function that is params aware. Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/12637) --- diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index efec516ac2..1d5585583e 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -844,7 +844,7 @@ static int evp_pkey_ctx_set1_octet_string(EVP_PKEY_CTX *ctx, int fallback, { OSSL_PARAM octet_string_params[2], *p = octet_string_params; - if (ctx == NULL || !EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) { + if (ctx == NULL || (ctx->operation & op) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; @@ -1026,6 +1026,16 @@ int EVP_PKEY_CTX_set_scrypt_maxmem_bytes(EVP_PKEY_CTX *ctx, maxmem_bytes); } +int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key, + int keylen) +{ + return evp_pkey_ctx_set1_octet_string(ctx, ctx->op.keymgmt.genctx == NULL, + OSSL_PKEY_PARAM_PRIV_KEY, + EVP_PKEY_OP_KEYGEN, + EVP_PKEY_CTRL_SET_MAC_KEY, + key, keylen); +} + static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd, int p1, void *p2) { diff --git a/include/openssl/evp.h b/include/openssl/evp.h index 62015a7b1b..290ccf56fb 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -1526,9 +1526,8 @@ int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); # define EVP_PKEY_OP_TYPE_FROMDATA \ (EVP_PKEY_OP_PARAMFROMDATA | EVP_PKEY_OP_KEYFROMDATA) -# define EVP_PKEY_CTX_set_mac_key(ctx, key, len) \ - EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_KEYGEN, \ - EVP_PKEY_CTRL_SET_MAC_KEY, len, (void *)(key)) +int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key, + int keylen); # define EVP_PKEY_CTRL_MD 1 # define EVP_PKEY_CTRL_PEER_KEY 2