diff options
| author | tb <> | 2023-08-10 16:57:15 +0000 |
|---|---|---|
| committer | tb <> | 2023-08-10 16:57:15 +0000 |
| commit | 77774e4ae96f2f49858b5c28789db495a4c52e9a (patch) | |
| tree | 40fb1e987c47592cf52cff6541c9dc6003e655f6 /src/lib/libcrypto/dsa | |
| parent | 5cc0283faaa330727bf60cb28b60c2683daf00fc (diff) | |
| download | openbsd-77774e4ae96f2f49858b5c28789db495a4c52e9a.tar.gz openbsd-77774e4ae96f2f49858b5c28789db495a4c52e9a.tar.bz2 openbsd-77774e4ae96f2f49858b5c28789db495a4c52e9a.zip | |
Convert {dh,dsa}_{pub,priv}_encode() to single exit
Use the same variable names throughout these functions and unify them
some more.
ok jsing
Diffstat (limited to 'src/lib/libcrypto/dsa')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_ameth.c | 89 |
1 files changed, 47 insertions, 42 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c index aab4588b5a..28aafebc04 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.45 2023/08/10 15:11:16 tb Exp $ */ | 1 | /* $OpenBSD: dsa_ameth.c,v 1.46 2023/08/10 16:57:15 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 | */ |
| @@ -139,55 +139,57 @@ static int | |||
| 139 | dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) | 139 | dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) |
| 140 | { | 140 | { |
| 141 | const DSA *dsa = pkey->pkey.dsa; | 141 | const DSA *dsa = pkey->pkey.dsa; |
| 142 | ASN1_STRING *str = NULL; | 142 | ASN1_STRING *params = NULL; |
| 143 | int ptype = V_ASN1_UNDEF; | 143 | int ptype = V_ASN1_UNDEF; |
| 144 | ASN1_INTEGER *pub_key = NULL; | 144 | ASN1_INTEGER *key = NULL; |
| 145 | ASN1_OBJECT *aobj; | 145 | ASN1_OBJECT *aobj; |
| 146 | unsigned char *data = NULL, *penc = NULL; | 146 | unsigned char *params_der = NULL, *key_der = NULL; |
| 147 | int datalen = 0, penclen = 0; | 147 | int params_len = 0, key_len = 0; |
| 148 | int ret = 0; | ||
| 148 | 149 | ||
| 149 | if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { | 150 | if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { |
| 150 | if ((datalen = i2d_DSAparams(dsa, &data)) <= 0) { | 151 | if ((params_len = i2d_DSAparams(dsa, ¶ms_der)) <= 0) { |
| 151 | DSAerror(ERR_R_MALLOC_FAILURE); | 152 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 152 | datalen = 0; | 153 | params_len = 0; |
| 153 | goto err; | 154 | goto err; |
| 154 | } | 155 | } |
| 155 | if ((str = ASN1_STRING_new()) == NULL) { | 156 | if ((params = ASN1_STRING_new()) == NULL) { |
| 156 | DSAerror(ERR_R_MALLOC_FAILURE); | 157 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 157 | goto err; | 158 | goto err; |
| 158 | } | 159 | } |
| 159 | ASN1_STRING_set0(str, data, datalen); | 160 | ASN1_STRING_set0(params, params_der, params_len); |
| 160 | data = NULL; | 161 | params_der = NULL; |
| 161 | datalen = 0; | 162 | params_len = 0; |
| 162 | ptype = V_ASN1_SEQUENCE; | 163 | ptype = V_ASN1_SEQUENCE; |
| 163 | } | 164 | } |
| 164 | 165 | ||
| 165 | if ((pub_key = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) { | 166 | if ((key = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) { |
| 166 | DSAerror(ERR_R_MALLOC_FAILURE); | 167 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 167 | goto err; | 168 | goto err; |
| 168 | } | 169 | } |
| 169 | if ((penclen = i2d_ASN1_INTEGER(pub_key, &penc)) <= 0) { | 170 | if ((key_len = i2d_ASN1_INTEGER(key, &key_der)) <= 0) { |
| 170 | DSAerror(ERR_R_MALLOC_FAILURE); | 171 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 171 | penclen = 0; | 172 | key_len = 0; |
| 172 | goto err; | 173 | goto err; |
| 173 | } | 174 | } |
| 174 | ASN1_INTEGER_free(pub_key); | ||
| 175 | pub_key = NULL; | ||
| 176 | 175 | ||
| 177 | if ((aobj = OBJ_nid2obj(EVP_PKEY_DSA)) == NULL) | 176 | if ((aobj = OBJ_nid2obj(EVP_PKEY_DSA)) == NULL) |
| 178 | goto err; | 177 | goto err; |
| 179 | if (!X509_PUBKEY_set0_param(pk, aobj, ptype, str, penc, penclen)) | 178 | if (!X509_PUBKEY_set0_param(pk, aobj, ptype, params, key_der, key_len)) |
| 180 | goto err; | 179 | goto err; |
| 180 | params = NULL; | ||
| 181 | key_der = NULL; | ||
| 182 | key_len = 0; | ||
| 181 | 183 | ||
| 182 | return 1; | 184 | ret = 1; |
| 183 | 185 | ||
| 184 | err: | 186 | err: |
| 185 | ASN1_STRING_free(str); | 187 | ASN1_STRING_free(params); |
| 186 | ASN1_INTEGER_free(pub_key); | 188 | ASN1_INTEGER_free(key); |
| 187 | freezero(data, datalen); | 189 | freezero(params_der, params_len); |
| 188 | freezero(penc, penclen); | 190 | freezero(key_der, key_len); |
| 189 | 191 | ||
| 190 | return 0; | 192 | return ret; |
| 191 | } | 193 | } |
| 192 | 194 | ||
| 193 | /* In PKCS#8 DSA: you just get a private key integer and parameters in the | 195 | /* In PKCS#8 DSA: you just get a private key integer and parameters in the |
| @@ -274,50 +276,53 @@ dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) | |||
| 274 | { | 276 | { |
| 275 | const DSA *dsa = pkey->pkey.dsa; | 277 | const DSA *dsa = pkey->pkey.dsa; |
| 276 | ASN1_STRING *params = NULL; | 278 | ASN1_STRING *params = NULL; |
| 277 | ASN1_INTEGER *prkey = NULL; | 279 | int ptype = V_ASN1_SEQUENCE; |
| 280 | ASN1_INTEGER *key = NULL; | ||
| 278 | ASN1_OBJECT *aobj; | 281 | ASN1_OBJECT *aobj; |
| 279 | unsigned char *data = NULL, *dp = NULL; | 282 | unsigned char *params_der = NULL, *key_der = NULL; |
| 280 | int datalen = 0, dplen = 0; | 283 | int params_len = 0, key_len = 0; |
| 284 | int ret = 0; | ||
| 281 | 285 | ||
| 282 | if ((datalen = i2d_DSAparams(dsa, &data)) <= 0) { | 286 | if ((params_len = i2d_DSAparams(dsa, ¶ms_der)) <= 0) { |
| 283 | DSAerror(ERR_R_MALLOC_FAILURE); | 287 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 284 | datalen = 0; | 288 | params_len = 0; |
| 285 | goto err; | 289 | goto err; |
| 286 | } | 290 | } |
| 287 | if ((params = ASN1_STRING_type_new(V_ASN1_SEQUENCE)) == NULL) { | 291 | if ((params = ASN1_STRING_type_new(V_ASN1_SEQUENCE)) == NULL) { |
| 288 | DSAerror(ERR_R_MALLOC_FAILURE); | 292 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 289 | goto err; | 293 | goto err; |
| 290 | } | 294 | } |
| 291 | ASN1_STRING_set0(params, data, datalen); | 295 | ASN1_STRING_set0(params, params_der, params_len); |
| 292 | data = NULL; | 296 | params_der = NULL; |
| 293 | datalen = 0; | 297 | params_len = 0; |
| 294 | 298 | ||
| 295 | if ((prkey = BN_to_ASN1_INTEGER(dsa->priv_key, NULL)) == NULL) { | 299 | if ((key = BN_to_ASN1_INTEGER(dsa->priv_key, NULL)) == NULL) { |
| 296 | DSAerror(DSA_R_BN_ERROR); | 300 | DSAerror(DSA_R_BN_ERROR); |
| 297 | goto err; | 301 | goto err; |
| 298 | } | 302 | } |
| 299 | if ((dplen = i2d_ASN1_INTEGER(prkey, &dp)) <= 0) { | 303 | if ((key_len = i2d_ASN1_INTEGER(key, &key_der)) <= 0) { |
| 300 | DSAerror(ERR_R_MALLOC_FAILURE); | 304 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 301 | dplen = 0; | 305 | key_len = 0; |
| 302 | goto err; | 306 | goto err; |
| 303 | } | 307 | } |
| 304 | ASN1_INTEGER_free(prkey); | ||
| 305 | prkey = NULL; | ||
| 306 | 308 | ||
| 307 | if ((aobj = OBJ_nid2obj(NID_dsa)) == NULL) | 309 | if ((aobj = OBJ_nid2obj(NID_dsa)) == NULL) |
| 308 | goto err; | 310 | goto err; |
| 309 | if (!PKCS8_pkey_set0(p8, aobj, 0, V_ASN1_SEQUENCE, params, dp, dplen)) | 311 | if (!PKCS8_pkey_set0(p8, aobj, 0, ptype, params, key_der, key_len)) |
| 310 | goto err; | 312 | goto err; |
| 313 | params = NULL; | ||
| 314 | key_der = NULL; | ||
| 315 | key_len = 0; | ||
| 311 | 316 | ||
| 312 | return 1; | 317 | ret = 1; |
| 313 | 318 | ||
| 314 | err: | 319 | err: |
| 315 | ASN1_STRING_free(params); | 320 | ASN1_STRING_free(params); |
| 316 | ASN1_INTEGER_free(prkey); | 321 | ASN1_INTEGER_free(key); |
| 317 | freezero(data, datalen); | 322 | freezero(params_der, params_len); |
| 318 | freezero(dp, dplen); | 323 | freezero(key_der, key_len); |
| 319 | 324 | ||
| 320 | return 0; | 325 | return ret; |
| 321 | } | 326 | } |
| 322 | 327 | ||
| 323 | static int | 328 | static int |
