summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa/dsa_ossl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_ossl.c')
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c56
1 files changed, 1 insertions, 55 deletions
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
69int __BN_rand_range(BIGNUM *r, BIGNUM *range);
70
71static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); 69static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
72static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); 70static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
73static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, 71static 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 */
350int __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 }