From 636dd0c1f36872f0abcb4f8a465e837929ed19d1 Mon Sep 17 00:00:00 2001 From: Vitaly Chikunov Date: Thu, 2 Aug 2018 00:03:06 +0300 Subject: [PATCH] Fix EVP_MD_CTX_copy_ex for OMAC Openssl copies a state between valid contexts. But, EVP_MD_CTX_copy_ex just memcpy-s private data (md_data), which points to OMAC_CTX), which have pointer to CMAC_CTX. Copying pointer makes CMAC context just the same on the both sides. As a consequence, we can not do normal copy of a state between CMAC contexts. As a fix, we just clone it if it's equal between copy sides. Reported-by: Gleb Fotengauer-Malinovskiy --- gost_omac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gost_omac.c b/gost_omac.c index c4e8111..af6eb2a 100644 --- a/gost_omac.c +++ b/gost_omac.c @@ -91,7 +91,7 @@ int omac_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) } if (c_to->cmac_ctx == c_from->cmac_ctx) { - return 1; + c_to->cmac_ctx = CMAC_CTX_new(); } return CMAC_CTX_copy(c_to->cmac_ctx, c_from->cmac_ctx); } -- 2.39.2