diff options
author | Adam Langley <agl@chromium.org> | 2013-04-23 12:13:51 -0400 |
---|---|---|
committer | Emilia Kasper <emilia@openssl.org> | 2014-09-04 16:07:39 +0200 |
commit | 45d129511ff0b43be9a4271133c9ee22658ff07e (patch) | |
tree | d0fed3d841527f5d8f1949346f552c3ceb81a848 /crypto/bn/bn_exp.c | |
parent | 0976adac8fb4e7d336b0edcd24d1bcd3e62abcf3 (diff) |
Ensure that x**0 mod 1 = 0.
(cherry picked from commit 2b0180c37fa6ffc48ee40caa831ca398b828e680)
Reviewed-by: Ben Laurie <ben@openssl.org>
Diffstat (limited to 'crypto/bn/bn_exp.c')
-rw-r--r-- | crypto/bn/bn_exp.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c index d9b6c737fc..2e1e4e7fd8 100644 --- a/crypto/bn/bn_exp.c +++ b/crypto/bn/bn_exp.c @@ -767,7 +767,14 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, bits = BN_num_bits(p); if (bits == 0) { - ret = BN_one(rr); + /* x**0 mod 1 is still zero. */ + if (BN_is_one(m)) + { + ret = 1; + BN_zero(rr); + } + else + ret = BN_one(rr); return ret; } if (a == 0) |