diff options
author | Bodo Möller <bodo@openssl.org> | 2000-11-30 00:18:19 +0000 |
---|---|---|
committer | Bodo Möller <bodo@openssl.org> | 2000-11-30 00:18:19 +0000 |
commit | cd2eebfd6497ac1ca4d450960ba843f14643a9b2 (patch) | |
tree | 04a45f2588ea5b3a984aab36c32fa75c6471cbc1 /crypto/bn/bn_exp.c | |
parent | 06676624fc148d511543586502126b3f2bf8b5dd (diff) |
BN_sqrt
Diffstat (limited to 'crypto/bn/bn_exp.c')
-rw-r--r-- | crypto/bn/bn_exp.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c index 35ab56efc0..51c8282593 100644 --- a/crypto/bn/bn_exp.c +++ b/crypto/bn/bn_exp.c @@ -205,6 +205,8 @@ int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, if (a->top == 1 && !a->neg) { BN_ULONG A = a->d[0]; + if (m->top == 1) + A %= m->d[0]; /* make sure that A is reduced */ ret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL); } else @@ -235,8 +237,13 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, if (bits == 0) { - BN_one(r); - return(1); + ret = BN_one(r); + return ret; + } + if (BN_is_zero(a)) + { + ret = BN_zero(r); + return ret; } BN_CTX_start(ctx); @@ -355,8 +362,13 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, bits=BN_num_bits(p); if (bits == 0) { - BN_one(rr); - return(1); + ret = BN_one(rr); + return ret; + } + if (BN_is_zero(a)) + { + ret = BN_zero(rr); + return ret; } BN_CTX_start(ctx); d = BN_CTX_get(ctx); @@ -500,9 +512,15 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, bits = BN_num_bits(p); if (bits == 0) { - BN_one(rr); - return(1); + ret = BN_one(rr); + return ret; } + if (a == 0) + { + ret = BN_zero(rr); + return ret; + } + BN_CTX_start(ctx); d = BN_CTX_get(ctx); r = BN_CTX_get(ctx); @@ -611,8 +629,13 @@ int BN_mod_exp_simple(BIGNUM *r, if (bits == 0) { - BN_one(r); - return(1); + ret = BN_one(r); + return ret; + } + if (BN_is_zero(a)) + { + ret = BN_one(r); + return ret; } BN_CTX_start(ctx); |