From 1f4f3b5be931cc066ccd9a45ccffcfc8a923888c Mon Sep 17 00:00:00 2001 From: tb Date: Thu, 28 Dec 2023 21:53:09 +0000 Subject: [PATCH] Replace EVP_KEY_assign_GOST() calls with EVP_PKEY_set_type() Calling EVP_KEY_assign_GOST(pkey, NULL) has the same effect as calling EVP_PKEY_set_type(pkey, EVP_PKEY_GOSTR01). The only difference is that the latter form allows for error checking while the former won't let you do that. Add comments explaining what we're actually doing: freeing and zeroing the pkey->pkey union. ok jsing --- lib/libcrypto/gost/gostr341001_ameth.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/libcrypto/gost/gostr341001_ameth.c b/lib/libcrypto/gost/gostr341001_ameth.c index 9098797adec..fc3bce412aa 100644 --- a/lib/libcrypto/gost/gostr341001_ameth.c +++ b/lib/libcrypto/gost/gostr341001_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gostr341001_ameth.c,v 1.21 2023/12/28 21:49:07 tb Exp $ */ +/* $OpenBSD: gostr341001_ameth.c,v 1.22 2023/12/28 21:53:09 tb Exp $ */ /* * Copyright (c) 2014 Dmitry Eremin-Solenikov * Copyright (c) 2005-2006 Cryptocom LTD @@ -207,7 +207,9 @@ pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub) if (X509_PUBKEY_get0_param(&palgobj, &pubkey_buf, &pub_len, &palg, pub) == 0) return 0; - (void)EVP_PKEY_assign_GOST(pk, NULL); + /* Called for the side effect of freeing pk->pkey. */ + if (!EVP_PKEY_set_type(pk, EVP_PKEY_GOSTR01)) + return 0; X509_ALGOR_get0(NULL, &ptype, (const void **)&pval, palg); if (ptype != V_ASN1_SEQUENCE) { GOSTerror(GOST_R_BAD_KEY_PARAMETERS_FORMAT); @@ -420,7 +422,9 @@ priv_decode_gost01(EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf) GOSTerror(GOST_R_BAD_KEY_PARAMETERS_FORMAT); return 0; } - (void)EVP_PKEY_assign_GOST(pk, NULL); + /* Called for the side effect of freeing pk->pkey. */ + if (!EVP_PKEY_set_type(pk, EVP_PKEY_GOSTR01)) + return 0; X509_ALGOR_get0(NULL, &ptype, (const void **)&pval, palg); if (ptype != V_ASN1_SEQUENCE) { GOSTerror(GOST_R_BAD_KEY_PARAMETERS_FORMAT); -- 2.20.1