summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-12-28 21:56:12 +0000
committertb <>2023-12-28 21:56:12 +0000
commit4e4593b9566b4947b4b7d631fae8797c12740aca (patch)
tree21d0f6dd472a206ac8bdde60864ab3910a2f4ec9
parent20547dc33c870f1d044c7fed8beb186ccdb88db0 (diff)
downloadopenbsd-4e4593b9566b4947b4b7d631fae8797c12740aca.tar.gz
openbsd-4e4593b9566b4947b4b7d631fae8797c12740aca.tar.bz2
openbsd-4e4593b9566b4947b4b7d631fae8797c12740aca.zip
Clean up and fix pkey_cmac_keygen()
A void pointer can be passed without any cast or assigning it to an intermediate variable. That's one of hte puzzling things in old OpenSSL code: there are plenty of unnecessary casts and assignments of void pointers. Make use of this fact and rework the function to be single exit, error check consistently, including the EVP_PKEY_assign() call that can't really fail and free the cmkey on exit. Why coverity didn't flag this one is another mystery. ok jsing
-rw-r--r--src/lib/libcrypto/cmac/cm_pmeth.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/lib/libcrypto/cmac/cm_pmeth.c b/src/lib/libcrypto/cmac/cm_pmeth.c
index fa2d53e53d..03538e204e 100644
--- a/src/lib/libcrypto/cmac/cm_pmeth.c
+++ b/src/lib/libcrypto/cmac/cm_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cm_pmeth.c,v 1.11 2023/11/29 21:35:57 tb Exp $ */ 1/* $OpenBSD: cm_pmeth.c,v 1.12 2023/12/28 21:56:12 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2010. 3 * project 2010.
4 */ 4 */
@@ -92,18 +92,23 @@ pkey_cmac_cleanup(EVP_PKEY_CTX *ctx)
92static int 92static int
93pkey_cmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 93pkey_cmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
94{ 94{
95 CMAC_CTX *cmkey = CMAC_CTX_new(); 95 CMAC_CTX *cmkey;
96 CMAC_CTX *cmctx = ctx->data; 96 int ret = 0;
97 97
98 if (!cmkey) 98 if ((cmkey = CMAC_CTX_new()) == NULL)
99 return 0; 99 goto err;
100 if (!CMAC_CTX_copy(cmkey, cmctx)) { 100 if (!CMAC_CTX_copy(cmkey, ctx->data))
101 CMAC_CTX_free(cmkey); 101 goto err;
102 return 0; 102 if (!EVP_PKEY_assign(pkey, EVP_PKEY_CMAC, cmkey))
103 } 103 goto err;
104 EVP_PKEY_assign(pkey, EVP_PKEY_CMAC, cmkey); 104 cmkey = NULL;
105 105
106 return 1; 106 ret = 1;
107
108 err:
109 CMAC_CTX_free(cmkey);
110
111 return ret;
107} 112}
108 113
109static int 114static int