Change EVP_MAC method from copy to dup
[openssl.git] / crypto / kmac / kmac.c
index db0a42c3a30eba5c4b3f81e1812af43a682e9381..69c334c37963bfd548cede79e663ccedeae94c6c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  *
 /*
  * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  *
- * Licensed under the OpenSSL license (the "License").  You may not use
+ * 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
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
  * this file except in compliance with the License.  You can obtain a copy
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
  * KMAC128(K, X, L, S)
  * {
  *     newX = bytepad(encode_string(K), 168) ||  X || right_encode(L).
  * KMAC128(K, X, L, S)
  * {
  *     newX = bytepad(encode_string(K), 168) ||  X || right_encode(L).
- *     T = bytepad(encode_string(“KMAC”) || encode_string(S), 168).
+ *     T = bytepad(encode_string("KMAC") || encode_string(S), 168).
  *     return KECCAK[256](T || newX || 00, L).
  * }
  *
  * KMAC256(K, X, L, S)
  * {
  *     newX = bytepad(encode_string(K), 136) ||  X || right_encode(L).
  *     return KECCAK[256](T || newX || 00, L).
  * }
  *
  * KMAC256(K, X, L, S)
  * {
  *     newX = bytepad(encode_string(K), 136) ||  X || right_encode(L).
- *     T = bytepad(encode_string(“KMAC”) || encode_string(S), 136).
+ *     T = bytepad(encode_string("KMAC") || encode_string(S), 136).
  *     return KECCAK[512](T || newX || 00, L).
  * }
  *
  * KMAC128XOF(K, X, L, S)
  * {
  *     newX = bytepad(encode_string(K), 168) ||  X || right_encode(0).
  *     return KECCAK[512](T || newX || 00, L).
  * }
  *
  * KMAC128XOF(K, X, L, S)
  * {
  *     newX = bytepad(encode_string(K), 168) ||  X || right_encode(0).
- *     T = bytepad(encode_string(“KMAC”) || encode_string(S), 168).
+ *     T = bytepad(encode_string("KMAC") || encode_string(S), 168).
  *     return KECCAK[256](T || newX || 00, L).
  * }
  *
  * KMAC256XOF(K, X, L, S)
  * {
  *     newX = bytepad(encode_string(K), 136) ||  X || right_encode(0).
  *     return KECCAK[256](T || newX || 00, L).
  * }
  *
  * KMAC256XOF(K, X, L, S)
  * {
  *     newX = bytepad(encode_string(K), 136) ||  X || right_encode(0).
- *     T = bytepad(encode_string(“KMAC”) || encode_string(S), 136).
+ *     T = bytepad(encode_string("KMAC") || encode_string(S), 136).
  *     return KECCAK[512](T || newX || 00, L).
  * }
  *
  *     return KECCAK[512](T || newX || 00, L).
  * }
  *
@@ -147,8 +147,19 @@ static EVP_MAC_IMPL *kmac256_new(void)
     return kmac_new(evp_keccak_kmac256());
 }
 
     return kmac_new(evp_keccak_kmac256());
 }
 
-static int kmac_copy(EVP_MAC_IMPL *gdst, EVP_MAC_IMPL *gsrc)
+static EVP_MAC_IMPL *kmac_dup(const EVP_MAC_IMPL *gsrc)
 {
 {
+    EVP_MAC_IMPL *gdst;
+
+    gdst = kmac_new(gsrc->md);
+    if (gdst == NULL)
+        return NULL;
+
+    if (!EVP_MD_CTX_copy(gdst->ctx, gsrc->ctx)) {
+        kmac_free(gdst);
+        return NULL;
+    }
+
     gdst->md = gsrc->md;
     gdst->out_len = gsrc->out_len;
     gdst->key_len = gsrc->key_len;
     gdst->md = gsrc->md;
     gdst->out_len = gsrc->out_len;
     gdst->key_len = gsrc->key_len;
@@ -157,7 +168,7 @@ static int kmac_copy(EVP_MAC_IMPL *gdst, EVP_MAC_IMPL *gsrc)
     memcpy(gdst->key, gsrc->key, gsrc->key_len);
     memcpy(gdst->custom, gsrc->custom, gdst->custom_len);
 
     memcpy(gdst->key, gsrc->key, gsrc->key_len);
     memcpy(gdst->custom, gsrc->custom, gdst->custom_len);
 
-    return EVP_MD_CTX_copy(gdst->ctx, gsrc->ctx);
+    return gdst;
 }
 
 /*
 }
 
 /*
@@ -444,7 +455,7 @@ static int kmac_bytepad_encode_key(unsigned char *out, int *out_len,
 const EVP_MAC kmac128_meth = {
     EVP_MAC_KMAC128,
     kmac128_new,
 const EVP_MAC kmac128_meth = {
     EVP_MAC_KMAC128,
     kmac128_new,
-    kmac_copy,
+    kmac_dup,
     kmac_free,
     kmac_size,
     kmac_init,
     kmac_free,
     kmac_size,
     kmac_init,
@@ -457,7 +468,7 @@ const EVP_MAC kmac128_meth = {
 const EVP_MAC kmac256_meth = {
     EVP_MAC_KMAC256,
     kmac256_new,
 const EVP_MAC kmac256_meth = {
     EVP_MAC_KMAC256,
     kmac256_new,
-    kmac_copy,
+    kmac_dup,
     kmac_free,
     kmac_size,
     kmac_init,
     kmac_free,
     kmac_size,
     kmac_init,