diff options
author | tb <> | 2018-11-06 07:02:33 +0000 |
---|---|---|
committer | tb <> | 2018-11-06 07:02:33 +0000 |
commit | 63569101089cbba78ffa6d2b7ab83e719262f5f0 (patch) | |
tree | 1f596901d57af99b215ca32a39768fc112724428 | |
parent | 8920ada6f077f74fa71612e7cab28a0a06089296 (diff) | |
download | openbsd-63569101089cbba78ffa6d2b7ab83e719262f5f0.tar.gz openbsd-63569101089cbba78ffa6d2b7ab83e719262f5f0.tar.bz2 openbsd-63569101089cbba78ffa6d2b7ab83e719262f5f0.zip |
unrevert the use of bn_rand_interval().
ok beck jsing
-rw-r--r-- | src/lib/libcrypto/dh/dh_key.c | 15 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_key.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_ossl.c | 17 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_key.c | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ecp_smpl.c | 8 |
6 files changed, 26 insertions, 35 deletions
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c index 3da2413666..790b706134 100644 --- a/src/lib/libcrypto/dh/dh_key.c +++ b/src/lib/libcrypto/dh/dh_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dh_key.c,v 1.33 2018/11/06 02:14:39 tb Exp $ */ | 1 | /* $OpenBSD: dh_key.c,v 1.34 2018/11/06 07:02:33 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -106,7 +106,7 @@ generate_key(DH *dh) | |||
106 | unsigned l; | 106 | unsigned l; |
107 | BN_CTX *ctx; | 107 | BN_CTX *ctx; |
108 | BN_MONT_CTX *mont = NULL; | 108 | BN_MONT_CTX *mont = NULL; |
109 | BIGNUM *pub_key = dh->pub_key, *priv_key = dh->priv_key; | 109 | BIGNUM *pub_key = dh->pub_key, *priv_key = dh->priv_key, *two = NULL; |
110 | 110 | ||
111 | if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { | 111 | if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { |
112 | DHerror(DH_R_MODULUS_TOO_LARGE); | 112 | DHerror(DH_R_MODULUS_TOO_LARGE); |
@@ -137,10 +137,12 @@ generate_key(DH *dh) | |||
137 | 137 | ||
138 | if (generate_new_key) { | 138 | if (generate_new_key) { |
139 | if (dh->q) { | 139 | if (dh->q) { |
140 | do { | 140 | if ((two = BN_new()) == NULL) |
141 | if (!BN_rand_range(priv_key, dh->q)) | 141 | goto err; |
142 | goto err; | 142 | if (!BN_add(two, BN_value_one(), BN_value_one())) |
143 | } while (BN_is_zero(priv_key) || BN_is_one(priv_key)); | 143 | goto err; |
144 | if (!bn_rand_interval(priv_key, two, dh->q)) | ||
145 | goto err; | ||
144 | } else { | 146 | } else { |
145 | /* secret exponent length */ | 147 | /* secret exponent length */ |
146 | l = dh->length ? dh->length : BN_num_bits(dh->p) - 1; | 148 | l = dh->length ? dh->length : BN_num_bits(dh->p) - 1; |
@@ -165,6 +167,7 @@ generate_key(DH *dh) | |||
165 | if (dh->priv_key == NULL) | 167 | if (dh->priv_key == NULL) |
166 | BN_free(priv_key); | 168 | BN_free(priv_key); |
167 | BN_CTX_free(ctx); | 169 | BN_CTX_free(ctx); |
170 | BN_free(two); | ||
168 | return ok; | 171 | return ok; |
169 | } | 172 | } |
170 | 173 | ||
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c index 4039fbf407..54c6550fef 100644 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ b/src/lib/libcrypto/dsa/dsa_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dsa_key.c,v 1.27 2018/11/06 02:14:39 tb Exp $ */ | 1 | /* $OpenBSD: dsa_key.c,v 1.28 2018/11/06 07:02:33 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -92,10 +92,8 @@ dsa_builtin_keygen(DSA *dsa) | |||
92 | goto err; | 92 | goto err; |
93 | } | 93 | } |
94 | 94 | ||
95 | do { | 95 | if (!bn_rand_interval(priv_key, BN_value_one(), dsa->q)) |
96 | if (!BN_rand_range(priv_key, dsa->q)) | 96 | goto err; |
97 | goto err; | ||
98 | } while (BN_is_zero(priv_key)); | ||
99 | 97 | ||
100 | if (pub_key == NULL) { | 98 | if (pub_key == NULL) { |
101 | if ((pub_key = BN_new()) == NULL) | 99 | if ((pub_key = BN_new()) == NULL) |
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c index 6eb391ddeb..fd56e8feee 100644 --- a/src/lib/libcrypto/dsa/dsa_ossl.c +++ b/src/lib/libcrypto/dsa/dsa_ossl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dsa_ossl.c,v 1.39 2018/11/06 02:14:39 tb Exp $ */ | 1 | /* $OpenBSD: dsa_ossl.c,v 1.40 2018/11/06 07:02:33 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -150,13 +150,9 @@ dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | |||
150 | * | 150 | * |
151 | * s = inv(k)inv(b)(bm + bxr) mod q | 151 | * s = inv(k)inv(b)(bm + bxr) mod q |
152 | * | 152 | * |
153 | * Where b is a random value in the range [1, q-1]. | 153 | * Where b is a random value in the range [1, q). |
154 | */ | 154 | */ |
155 | if (!BN_sub(&bm, dsa->q, BN_value_one())) | 155 | if (!bn_rand_interval(&b, BN_value_one(), dsa->q)) |
156 | goto err; | ||
157 | if (!BN_rand_range(&b, &bm)) | ||
158 | goto err; | ||
159 | if (!BN_add(&b, &b, BN_value_one())) | ||
160 | goto err; | 156 | goto err; |
161 | if (BN_mod_inverse_ct(&binv, &b, dsa->q, ctx) == NULL) | 157 | if (BN_mod_inverse_ct(&binv, &b, dsa->q, ctx) == NULL) |
162 | goto err; | 158 | goto err; |
@@ -242,11 +238,8 @@ dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | |||
242 | !BN_set_bit(&m, q_bits)) | 238 | !BN_set_bit(&m, q_bits)) |
243 | goto err; | 239 | goto err; |
244 | 240 | ||
245 | /* Get random k */ | 241 | if (!bn_rand_interval(&k, BN_value_one(), dsa->q)) |
246 | do { | 242 | goto err; |
247 | if (!BN_rand_range(&k, dsa->q)) | ||
248 | goto err; | ||
249 | } while (BN_is_zero(&k)); | ||
250 | 243 | ||
251 | BN_set_flags(&k, BN_FLG_CONSTTIME); | 244 | BN_set_flags(&k, BN_FLG_CONSTTIME); |
252 | 245 | ||
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c index ca49c7676e..6ab4d3c9a4 100644 --- a/src/lib/libcrypto/ec/ec_key.c +++ b/src/lib/libcrypto/ec/ec_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_key.c,v 1.20 2018/11/06 02:14:39 tb Exp $ */ | 1 | /* $OpenBSD: ec_key.c,v 1.21 2018/11/06 07:02:33 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -65,6 +65,7 @@ | |||
65 | 65 | ||
66 | #include <openssl/opensslconf.h> | 66 | #include <openssl/opensslconf.h> |
67 | 67 | ||
68 | #include "bn_lcl.h" | ||
68 | #include "ec_lcl.h" | 69 | #include "ec_lcl.h" |
69 | #include <openssl/err.h> | 70 | #include <openssl/err.h> |
70 | 71 | ||
@@ -231,10 +232,8 @@ EC_KEY_generate_key(EC_KEY *eckey) | |||
231 | if (!EC_GROUP_get_order(eckey->group, order, ctx)) | 232 | if (!EC_GROUP_get_order(eckey->group, order, ctx)) |
232 | goto err; | 233 | goto err; |
233 | 234 | ||
234 | do | 235 | if (!bn_rand_interval(priv_key, BN_value_one(), order)) |
235 | if (!BN_rand_range(priv_key, order)) | 236 | goto err; |
236 | goto err; | ||
237 | while (BN_is_zero(priv_key)); | ||
238 | 237 | ||
239 | if (pub_key == NULL) { | 238 | if (pub_key == NULL) { |
240 | if ((pub_key = EC_POINT_new(eckey->group)) == NULL) | 239 | if ((pub_key = EC_POINT_new(eckey->group)) == NULL) |
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index bf2f652fc7..e5d9620a00 100644 --- a/src/lib/libcrypto/ec/ec_lib.c +++ b/src/lib/libcrypto/ec/ec_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_lib.c,v 1.30 2018/11/05 20:18:21 tb Exp $ */ | 1 | /* $OpenBSD: ec_lib.c,v 1.31 2018/11/06 07:02:33 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -547,7 +547,7 @@ ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx) | |||
547 | { | 547 | { |
548 | if (group->meth->blind_coordinates == NULL) | 548 | if (group->meth->blind_coordinates == NULL) |
549 | return 1; | 549 | return 1; |
550 | 550 | ||
551 | return group->meth->blind_coordinates(group, p, ctx); | 551 | return group->meth->blind_coordinates(group, p, ctx); |
552 | } | 552 | } |
553 | 553 | ||
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c index e379a74fb1..c64c41130a 100644 --- a/src/lib/libcrypto/ec/ecp_smpl.c +++ b/src/lib/libcrypto/ec/ecp_smpl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecp_smpl.c,v 1.27 2018/11/06 06:59:25 tb Exp $ */ | 1 | /* $OpenBSD: ecp_smpl.c,v 1.28 2018/11/06 07:02:33 tb Exp $ */ |
2 | /* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> | 2 | /* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> |
3 | * for the OpenSSL project. | 3 | * for the OpenSSL project. |
4 | * Includes code written by Bodo Moeller for the OpenSSL project. | 4 | * Includes code written by Bodo Moeller for the OpenSSL project. |
@@ -1434,10 +1434,8 @@ ec_GFp_simple_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx) | |||
1434 | goto err; | 1434 | goto err; |
1435 | 1435 | ||
1436 | /* Generate lambda in [1, group->field - 1] */ | 1436 | /* Generate lambda in [1, group->field - 1] */ |
1437 | do { | 1437 | if (!bn_rand_interval(lambda, BN_value_one(), &group->field)) |
1438 | if (!BN_rand_range(lambda, &group->field)) | 1438 | goto err; |
1439 | goto err; | ||
1440 | } while (BN_is_zero(lambda)); | ||
1441 | 1439 | ||
1442 | if (group->meth->field_encode != NULL && | 1440 | if (group->meth->field_encode != NULL && |
1443 | !group->meth->field_encode(group, lambda, lambda, ctx)) | 1441 | !group->meth->field_encode(group, lambda, lambda, ctx)) |