diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_ameth.c | 80 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/dsa/dsa_ameth.c | 80 |
2 files changed, 40 insertions, 120 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c index 9bef6e5a13..a6e21a688e 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.18 2015/09/10 18:12:55 miod Exp $ */ | 1 | /* $OpenBSD: dsa_ameth.c,v 1.19 2016/03/01 07:04:41 doug 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 | */ |
| @@ -181,7 +181,6 @@ err: | |||
| 181 | /* In PKCS#8 DSA: you just get a private key integer and parameters in the | 181 | /* In PKCS#8 DSA: you just get a private key integer and parameters in the |
| 182 | * AlgorithmIdentifier the pubkey must be recalculated. | 182 | * AlgorithmIdentifier the pubkey must be recalculated. |
| 183 | */ | 183 | */ |
| 184 | |||
| 185 | static int | 184 | static int |
| 186 | dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) | 185 | dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) |
| 187 | { | 186 | { |
| @@ -193,56 +192,22 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) | |||
| 193 | X509_ALGOR *palg; | 192 | X509_ALGOR *palg; |
| 194 | ASN1_INTEGER *privkey = NULL; | 193 | ASN1_INTEGER *privkey = NULL; |
| 195 | BN_CTX *ctx = NULL; | 194 | BN_CTX *ctx = NULL; |
| 196 | STACK_OF(ASN1_TYPE) *ndsa = NULL; | ||
| 197 | DSA *dsa = NULL; | 195 | DSA *dsa = NULL; |
| 198 | 196 | ||
| 197 | int ret = 0; | ||
| 198 | |||
| 199 | if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8)) | 199 | if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8)) |
| 200 | return 0; | 200 | return 0; |
| 201 | X509_ALGOR_get0(NULL, &ptype, &pval, palg); | 201 | X509_ALGOR_get0(NULL, &ptype, &pval, palg); |
| 202 | if (ptype != V_ASN1_SEQUENCE) | ||
| 203 | goto decerr; | ||
| 202 | 204 | ||
| 203 | /* Check for broken DSA PKCS#8, UGH! */ | 205 | if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL) |
| 204 | if (*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) { | 206 | goto decerr; |
| 205 | ASN1_TYPE *t1, *t2; | 207 | if (privkey->type == V_ASN1_NEG_INTEGER) |
| 206 | if (!(ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen))) | 208 | goto decerr; |
| 207 | goto decerr; | ||
| 208 | if (sk_ASN1_TYPE_num(ndsa) != 2) | ||
| 209 | goto decerr; | ||
| 210 | /* | ||
| 211 | * Handle Two broken types: | ||
| 212 | * SEQUENCE {parameters, priv_key} | ||
| 213 | * SEQUENCE {pub_key, priv_key} | ||
| 214 | */ | ||
| 215 | |||
| 216 | t1 = sk_ASN1_TYPE_value(ndsa, 0); | ||
| 217 | t2 = sk_ASN1_TYPE_value(ndsa, 1); | ||
| 218 | if (t1->type == V_ASN1_SEQUENCE) { | ||
| 219 | p8->broken = PKCS8_EMBEDDED_PARAM; | ||
| 220 | pval = t1->value.ptr; | ||
| 221 | } else if (ptype == V_ASN1_SEQUENCE) | ||
| 222 | p8->broken = PKCS8_NS_DB; | ||
| 223 | else | ||
| 224 | goto decerr; | ||
| 225 | |||
| 226 | if (t2->type != V_ASN1_INTEGER) | ||
| 227 | goto decerr; | ||
| 228 | |||
| 229 | privkey = t2->value.integer; | ||
| 230 | } else { | ||
| 231 | const unsigned char *q = p; | ||
| 232 | |||
| 233 | if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen))) | ||
| 234 | goto decerr; | ||
| 235 | if (privkey->type == V_ASN1_NEG_INTEGER) { | ||
| 236 | p8->broken = PKCS8_NEG_PRIVKEY; | ||
| 237 | ASN1_INTEGER_free(privkey); | ||
| 238 | if (!(privkey = d2i_ASN1_UINTEGER(NULL, &q, pklen))) | ||
| 239 | goto decerr; | ||
| 240 | } | ||
| 241 | if (ptype != V_ASN1_SEQUENCE) | ||
| 242 | goto decerr; | ||
| 243 | } | ||
| 244 | 209 | ||
| 245 | pstr = pval; | 210 | pstr = pval; |
| 246 | pm = pstr->data; | 211 | pm = pstr->data; |
| 247 | pmlen = pstr->length; | 212 | pmlen = pstr->length; |
| 248 | if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) | 213 | if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) |
| @@ -261,31 +226,26 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) | |||
| 261 | DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); | 226 | DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); |
| 262 | goto dsaerr; | 227 | goto dsaerr; |
| 263 | } | 228 | } |
| 264 | 229 | ||
| 265 | if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) { | 230 | if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) { |
| 266 | DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR); | 231 | DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR); |
| 267 | goto dsaerr; | 232 | goto dsaerr; |
| 268 | } | 233 | } |
| 269 | 234 | ||
| 270 | EVP_PKEY_assign_DSA(pkey, dsa); | 235 | if (!EVP_PKEY_assign_DSA(pkey, dsa)) |
| 271 | BN_CTX_free(ctx); | 236 | goto decerr; |
| 272 | if (ndsa) | ||
| 273 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
| 274 | else | ||
| 275 | ASN1_INTEGER_free(privkey); | ||
| 276 | 237 | ||
| 277 | return 1; | 238 | ret = 1; |
| 239 | goto done; | ||
| 278 | 240 | ||
| 279 | decerr: | 241 | decerr: |
| 280 | DSAerr(DSA_F_DSA_PRIV_DECODE, EVP_R_DECODE_ERROR); | 242 | DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_DECODE_ERROR); |
| 281 | dsaerr: | 243 | dsaerr: |
| 282 | BN_CTX_free(ctx); | ||
| 283 | if (ndsa) | ||
| 284 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
| 285 | else | ||
| 286 | ASN1_INTEGER_free(privkey); | ||
| 287 | DSA_free(dsa); | 244 | DSA_free(dsa); |
| 288 | return 0; | 245 | done: |
| 246 | BN_CTX_free(ctx); | ||
| 247 | ASN1_INTEGER_free(privkey); | ||
| 248 | return ret; | ||
| 289 | } | 249 | } |
| 290 | 250 | ||
| 291 | static int | 251 | static int |
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_ameth.c b/src/lib/libssl/src/crypto/dsa/dsa_ameth.c index 9bef6e5a13..a6e21a688e 100644 --- a/src/lib/libssl/src/crypto/dsa/dsa_ameth.c +++ b/src/lib/libssl/src/crypto/dsa/dsa_ameth.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dsa_ameth.c,v 1.18 2015/09/10 18:12:55 miod Exp $ */ | 1 | /* $OpenBSD: dsa_ameth.c,v 1.19 2016/03/01 07:04:41 doug 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 | */ |
| @@ -181,7 +181,6 @@ err: | |||
| 181 | /* In PKCS#8 DSA: you just get a private key integer and parameters in the | 181 | /* In PKCS#8 DSA: you just get a private key integer and parameters in the |
| 182 | * AlgorithmIdentifier the pubkey must be recalculated. | 182 | * AlgorithmIdentifier the pubkey must be recalculated. |
| 183 | */ | 183 | */ |
| 184 | |||
| 185 | static int | 184 | static int |
| 186 | dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) | 185 | dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) |
| 187 | { | 186 | { |
| @@ -193,56 +192,22 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) | |||
| 193 | X509_ALGOR *palg; | 192 | X509_ALGOR *palg; |
| 194 | ASN1_INTEGER *privkey = NULL; | 193 | ASN1_INTEGER *privkey = NULL; |
| 195 | BN_CTX *ctx = NULL; | 194 | BN_CTX *ctx = NULL; |
| 196 | STACK_OF(ASN1_TYPE) *ndsa = NULL; | ||
| 197 | DSA *dsa = NULL; | 195 | DSA *dsa = NULL; |
| 198 | 196 | ||
| 197 | int ret = 0; | ||
| 198 | |||
| 199 | if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8)) | 199 | if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8)) |
| 200 | return 0; | 200 | return 0; |
| 201 | X509_ALGOR_get0(NULL, &ptype, &pval, palg); | 201 | X509_ALGOR_get0(NULL, &ptype, &pval, palg); |
| 202 | if (ptype != V_ASN1_SEQUENCE) | ||
| 203 | goto decerr; | ||
| 202 | 204 | ||
| 203 | /* Check for broken DSA PKCS#8, UGH! */ | 205 | if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL) |
| 204 | if (*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) { | 206 | goto decerr; |
| 205 | ASN1_TYPE *t1, *t2; | 207 | if (privkey->type == V_ASN1_NEG_INTEGER) |
| 206 | if (!(ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen))) | 208 | goto decerr; |
| 207 | goto decerr; | ||
| 208 | if (sk_ASN1_TYPE_num(ndsa) != 2) | ||
| 209 | goto decerr; | ||
| 210 | /* | ||
| 211 | * Handle Two broken types: | ||
| 212 | * SEQUENCE {parameters, priv_key} | ||
| 213 | * SEQUENCE {pub_key, priv_key} | ||
| 214 | */ | ||
| 215 | |||
| 216 | t1 = sk_ASN1_TYPE_value(ndsa, 0); | ||
| 217 | t2 = sk_ASN1_TYPE_value(ndsa, 1); | ||
| 218 | if (t1->type == V_ASN1_SEQUENCE) { | ||
| 219 | p8->broken = PKCS8_EMBEDDED_PARAM; | ||
| 220 | pval = t1->value.ptr; | ||
| 221 | } else if (ptype == V_ASN1_SEQUENCE) | ||
| 222 | p8->broken = PKCS8_NS_DB; | ||
| 223 | else | ||
| 224 | goto decerr; | ||
| 225 | |||
| 226 | if (t2->type != V_ASN1_INTEGER) | ||
| 227 | goto decerr; | ||
| 228 | |||
| 229 | privkey = t2->value.integer; | ||
| 230 | } else { | ||
| 231 | const unsigned char *q = p; | ||
| 232 | |||
| 233 | if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen))) | ||
| 234 | goto decerr; | ||
| 235 | if (privkey->type == V_ASN1_NEG_INTEGER) { | ||
| 236 | p8->broken = PKCS8_NEG_PRIVKEY; | ||
| 237 | ASN1_INTEGER_free(privkey); | ||
| 238 | if (!(privkey = d2i_ASN1_UINTEGER(NULL, &q, pklen))) | ||
| 239 | goto decerr; | ||
| 240 | } | ||
| 241 | if (ptype != V_ASN1_SEQUENCE) | ||
| 242 | goto decerr; | ||
| 243 | } | ||
| 244 | 209 | ||
| 245 | pstr = pval; | 210 | pstr = pval; |
| 246 | pm = pstr->data; | 211 | pm = pstr->data; |
| 247 | pmlen = pstr->length; | 212 | pmlen = pstr->length; |
| 248 | if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) | 213 | if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) |
| @@ -261,31 +226,26 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) | |||
| 261 | DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); | 226 | DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); |
| 262 | goto dsaerr; | 227 | goto dsaerr; |
| 263 | } | 228 | } |
| 264 | 229 | ||
| 265 | if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) { | 230 | if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) { |
| 266 | DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR); | 231 | DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR); |
| 267 | goto dsaerr; | 232 | goto dsaerr; |
| 268 | } | 233 | } |
| 269 | 234 | ||
| 270 | EVP_PKEY_assign_DSA(pkey, dsa); | 235 | if (!EVP_PKEY_assign_DSA(pkey, dsa)) |
| 271 | BN_CTX_free(ctx); | 236 | goto decerr; |
| 272 | if (ndsa) | ||
| 273 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
| 274 | else | ||
| 275 | ASN1_INTEGER_free(privkey); | ||
| 276 | 237 | ||
| 277 | return 1; | 238 | ret = 1; |
| 239 | goto done; | ||
| 278 | 240 | ||
| 279 | decerr: | 241 | decerr: |
| 280 | DSAerr(DSA_F_DSA_PRIV_DECODE, EVP_R_DECODE_ERROR); | 242 | DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_DECODE_ERROR); |
| 281 | dsaerr: | 243 | dsaerr: |
| 282 | BN_CTX_free(ctx); | ||
| 283 | if (ndsa) | ||
| 284 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
| 285 | else | ||
| 286 | ASN1_INTEGER_free(privkey); | ||
| 287 | DSA_free(dsa); | 244 | DSA_free(dsa); |
| 288 | return 0; | 245 | done: |
| 246 | BN_CTX_free(ctx); | ||
| 247 | ASN1_INTEGER_free(privkey); | ||
| 248 | return ret; | ||
| 289 | } | 249 | } |
| 290 | 250 | ||
| 291 | static int | 251 | static int |
