summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2023-05-09 05:38:12 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2023-05-09 05:38:12 +0000
commit8e570acf08180c565e84a3b76068671b6b5f3196 (patch)
tree053649920556dc7dafa5897030102ac5effdb62c /lib
parentab6a0a8fc329e93aa45aa7c87256a4afb73a749b (diff)
bn_exp: also special case -1 modulus
Anything taken to the power of 0 is 1, and then reduced mod 1 or mod -1 it will be 0. If "anything" includes 0 or not is a matter of convention, but it should not depend on the sign of the modulus... Reported by Guido Vranken ok jsing (who had the same diff)
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/bn/bn_exp.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/libcrypto/bn/bn_exp.c b/lib/libcrypto/bn/bn_exp.c
index ff9933578ca..9e5d1fd26db 100644
--- a/lib/libcrypto/bn/bn_exp.c
+++ b/lib/libcrypto/bn/bn_exp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn_exp.c,v 1.45 2023/03/30 14:21:10 tb Exp $ */
+/* $OpenBSD: bn_exp.c,v 1.46 2023/05/09 05:38:11 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -194,7 +194,7 @@ BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
bits = BN_num_bits(p);
if (bits == 0) {
/* x**0 mod 1 is still zero. */
- if (BN_is_one(m)) {
+ if (BN_abs_is_word(m, 1)) {
ret = 1;
BN_zero(r);
} else
@@ -402,7 +402,7 @@ BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
bits = BN_num_bits(p);
if (bits == 0) {
/* x**0 mod 1 is still zero. */
- if (BN_is_one(m)) {
+ if (BN_abs_is_word(m, 1)) {
ret = 1;
BN_zero(rr);
} else
@@ -658,7 +658,7 @@ BN_mod_exp_mont_internal(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, const BIG
bits = BN_num_bits(p);
if (bits == 0) {
/* x**0 mod 1 is still zero. */
- if (BN_is_one(m)) {
+ if (BN_abs_is_word(m, 1)) {
ret = 1;
BN_zero(rr);
} else
@@ -843,7 +843,7 @@ BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, const BIGNUM *m,
bits = BN_num_bits(p);
if (bits == 0) {
/* x**0 mod 1 is still zero. */
- if (BN_is_one(m)) {
+ if (BN_abs_is_word(m, 1)) {
ret = 1;
BN_zero(rr);
} else
@@ -968,7 +968,7 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
bits = BN_num_bits(p);
if (bits == 0) {
/* x**0 mod 1 is still zero. */
- if (BN_is_one(m)) {
+ if (BN_abs_is_word(m, 1)) {
ret = 1;
BN_zero(r);
} else