diff options
author | tb <> | 2022-01-15 04:02:37 +0000 |
---|---|---|
committer | tb <> | 2022-01-15 04:02:37 +0000 |
commit | cbab7089b7297d8aeb708a99bc2b6052d2e5a2ab (patch) | |
tree | d132b96606bdc22d0065ebb3d1356464b3119060 /src | |
parent | 838b8b87f8aca8de4ee4ea2dedeb61771835a9a0 (diff) | |
download | openbsd-cbab7089b7297d8aeb708a99bc2b6052d2e5a2ab.tar.gz openbsd-cbab7089b7297d8aeb708a99bc2b6052d2e5a2ab.tar.bz2 openbsd-cbab7089b7297d8aeb708a99bc2b6052d2e5a2ab.zip |
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 'src')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_ameth.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c index 5fff2890a2..4e8f4ac825 100644 --- a/src/lib/libcrypto/dsa/dsa_ameth.c +++ b/src/lib/libcrypto/dsa/dsa_ameth.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dsa_ameth.c,v 1.31 2022/01/14 08:29:06 tb Exp $ */ | 1 | /* $OpenBSD: dsa_ameth.c,v 1.32 2022/01/15 04:02:37 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 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -134,31 +134,24 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) | |||
134 | { | 134 | { |
135 | DSA *dsa; | 135 | DSA *dsa; |
136 | ASN1_INTEGER *pubint = NULL; | 136 | ASN1_INTEGER *pubint = NULL; |
137 | void *pval = NULL; | 137 | ASN1_STRING *str = NULL; |
138 | int ptype; | 138 | int ptype = V_ASN1_UNDEF; |
139 | unsigned char *penc = NULL; | 139 | unsigned char *penc = NULL; |
140 | int penclen; | 140 | int penclen; |
141 | 141 | ||
142 | dsa = pkey->pkey.dsa; | 142 | dsa = pkey->pkey.dsa; |
143 | if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { | 143 | if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { |
144 | ASN1_STRING *str; | 144 | if ((str = ASN1_STRING_new()) == NULL) { |
145 | |||
146 | str = ASN1_STRING_new(); | ||
147 | if (str == NULL) { | ||
148 | DSAerror(ERR_R_MALLOC_FAILURE); | 145 | DSAerror(ERR_R_MALLOC_FAILURE); |
149 | goto err; | 146 | goto err; |
150 | } | 147 | } |
151 | str->length = i2d_DSAparams(dsa, &str->data); | 148 | str->length = i2d_DSAparams(dsa, &str->data); |
152 | if (str->length <= 0) { | 149 | if (str->length <= 0) { |
153 | DSAerror(ERR_R_MALLOC_FAILURE); | 150 | DSAerror(ERR_R_MALLOC_FAILURE); |
154 | ASN1_STRING_free(str); | ||
155 | goto err; | 151 | goto err; |
156 | } | 152 | } |
157 | pval = str; | ||
158 | ptype = V_ASN1_SEQUENCE; | 153 | ptype = V_ASN1_SEQUENCE; |
159 | } else | 154 | } |
160 | ptype = V_ASN1_UNDEF; | ||
161 | |||
162 | 155 | ||
163 | if ((pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) { | 156 | if ((pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) { |
164 | DSAerror(ERR_R_MALLOC_FAILURE); | 157 | DSAerror(ERR_R_MALLOC_FAILURE); |
@@ -173,13 +166,13 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) | |||
173 | goto err; | 166 | goto err; |
174 | } | 167 | } |
175 | 168 | ||
176 | if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA), ptype, pval, | 169 | if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA), ptype, str, |
177 | penc, penclen)) | 170 | penc, penclen)) |
178 | return 1; | 171 | return 1; |
179 | 172 | ||
180 | err: | 173 | err: |
181 | free(penc); | 174 | free(penc); |
182 | ASN1_STRING_free(pval); | 175 | ASN1_STRING_free(str); |
183 | 176 | ||
184 | return 0; | 177 | return 0; |
185 | } | 178 | } |