diff options
author | Pauli <ppzgs1@gmail.com> | 2021-02-25 13:54:12 +1000 |
---|---|---|
committer | Pauli <ppzgs1@gmail.com> | 2021-02-28 17:25:49 +1000 |
commit | 005b190297e1ed7a930a1085b49c95c6f4ad57f7 (patch) | |
tree | 847bd5d5388414e8a414a4c7cf7228c884da790f /providers/implementations/macs | |
parent | cf5784aa03bf4e9214dc92bd9f92fcc09e664d40 (diff) | |
download | openssl-005b190297e1ed7a930a1085b49c95c6f4ad57f7.zip openssl-005b190297e1ed7a930a1085b49c95c6f4ad57f7.tar.gz openssl-005b190297e1ed7a930a1085b49c95c6f4ad57f7.tar.bz2 |
prov: update cmac to have additional init arguments
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14310)
Diffstat (limited to 'providers/implementations/macs')
-rw-r--r-- | providers/implementations/macs/cmac_prov.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/providers/implementations/macs/cmac_prov.c b/providers/implementations/macs/cmac_prov.c index 08c4eeb..9aefc2c 100644 --- a/providers/implementations/macs/cmac_prov.c +++ b/providers/implementations/macs/cmac_prov.c @@ -102,20 +102,26 @@ static size_t cmac_size(void *vmacctx) return EVP_CIPHER_CTX_block_size(CMAC_CTX_get0_cipher_ctx(macctx->ctx)); } -static int cmac_init(void *vmacctx) +static int cmac_setkey(struct cmac_data_st *macctx, + const unsigned char *key, size_t keylen) +{ + int rv = CMAC_Init(macctx->ctx, key, keylen, + ossl_prov_cipher_cipher(&macctx->cipher), + ossl_prov_cipher_engine(&macctx->cipher)); + ossl_prov_cipher_reset(&macctx->cipher); + return rv; +} + +static int cmac_init(void *vmacctx, const unsigned char *key, + size_t keylen, const OSSL_PARAM params[]) { struct cmac_data_st *macctx = vmacctx; - int rv; - if (!ossl_prov_is_running()) + if (!ossl_prov_is_running() || !cmac_set_ctx_params(macctx, params)) return 0; - - rv = CMAC_Init(macctx->ctx, NULL, 0, - ossl_prov_cipher_cipher(&macctx->cipher), - ossl_prov_cipher_engine(&macctx->cipher)); - - ossl_prov_cipher_reset(&macctx->cipher); - return rv; + if (key != NULL) + return cmac_setkey(macctx, key, keylen); + return 1; } static int cmac_update(void *vmacctx, const unsigned char *data, @@ -184,13 +190,7 @@ static int cmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[]) if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) { if (p->data_type != OSSL_PARAM_OCTET_STRING) return 0; - - if (!CMAC_Init(macctx->ctx, p->data, p->data_size, - ossl_prov_cipher_cipher(&macctx->cipher), - ossl_prov_cipher_engine(&macctx->cipher))) - return 0; - - ossl_prov_cipher_reset(&macctx->cipher); + return cmac_setkey(macctx, p->data, p->data_size); } return 1; } |