summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2022-01-15 04:02:38 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2022-01-15 04:02:38 +0000
commite1f96b5341dea12ce7ec2e2b92b305bdcfaedc43 (patch)
treecd6557ac8e6bfdf9227025adfb1a99857a8f08d0 /lib
parent53d919a595a7f8e0c086114f568e1fcbab82cf0d (diff)
Minor cleanup and simplification in dsa_pub_encode()
This function has a weird dance of allocating an ASN1_STRING in an inner scope and assigning it to a void pointer in an outer scope for passing it to X509_PUBKEY_set0_param() and ASN1_STRING_free() on error. This can be simplified and streamlined. ok inoguchi
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/dsa/dsa_ameth.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/lib/libcrypto/dsa/dsa_ameth.c b/lib/libcrypto/dsa/dsa_ameth.c
index 5fff2890a2f..4e8f4ac8253 100644
--- a/lib/libcrypto/dsa/dsa_ameth.c
+++ b/lib/libcrypto/dsa/dsa_ameth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dsa_ameth.c,v 1.31 2022/01/14 08:29:06 tb Exp $ */
+/* $OpenBSD: dsa_ameth.c,v 1.32 2022/01/15 04:02:37 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@@ -134,31 +134,24 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
{
DSA *dsa;
ASN1_INTEGER *pubint = NULL;
- void *pval = NULL;
- int ptype;
+ ASN1_STRING *str = NULL;
+ int ptype = V_ASN1_UNDEF;
unsigned char *penc = NULL;
int penclen;
dsa = pkey->pkey.dsa;
if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) {
- ASN1_STRING *str;
-
- str = ASN1_STRING_new();
- if (str == NULL) {
+ if ((str = ASN1_STRING_new()) == NULL) {
DSAerror(ERR_R_MALLOC_FAILURE);
goto err;
}
str->length = i2d_DSAparams(dsa, &str->data);
if (str->length <= 0) {
DSAerror(ERR_R_MALLOC_FAILURE);
- ASN1_STRING_free(str);
goto err;
}
- pval = str;
ptype = V_ASN1_SEQUENCE;
- } else
- ptype = V_ASN1_UNDEF;
-
+ }
if ((pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) {
DSAerror(ERR_R_MALLOC_FAILURE);
@@ -173,13 +166,13 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
goto err;
}
- if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA), ptype, pval,
+ if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA), ptype, str,
penc, penclen))
return 1;
-err:
+ err:
free(penc);
- ASN1_STRING_free(pval);
+ ASN1_STRING_free(str);
return 0;
}