diff options
author | markus <> | 2002-09-05 22:12:12 +0000 |
---|---|---|
committer | markus <> | 2002-09-05 22:12:12 +0000 |
commit | e08fb7998d733407336e83a299f140b0c1d2fcd3 (patch) | |
tree | 64de5de3b0be4adfc5050b6f785b6975c564b730 /src/lib/libcrypto/dsa | |
parent | b200d1ec45aafc7c92b197a4b605e34834d74f1d (diff) | |
download | openbsd-e08fb7998d733407336e83a299f140b0c1d2fcd3.tar.gz openbsd-e08fb7998d733407336e83a299f140b0c1d2fcd3.tar.bz2 openbsd-e08fb7998d733407336e83a299f140b0c1d2fcd3.zip |
merge with 0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/dsa')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_key.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_ossl.c | 56 |
2 files changed, 2 insertions, 58 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c index bf718c1c6d..ef87c3e637 100644 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ b/src/lib/libcrypto/dsa/dsa_key.c | |||
@@ -64,8 +64,6 @@ | |||
64 | #include <openssl/dsa.h> | 64 | #include <openssl/dsa.h> |
65 | #include <openssl/rand.h> | 65 | #include <openssl/rand.h> |
66 | 66 | ||
67 | extern int __BN_rand_range(BIGNUM *r, BIGNUM *range); | ||
68 | |||
69 | int DSA_generate_key(DSA *dsa) | 67 | int DSA_generate_key(DSA *dsa) |
70 | { | 68 | { |
71 | int ok=0; | 69 | int ok=0; |
@@ -82,7 +80,7 @@ int DSA_generate_key(DSA *dsa) | |||
82 | priv_key=dsa->priv_key; | 80 | priv_key=dsa->priv_key; |
83 | 81 | ||
84 | do | 82 | do |
85 | if (!__BN_rand_range(priv_key,dsa->q)) goto err; | 83 | if (!BN_rand_range(priv_key,dsa->q)) goto err; |
86 | while (BN_is_zero(priv_key)); | 84 | while (BN_is_zero(priv_key)); |
87 | 85 | ||
88 | if (dsa->pub_key == NULL) | 86 | if (dsa->pub_key == NULL) |
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c index 07addc94d9..37dd5fc994 100644 --- a/src/lib/libcrypto/dsa/dsa_ossl.c +++ b/src/lib/libcrypto/dsa/dsa_ossl.c | |||
@@ -66,8 +66,6 @@ | |||
66 | #include <openssl/asn1.h> | 66 | #include <openssl/asn1.h> |
67 | #include <openssl/engine.h> | 67 | #include <openssl/engine.h> |
68 | 68 | ||
69 | int __BN_rand_range(BIGNUM *r, BIGNUM *range); | ||
70 | |||
71 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | 69 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); |
72 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); | 70 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); |
73 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | 71 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, |
@@ -193,7 +191,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | |||
193 | 191 | ||
194 | /* Get random k */ | 192 | /* Get random k */ |
195 | do | 193 | do |
196 | if (!__BN_rand_range(&k, dsa->q)) goto err; | 194 | if (!BN_rand_range(&k, dsa->q)) goto err; |
197 | while (BN_is_zero(&k)); | 195 | while (BN_is_zero(&k)); |
198 | 196 | ||
199 | if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) | 197 | if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) |
@@ -344,55 +342,3 @@ static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | |||
344 | { | 342 | { |
345 | return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx); | 343 | return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx); |
346 | } | 344 | } |
347 | |||
348 | |||
349 | /* random number r: 0 <= r < range */ | ||
350 | int __BN_rand_range(BIGNUM *r, BIGNUM *range) | ||
351 | { | ||
352 | int n; | ||
353 | |||
354 | if (range->neg || BN_is_zero(range)) | ||
355 | { | ||
356 | /* BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE); */ | ||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | n = BN_num_bits(range); /* n > 0 */ | ||
361 | |||
362 | if (n == 1) | ||
363 | { | ||
364 | if (!BN_zero(r)) return 0; | ||
365 | } | ||
366 | else if (BN_is_bit_set(range, n - 2)) | ||
367 | { | ||
368 | do | ||
369 | { | ||
370 | /* range = 11..._2, so each iteration succeeds with probability >= .75 */ | ||
371 | if (!BN_rand(r, n, -1, 0)) return 0; | ||
372 | } | ||
373 | while (BN_cmp(r, range) >= 0); | ||
374 | } | ||
375 | else | ||
376 | { | ||
377 | /* range = 10..._2, | ||
378 | * so 3*range (= 11..._2) is exactly one bit longer than range */ | ||
379 | do | ||
380 | { | ||
381 | if (!BN_rand(r, n + 1, -1, 0)) return 0; | ||
382 | /* If r < 3*range, use r := r MOD range | ||
383 | * (which is either r, r - range, or r - 2*range). | ||
384 | * Otherwise, iterate once more. | ||
385 | * Since 3*range = 11..._2, each iteration succeeds with | ||
386 | * probability >= .75. */ | ||
387 | if (BN_cmp(r ,range) >= 0) | ||
388 | { | ||
389 | if (!BN_sub(r, r, range)) return 0; | ||
390 | if (BN_cmp(r, range) >= 0) | ||
391 | if (!BN_sub(r, r, range)) return 0; | ||
392 | } | ||
393 | } | ||
394 | while (BN_cmp(r, range) >= 0); | ||
395 | } | ||
396 | |||
397 | return 1; | ||
398 | } | ||