diff options
Diffstat (limited to 'src/lib/libcrypto/dh/dh_key.c')
| -rw-r--r-- | src/lib/libcrypto/dh/dh_key.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c index 74de589204..e7db440342 100644 --- a/src/lib/libcrypto/dh/dh_key.c +++ b/src/lib/libcrypto/dh/dh_key.c | |||
| @@ -62,8 +62,6 @@ | |||
| 62 | #include <openssl/rand.h> | 62 | #include <openssl/rand.h> |
| 63 | #include <openssl/dh.h> | 63 | #include <openssl/dh.h> |
| 64 | 64 | ||
| 65 | #ifndef OPENSSL_FIPS | ||
| 66 | |||
| 67 | static int generate_key(DH *dh); | 65 | static int generate_key(DH *dh); |
| 68 | static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh); | 66 | static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh); |
| 69 | static int dh_bn_mod_exp(const DH *dh, BIGNUM *r, | 67 | static int dh_bn_mod_exp(const DH *dh, BIGNUM *r, |
| @@ -91,6 +89,7 @@ dh_bn_mod_exp, | |||
| 91 | dh_init, | 89 | dh_init, |
| 92 | dh_finish, | 90 | dh_finish, |
| 93 | 0, | 91 | 0, |
| 92 | NULL, | ||
| 94 | NULL | 93 | NULL |
| 95 | }; | 94 | }; |
| 96 | 95 | ||
| @@ -131,8 +130,7 @@ static int generate_key(DH *dh) | |||
| 131 | 130 | ||
| 132 | if (dh->flags & DH_FLAG_CACHE_MONT_P) | 131 | if (dh->flags & DH_FLAG_CACHE_MONT_P) |
| 133 | { | 132 | { |
| 134 | mont = BN_MONT_CTX_set_locked( | 133 | mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, |
| 135 | (BN_MONT_CTX **)&dh->method_mont_p, | ||
| 136 | CRYPTO_LOCK_DH, dh->p, ctx); | 134 | CRYPTO_LOCK_DH, dh->p, ctx); |
| 137 | if (!mont) | 135 | if (!mont) |
| 138 | goto err; | 136 | goto err; |
| @@ -152,7 +150,7 @@ static int generate_key(DH *dh) | |||
| 152 | { | 150 | { |
| 153 | BN_init(&local_prk); | 151 | BN_init(&local_prk); |
| 154 | prk = &local_prk; | 152 | prk = &local_prk; |
| 155 | BN_with_flags(prk, priv_key, BN_FLG_EXP_CONSTTIME); | 153 | BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); |
| 156 | } | 154 | } |
| 157 | else | 155 | else |
| 158 | prk = priv_key; | 156 | prk = priv_key; |
| @@ -165,7 +163,7 @@ static int generate_key(DH *dh) | |||
| 165 | ok=1; | 163 | ok=1; |
| 166 | err: | 164 | err: |
| 167 | if (ok != 1) | 165 | if (ok != 1) |
| 168 | DHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB); | 166 | DHerr(DH_F_GENERATE_KEY,ERR_R_BN_LIB); |
| 169 | 167 | ||
| 170 | if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key); | 168 | if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key); |
| 171 | if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key); | 169 | if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key); |
| @@ -175,16 +173,16 @@ err: | |||
| 175 | 173 | ||
| 176 | static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | 174 | static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) |
| 177 | { | 175 | { |
| 178 | BN_CTX *ctx; | 176 | BN_CTX *ctx=NULL; |
| 179 | BN_MONT_CTX *mont=NULL; | 177 | BN_MONT_CTX *mont=NULL; |
| 180 | BIGNUM *tmp; | 178 | BIGNUM *tmp; |
| 181 | int ret= -1; | 179 | int ret= -1; |
| 182 | int check_result; | 180 | int check_result; |
| 183 | 181 | ||
| 184 | if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) | 182 | if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) |
| 185 | { | 183 | { |
| 186 | DHerr(DH_F_DH_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE); | 184 | DHerr(DH_F_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE); |
| 187 | return -1; | 185 | goto err; |
| 188 | } | 186 | } |
| 189 | 187 | ||
| 190 | ctx = BN_CTX_new(); | 188 | ctx = BN_CTX_new(); |
| @@ -194,31 +192,32 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | |||
| 194 | 192 | ||
| 195 | if (dh->priv_key == NULL) | 193 | if (dh->priv_key == NULL) |
| 196 | { | 194 | { |
| 197 | DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE); | 195 | DHerr(DH_F_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE); |
| 198 | goto err; | 196 | goto err; |
| 199 | } | 197 | } |
| 200 | 198 | ||
| 201 | if (dh->flags & DH_FLAG_CACHE_MONT_P) | 199 | if (dh->flags & DH_FLAG_CACHE_MONT_P) |
| 202 | { | 200 | { |
| 203 | mont = BN_MONT_CTX_set_locked( | 201 | mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, |
| 204 | (BN_MONT_CTX **)&dh->method_mont_p, | ||
| 205 | CRYPTO_LOCK_DH, dh->p, ctx); | 202 | CRYPTO_LOCK_DH, dh->p, ctx); |
| 206 | if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) | 203 | if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) |
| 207 | { | 204 | { |
| 208 | /* XXX */ | 205 | /* XXX */ |
| 209 | BN_set_flags(dh->priv_key, BN_FLG_EXP_CONSTTIME); | 206 | BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME); |
| 210 | } | 207 | } |
| 211 | if (!mont) | 208 | if (!mont) |
| 212 | goto err; | 209 | goto err; |
| 213 | } | 210 | } |
| 214 | if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) | 211 | |
| 212 | if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) | ||
| 215 | { | 213 | { |
| 216 | DHerr(DH_F_DH_COMPUTE_KEY,DH_R_INVALID_PUBKEY); | 214 | DHerr(DH_F_COMPUTE_KEY,DH_R_INVALID_PUBKEY); |
| 217 | goto err; | 215 | goto err; |
| 218 | } | 216 | } |
| 217 | |||
| 219 | if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont)) | 218 | if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont)) |
| 220 | { | 219 | { |
| 221 | DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB); | 220 | DHerr(DH_F_COMPUTE_KEY,ERR_R_BN_LIB); |
| 222 | goto err; | 221 | goto err; |
| 223 | } | 222 | } |
| 224 | 223 | ||
| @@ -259,8 +258,6 @@ static int dh_init(DH *dh) | |||
| 259 | static int dh_finish(DH *dh) | 258 | static int dh_finish(DH *dh) |
| 260 | { | 259 | { |
| 261 | if(dh->method_mont_p) | 260 | if(dh->method_mont_p) |
| 262 | BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p); | 261 | BN_MONT_CTX_free(dh->method_mont_p); |
| 263 | return(1); | 262 | return(1); |
| 264 | } | 263 | } |
| 265 | |||
| 266 | #endif | ||
