diff options
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_ameth.c')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_ameth.c | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c index 529bab4d47..494bef3ce4 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.50 2023/08/11 13:53:45 tb Exp $ */ | 1 | /* $OpenBSD: dsa_ameth.c,v 1.51 2023/08/11 13:57:24 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 | */ |
| @@ -78,23 +78,23 @@ dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) | |||
| 78 | X509_ALGOR *algor; | 78 | X509_ALGOR *algor; |
| 79 | int ptype; | 79 | int ptype; |
| 80 | const void *pval; | 80 | const void *pval; |
| 81 | const ASN1_STRING *params; | 81 | const ASN1_STRING *astr; |
| 82 | const unsigned char *key_der, *params_der, *p; | 82 | const unsigned char *key, *params, *p; |
| 83 | int key_len, params_len; | 83 | int key_len, params_len; |
| 84 | ASN1_INTEGER *key = NULL; | 84 | ASN1_INTEGER *aint = NULL; |
| 85 | DSA *dsa = NULL; | 85 | DSA *dsa = NULL; |
| 86 | int ret = 0; | 86 | int ret = 0; |
| 87 | 87 | ||
| 88 | if (!X509_PUBKEY_get0_param(NULL, &key_der, &key_len, &algor, pubkey)) | 88 | if (!X509_PUBKEY_get0_param(NULL, &key, &key_len, &algor, pubkey)) |
| 89 | goto err; | 89 | goto err; |
| 90 | X509_ALGOR_get0(NULL, &ptype, &pval, algor); | 90 | X509_ALGOR_get0(NULL, &ptype, &pval, algor); |
| 91 | 91 | ||
| 92 | if (ptype == V_ASN1_SEQUENCE) { | 92 | if (ptype == V_ASN1_SEQUENCE) { |
| 93 | params = pval; | 93 | astr = pval; |
| 94 | params_der = params->data; | 94 | params = astr->data; |
| 95 | params_len = params->length; | 95 | params_len = astr->length; |
| 96 | 96 | ||
| 97 | p = params_der; | 97 | p = params; |
| 98 | if ((dsa = d2i_DSAparams(NULL, &p, params_len)) == NULL) { | 98 | if ((dsa = d2i_DSAparams(NULL, &p, params_len)) == NULL) { |
| 99 | DSAerror(DSA_R_DECODE_ERROR); | 99 | DSAerror(DSA_R_DECODE_ERROR); |
| 100 | goto err; | 100 | goto err; |
| @@ -109,12 +109,12 @@ dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) | |||
| 109 | goto err; | 109 | goto err; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | p = key_der; | 112 | p = key; |
| 113 | if ((key = d2i_ASN1_INTEGER(NULL, &p, key_len)) == NULL) { | 113 | if ((aint = d2i_ASN1_INTEGER(NULL, &p, key_len)) == NULL) { |
| 114 | DSAerror(DSA_R_DECODE_ERROR); | 114 | DSAerror(DSA_R_DECODE_ERROR); |
| 115 | goto err; | 115 | goto err; |
| 116 | } | 116 | } |
| 117 | if ((dsa->pub_key = ASN1_INTEGER_to_BN(key, NULL)) == NULL) { | 117 | if ((dsa->pub_key = ASN1_INTEGER_to_BN(aint, NULL)) == NULL) { |
| 118 | DSAerror(DSA_R_BN_DECODE_ERROR); | 118 | DSAerror(DSA_R_BN_DECODE_ERROR); |
| 119 | goto err; | 119 | goto err; |
| 120 | } | 120 | } |
| @@ -132,7 +132,7 @@ dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) | |||
| 132 | ret = 1; | 132 | ret = 1; |
| 133 | 133 | ||
| 134 | err: | 134 | err: |
| 135 | ASN1_INTEGER_free(key); | 135 | ASN1_INTEGER_free(aint); |
| 136 | DSA_free(dsa); | 136 | DSA_free(dsa); |
| 137 | 137 | ||
| 138 | return ret; | 138 | return ret; |
| @@ -142,35 +142,35 @@ static int | |||
| 142 | dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) | 142 | dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) |
| 143 | { | 143 | { |
| 144 | const DSA *dsa = pkey->pkey.dsa; | 144 | const DSA *dsa = pkey->pkey.dsa; |
| 145 | ASN1_STRING *params = NULL; | 145 | ASN1_STRING *astr = NULL; |
| 146 | int ptype = V_ASN1_UNDEF; | 146 | int ptype = V_ASN1_UNDEF; |
| 147 | ASN1_INTEGER *key = NULL; | 147 | ASN1_INTEGER *aint = NULL; |
| 148 | ASN1_OBJECT *aobj; | 148 | ASN1_OBJECT *aobj; |
| 149 | unsigned char *params_der = NULL, *key_der = NULL; | 149 | unsigned char *params = NULL, *key = NULL; |
| 150 | int params_len = 0, key_len = 0; | 150 | int params_len = 0, key_len = 0; |
| 151 | int ret = 0; | 151 | int ret = 0; |
| 152 | 152 | ||
| 153 | if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { | 153 | if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { |
| 154 | if ((params_len = i2d_DSAparams(dsa, ¶ms_der)) <= 0) { | 154 | if ((params_len = i2d_DSAparams(dsa, ¶ms)) <= 0) { |
| 155 | DSAerror(ERR_R_MALLOC_FAILURE); | 155 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 156 | params_len = 0; | 156 | params_len = 0; |
| 157 | goto err; | 157 | goto err; |
| 158 | } | 158 | } |
| 159 | if ((params = ASN1_STRING_new()) == NULL) { | 159 | if ((astr = ASN1_STRING_new()) == NULL) { |
| 160 | DSAerror(ERR_R_MALLOC_FAILURE); | 160 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 161 | goto err; | 161 | goto err; |
| 162 | } | 162 | } |
| 163 | ASN1_STRING_set0(params, params_der, params_len); | 163 | ASN1_STRING_set0(astr, params, params_len); |
| 164 | params_der = NULL; | 164 | params = NULL; |
| 165 | params_len = 0; | 165 | params_len = 0; |
| 166 | ptype = V_ASN1_SEQUENCE; | 166 | ptype = V_ASN1_SEQUENCE; |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | if ((key = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) { | 169 | if ((aint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) { |
| 170 | DSAerror(ERR_R_MALLOC_FAILURE); | 170 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 171 | goto err; | 171 | goto err; |
| 172 | } | 172 | } |
| 173 | if ((key_len = i2d_ASN1_INTEGER(key, &key_der)) <= 0) { | 173 | if ((key_len = i2d_ASN1_INTEGER(aint, &key)) <= 0) { |
| 174 | DSAerror(ERR_R_MALLOC_FAILURE); | 174 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 175 | key_len = 0; | 175 | key_len = 0; |
| 176 | goto err; | 176 | goto err; |
| @@ -178,19 +178,19 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) | |||
| 178 | 178 | ||
| 179 | if ((aobj = OBJ_nid2obj(EVP_PKEY_DSA)) == NULL) | 179 | if ((aobj = OBJ_nid2obj(EVP_PKEY_DSA)) == NULL) |
| 180 | goto err; | 180 | goto err; |
| 181 | if (!X509_PUBKEY_set0_param(pk, aobj, ptype, params, key_der, key_len)) | 181 | if (!X509_PUBKEY_set0_param(pk, aobj, ptype, astr, key, key_len)) |
| 182 | goto err; | 182 | goto err; |
| 183 | params = NULL; | 183 | astr = NULL; |
| 184 | key_der = NULL; | 184 | key = NULL; |
| 185 | key_len = 0; | 185 | key_len = 0; |
| 186 | 186 | ||
| 187 | ret = 1; | 187 | ret = 1; |
| 188 | 188 | ||
| 189 | err: | 189 | err: |
| 190 | ASN1_STRING_free(params); | 190 | ASN1_STRING_free(astr); |
| 191 | ASN1_INTEGER_free(key); | 191 | ASN1_INTEGER_free(aint); |
| 192 | freezero(params_der, params_len); | 192 | freezero(params, params_len); |
| 193 | freezero(key_der, key_len); | 193 | freezero(key, key_len); |
| 194 | 194 | ||
| 195 | return ret; | 195 | return ret; |
| 196 | } | 196 | } |
| @@ -205,15 +205,15 @@ dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) | |||
| 205 | const X509_ALGOR *algor; | 205 | const X509_ALGOR *algor; |
| 206 | int ptype; | 206 | int ptype; |
| 207 | const void *pval; | 207 | const void *pval; |
| 208 | const ASN1_STRING *params; | 208 | const ASN1_STRING *astr; |
| 209 | const unsigned char *key_der, *params_der, *p; | 209 | const unsigned char *key, *params, *p; |
| 210 | int key_len, params_len; | 210 | int key_len, params_len; |
| 211 | ASN1_INTEGER *key = NULL; | 211 | ASN1_INTEGER *aint = NULL; |
| 212 | BN_CTX *ctx = NULL; | 212 | BN_CTX *ctx = NULL; |
| 213 | DSA *dsa = NULL; | 213 | DSA *dsa = NULL; |
| 214 | int ret = 0; | 214 | int ret = 0; |
| 215 | 215 | ||
| 216 | if (!PKCS8_pkey_get0(NULL, &key_der, &key_len, &algor, p8)) | 216 | if (!PKCS8_pkey_get0(NULL, &key, &key_len, &algor, p8)) |
| 217 | goto err; | 217 | goto err; |
| 218 | X509_ALGOR_get0(NULL, &ptype, &pval, algor); | 218 | X509_ALGOR_get0(NULL, &ptype, &pval, algor); |
| 219 | 219 | ||
| @@ -222,21 +222,21 @@ dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) | |||
| 222 | goto err; | 222 | goto err; |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | params = pval; | 225 | astr = pval; |
| 226 | params_der = params->data; | 226 | params = astr->data; |
| 227 | params_len = params->length; | 227 | params_len = astr->length; |
| 228 | 228 | ||
| 229 | p = params_der; | 229 | p = params; |
| 230 | if ((dsa = d2i_DSAparams(NULL, &p, params_len)) == NULL) { | 230 | if ((dsa = d2i_DSAparams(NULL, &p, params_len)) == NULL) { |
| 231 | DSAerror(DSA_R_DECODE_ERROR); | 231 | DSAerror(DSA_R_DECODE_ERROR); |
| 232 | goto err; | 232 | goto err; |
| 233 | } | 233 | } |
| 234 | p = key_der; | 234 | p = key; |
| 235 | if ((key = d2i_ASN1_INTEGER(NULL, &p, key_len)) == NULL) { | 235 | if ((aint = d2i_ASN1_INTEGER(NULL, &p, key_len)) == NULL) { |
| 236 | DSAerror(DSA_R_DECODE_ERROR); | 236 | DSAerror(DSA_R_DECODE_ERROR); |
| 237 | goto err; | 237 | goto err; |
| 238 | } | 238 | } |
| 239 | if ((dsa->priv_key = ASN1_INTEGER_to_BN(key, NULL)) == NULL) { | 239 | if ((dsa->priv_key = ASN1_INTEGER_to_BN(aint, NULL)) == NULL) { |
| 240 | DSAerror(DSA_R_BN_DECODE_ERROR); | 240 | DSAerror(DSA_R_BN_DECODE_ERROR); |
| 241 | goto err; | 241 | goto err; |
| 242 | } | 242 | } |
| @@ -273,7 +273,7 @@ dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) | |||
| 273 | DSA_free(dsa); | 273 | DSA_free(dsa); |
| 274 | BN_CTX_end(ctx); | 274 | BN_CTX_end(ctx); |
| 275 | BN_CTX_free(ctx); | 275 | BN_CTX_free(ctx); |
| 276 | ASN1_INTEGER_free(key); | 276 | ASN1_INTEGER_free(aint); |
| 277 | 277 | ||
| 278 | return ret; | 278 | return ret; |
| 279 | } | 279 | } |
| @@ -282,32 +282,32 @@ static int | |||
| 282 | dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) | 282 | dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) |
| 283 | { | 283 | { |
| 284 | const DSA *dsa = pkey->pkey.dsa; | 284 | const DSA *dsa = pkey->pkey.dsa; |
| 285 | ASN1_STRING *params = NULL; | 285 | ASN1_STRING *astr = NULL; |
| 286 | int ptype = V_ASN1_SEQUENCE; | 286 | int ptype = V_ASN1_SEQUENCE; |
| 287 | ASN1_INTEGER *key = NULL; | 287 | ASN1_INTEGER *aint = NULL; |
| 288 | ASN1_OBJECT *aobj; | 288 | ASN1_OBJECT *aobj; |
| 289 | unsigned char *params_der = NULL, *key_der = NULL; | 289 | unsigned char *params = NULL, *key = NULL; |
| 290 | int params_len = 0, key_len = 0; | 290 | int params_len = 0, key_len = 0; |
| 291 | int ret = 0; | 291 | int ret = 0; |
| 292 | 292 | ||
| 293 | if ((params_len = i2d_DSAparams(dsa, ¶ms_der)) <= 0) { | 293 | if ((params_len = i2d_DSAparams(dsa, ¶ms)) <= 0) { |
| 294 | DSAerror(ERR_R_MALLOC_FAILURE); | 294 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 295 | params_len = 0; | 295 | params_len = 0; |
| 296 | goto err; | 296 | goto err; |
| 297 | } | 297 | } |
| 298 | if ((params = ASN1_STRING_type_new(V_ASN1_SEQUENCE)) == NULL) { | 298 | if ((astr = ASN1_STRING_type_new(V_ASN1_SEQUENCE)) == NULL) { |
| 299 | DSAerror(ERR_R_MALLOC_FAILURE); | 299 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 300 | goto err; | 300 | goto err; |
| 301 | } | 301 | } |
| 302 | ASN1_STRING_set0(params, params_der, params_len); | 302 | ASN1_STRING_set0(astr, params, params_len); |
| 303 | params_der = NULL; | 303 | params = NULL; |
| 304 | params_len = 0; | 304 | params_len = 0; |
| 305 | 305 | ||
| 306 | if ((key = BN_to_ASN1_INTEGER(dsa->priv_key, NULL)) == NULL) { | 306 | if ((aint = BN_to_ASN1_INTEGER(dsa->priv_key, NULL)) == NULL) { |
| 307 | DSAerror(DSA_R_BN_ERROR); | 307 | DSAerror(DSA_R_BN_ERROR); |
| 308 | goto err; | 308 | goto err; |
| 309 | } | 309 | } |
| 310 | if ((key_len = i2d_ASN1_INTEGER(key, &key_der)) <= 0) { | 310 | if ((key_len = i2d_ASN1_INTEGER(aint, &key)) <= 0) { |
| 311 | DSAerror(ERR_R_MALLOC_FAILURE); | 311 | DSAerror(ERR_R_MALLOC_FAILURE); |
| 312 | key_len = 0; | 312 | key_len = 0; |
| 313 | goto err; | 313 | goto err; |
| @@ -315,19 +315,19 @@ dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) | |||
| 315 | 315 | ||
| 316 | if ((aobj = OBJ_nid2obj(NID_dsa)) == NULL) | 316 | if ((aobj = OBJ_nid2obj(NID_dsa)) == NULL) |
| 317 | goto err; | 317 | goto err; |
| 318 | if (!PKCS8_pkey_set0(p8, aobj, 0, ptype, params, key_der, key_len)) | 318 | if (!PKCS8_pkey_set0(p8, aobj, 0, ptype, astr, key, key_len)) |
| 319 | goto err; | 319 | goto err; |
| 320 | params = NULL; | 320 | astr = NULL; |
| 321 | key_der = NULL; | 321 | key = NULL; |
| 322 | key_len = 0; | 322 | key_len = 0; |
| 323 | 323 | ||
| 324 | ret = 1; | 324 | ret = 1; |
| 325 | 325 | ||
| 326 | err: | 326 | err: |
| 327 | ASN1_STRING_free(params); | 327 | ASN1_STRING_free(astr); |
| 328 | ASN1_INTEGER_free(key); | 328 | ASN1_INTEGER_free(aint); |
| 329 | freezero(params_der, params_len); | 329 | freezero(params, params_len); |
| 330 | freezero(key_der, key_len); | 330 | freezero(key, key_len); |
| 331 | 331 | ||
| 332 | return ret; | 332 | return ret; |
| 333 | } | 333 | } |
