From fc2e05c2d5c078d1fdf0ee56fc118ea471000a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bodo=20M=C3=B6ller?= Date: Thu, 30 Nov 2000 22:34:57 +0000 Subject: [PATCH] Fix BN_rshift, which caused lots of trouble. --- CHANGES | 3 +++ crypto/bn/bn_mul.c | 2 +- crypto/bn/bn_shift.c | 5 +++++ crypto/bn/bntest.c | 20 ++------------------ 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index eb3e87ba72..71582c3e06 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,9 @@ Changes between 0.9.6 and 0.9.7 [xx XXX 2000] + *) BN_rshift bugfix for n == 0. + [Bodo Moeller] + *) Reformat the FAQ so the different questions and answers can be divided i sections depending on the subject. [Richard Levitte] diff --git a/crypto/bn/bn_mul.c b/crypto/bn/bn_mul.c index b6608c47de..ff351af10f 100644 --- a/crypto/bn/bn_mul.c +++ b/crypto/bn/bn_mul.c @@ -928,7 +928,7 @@ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2, } #endif /* BN_RECURSION */ -int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) +int BN_mul(BIGNUM *r, /* almost const */ const BIGNUM *a, /* almost const */ const BIGNUM *b, BN_CTX *ctx) { int top,al,bl; BIGNUM *rr; diff --git a/crypto/bn/bn_shift.c b/crypto/bn/bn_shift.c index 37c6988da3..70f785ea18 100644 --- a/crypto/bn/bn_shift.c +++ b/crypto/bn/bn_shift.c @@ -172,6 +172,11 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n) r->neg=a->neg; if (bn_wexpand(r,a->top-nw+1) == NULL) return(0); } + else + { + if (n == 0) + return 1; /* or the copying loop will go berserk */ + } f= &(a->d[nw]); t=r->d; diff --git a/crypto/bn/bntest.c b/crypto/bn/bntest.c index 3c0c95feb6..2df0d29b1a 100644 --- a/crypto/bn/bntest.c +++ b/crypto/bn/bntest.c @@ -165,7 +165,6 @@ int main(int argc, char *argv[]) if (!results) BIO_puts(out,"obase=16\nibase=16\n"); -#if 0 message(out,"BN_add"); if (!test_add(out)) goto err; BIO_flush(out); @@ -230,7 +229,6 @@ int main(int argc, char *argv[]) message(out,"BN_exp"); if (!test_exp(out,ctx)) goto err; BIO_flush(out); -#endif message(out,"BN_kronecker"); if (!test_kron(out,ctx)) goto err; @@ -946,34 +944,20 @@ int test_kron(BIO *bp, BN_CTX *ctx) * don't want to test whether b is prime but whether BN_kronecker * works.) */ -#if 0 if (!BN_generate_prime(b, 512, 0, NULL, NULL, genprime_cb, NULL)) goto err; -#else - if (!BN_set_word(b,65537)) goto err; -#endif putc('\n', stderr); for (i = 0; i < num0; i++) { -#if 0 if (!BN_rand(a, 512, 0, 0)) goto err; a->neg = rand_neg(); -#else - if (!BN_bin2bn("\x01\xff\xff\xff\xff", 5, a)) goto err; -#endif /* t := (b-1)/2 (note that b is odd) */ if (!BN_copy(t, b)) goto err; if (!BN_sub_word(t, 1)) goto err; if (!BN_rshift1(t, t)) goto err; /* r := a^t mod b */ -#if 0 if (!BN_mod_exp(r, a, t, b, ctx)) goto err; -#elif 0 - if (!BN_mod_exp_recp(r, a, t, b, ctx)) goto err; -#else - if (!BN_mod_exp_simple(r, a, t, b, ctx)) goto err; -#endif if (BN_is_word(r, 1)) legendre = 1; @@ -989,7 +973,7 @@ int test_kron(BIO *bp, BN_CTX *ctx) } legendre = -1; } - + kronecker = BN_kronecker(a, b, ctx); if (kronecker < -1) goto err; @@ -997,7 +981,7 @@ int test_kron(BIO *bp, BN_CTX *ctx) { fprintf(stderr, "legendre != kronecker; a = "); BN_print_fp(stderr, a); - fprintf(stderr, ", a = "); + fprintf(stderr, ", b = "); BN_print_fp(stderr, b); fprintf(stderr, "\n"); goto err; -- GitLab