prov: use new MAC_init arguments in signature legacy code
[openssl.git] / providers / implementations / signature / mac_legacy.c
index 0b1415a9c968c8848079077898faeb2208429558..fb99221f0877c6ed38424b7555651a21e08ce719 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-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
  *
  * 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
@@ -37,7 +37,7 @@ static OSSL_FUNC_signature_settable_ctx_params_fn mac_poly1305_settable_ctx_para
 static OSSL_FUNC_signature_settable_ctx_params_fn mac_cmac_settable_ctx_params;
 
 typedef struct {
 static OSSL_FUNC_signature_settable_ctx_params_fn mac_cmac_settable_ctx_params;
 
 typedef struct {
-    OPENSSL_CTX *libctx;
+    OSSL_LIB_CTX *libctx;
     char *propq;
     MAC_KEY *key;
     EVP_MAC_CTX *macctx;
     char *propq;
     MAC_KEY *key;
     EVP_MAC_CTX *macctx;
@@ -55,7 +55,7 @@ static void *mac_newctx(void *provctx, const char *propq, const char *macname)
     if (pmacctx == NULL)
         return NULL;
 
     if (pmacctx == NULL)
         return NULL;
 
-    pmacctx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
+    pmacctx->libctx = PROV_LIBCTX_OF(provctx);
     if (propq != NULL && (pmacctx->propq = OPENSSL_strdup(propq)) == NULL) {
         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
         goto err;
     if (propq != NULL && (pmacctx->propq = OPENSSL_strdup(propq)) == NULL) {
         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
         goto err;
@@ -74,6 +74,7 @@ static void *mac_newctx(void *provctx, const char *propq, const char *macname)
     return pmacctx;
 
  err:
     return pmacctx;
 
  err:
+    OPENSSL_free(pmacctx->propq);
     OPENSSL_free(pmacctx);
     EVP_MAC_free(mac);
     return NULL;
     OPENSSL_free(pmacctx);
     EVP_MAC_free(mac);
     return NULL;
@@ -98,10 +99,10 @@ static int mac_digest_sign_init(void *vpmacctx, const char *mdname, void *vkey)
     if (!ossl_prov_is_running()
             || pmacctx == NULL
             || vkey == NULL
     if (!ossl_prov_is_running()
             || pmacctx == NULL
             || vkey == NULL
-            || !mac_key_up_ref(vkey))
+            || !ossl_mac_key_up_ref(vkey))
         return 0;
 
         return 0;
 
-    mac_key_free(pmacctx->key);
+    ossl_mac_key_free(pmacctx->key);
     pmacctx->key = vkey;
 
     if (pmacctx->key->cipher.cipher != NULL)
     pmacctx->key = vkey;
 
     if (pmacctx->key->cipher.cipher != NULL)
@@ -116,11 +117,11 @@ static int mac_digest_sign_init(void *vpmacctx, const char *mdname, void *vkey)
                               (char *)mdname,
                               (char *)engine,
                               pmacctx->key->properties,
                               (char *)mdname,
                               (char *)engine,
                               pmacctx->key->properties,
-                              pmacctx->key->priv_key,
-                              pmacctx->key->priv_key_len))
+                              NULL, 0))
         return 0;
 
         return 0;
 
-    if (!EVP_MAC_init(pmacctx->macctx))
+    if (!EVP_MAC_init(pmacctx->macctx, pmacctx->key->priv_key,
+                      pmacctx->key->priv_key_len, NULL))
         return 0;
 
     return 1;
         return 0;
 
     return 1;
@@ -154,7 +155,7 @@ static void mac_freectx(void *vpmacctx)
 
     OPENSSL_free(ctx->propq);
     EVP_MAC_CTX_free(ctx->macctx);
 
     OPENSSL_free(ctx->propq);
     EVP_MAC_CTX_free(ctx->macctx);
-    mac_key_free(ctx->key);
+    ossl_mac_key_free(ctx->key);
     OPENSSL_free(ctx);
 }
 
     OPENSSL_free(ctx);
 }
 
@@ -171,10 +172,14 @@ static void *mac_dupctx(void *vpmacctx)
         return NULL;
 
     *dstctx = *srcctx;
         return NULL;
 
     *dstctx = *srcctx;
+    dstctx->propq = NULL;
     dstctx->key = NULL;
     dstctx->macctx = NULL;
 
     dstctx->key = NULL;
     dstctx->macctx = NULL;
 
-    if (srcctx->key != NULL && !mac_key_up_ref(srcctx->key))
+    if (srcctx->propq != NULL && (dstctx->propq = OPENSSL_strdup(srcctx->propq)) == NULL)
+        goto err;
+
+    if (srcctx->key != NULL && !ossl_mac_key_up_ref(srcctx->key))
         goto err;
     dstctx->key = srcctx->key;
 
         goto err;
     dstctx->key = srcctx->key;
 
@@ -200,7 +205,7 @@ static int mac_set_ctx_params(void *vpmacctx, const OSSL_PARAM params[])
 static const OSSL_PARAM *mac_settable_ctx_params(void *provctx,
                                                  const char *macname)
 {
 static const OSSL_PARAM *mac_settable_ctx_params(void *provctx,
                                                  const char *macname)
 {
-    EVP_MAC *mac = EVP_MAC_fetch(PROV_LIBRARY_CONTEXT_OF(provctx), macname,
+    EVP_MAC *mac = EVP_MAC_fetch(PROV_LIBCTX_OF(provctx), macname,
                                  NULL);
     const OSSL_PARAM *params;
 
                                  NULL);
     const OSSL_PARAM *params;
 
@@ -225,7 +230,7 @@ MAC_SETTABLE_CTX_PARAMS(poly1305, "POLY1305")
 MAC_SETTABLE_CTX_PARAMS(cmac, "CMAC")
 
 #define MAC_SIGNATURE_FUNCTIONS(funcname) \
 MAC_SETTABLE_CTX_PARAMS(cmac, "CMAC")
 
 #define MAC_SIGNATURE_FUNCTIONS(funcname) \
-    const OSSL_DISPATCH mac_legacy_##funcname##_signature_functions[] = { \
+    const OSSL_DISPATCH ossl_mac_legacy_##funcname##_signature_functions[] = { \
         { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))mac_##funcname##_newctx }, \
         { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, \
         (void (*)(void))mac_digest_sign_init }, \
         { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))mac_##funcname##_newctx }, \
         { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, \
         (void (*)(void))mac_digest_sign_init }, \