]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
prov: update cmac to have additional init arguments
authorPauli <ppzgs1@gmail.com>
Thu, 25 Feb 2021 03:54:12 +0000 (13:54 +1000)
committerPauli <ppzgs1@gmail.com>
Sun, 28 Feb 2021 07:25:49 +0000 (17:25 +1000)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14310)

providers/implementations/macs/cmac_prov.c

index 08c4eebbf31a0fde95f14bb1d1211751816a7d7b..9aefc2cbec71de198384483a4e51cb9ea6629d30 100644 (file)
@@ -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;
 }