summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-05-09 05:38:11 +0000
committertb <>2023-05-09 05:38:11 +0000
commita12cb743f19d02d79b27833e923b1eda920e4381 (patch)
tree4c67696d92f153d2f2ab95413bb44eca0e41ae56 /src/lib
parentbddde9f4a7b728245a440b7da9afc22565f90e1f (diff)
downloadopenbsd-a12cb743f19d02d79b27833e923b1eda920e4381.tar.gz
openbsd-a12cb743f19d02d79b27833e923b1eda920e4381.tar.bz2
openbsd-a12cb743f19d02d79b27833e923b1eda920e4381.zip
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 'src/lib')
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index ff9933578c..9e5d1fd26d 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_exp.c,v 1.45 2023/03/30 14:21:10 tb Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.46 2023/05/09 05:38:11 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -194,7 +194,7 @@ BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
194 bits = BN_num_bits(p); 194 bits = BN_num_bits(p);
195 if (bits == 0) { 195 if (bits == 0) {
196 /* x**0 mod 1 is still zero. */ 196 /* x**0 mod 1 is still zero. */
197 if (BN_is_one(m)) { 197 if (BN_abs_is_word(m, 1)) {
198 ret = 1; 198 ret = 1;
199 BN_zero(r); 199 BN_zero(r);
200 } else 200 } else
@@ -402,7 +402,7 @@ BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
402 bits = BN_num_bits(p); 402 bits = BN_num_bits(p);
403 if (bits == 0) { 403 if (bits == 0) {
404 /* x**0 mod 1 is still zero. */ 404 /* x**0 mod 1 is still zero. */
405 if (BN_is_one(m)) { 405 if (BN_abs_is_word(m, 1)) {
406 ret = 1; 406 ret = 1;
407 BN_zero(rr); 407 BN_zero(rr);
408 } else 408 } else
@@ -658,7 +658,7 @@ BN_mod_exp_mont_internal(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, const BIG
658 bits = BN_num_bits(p); 658 bits = BN_num_bits(p);
659 if (bits == 0) { 659 if (bits == 0) {
660 /* x**0 mod 1 is still zero. */ 660 /* x**0 mod 1 is still zero. */
661 if (BN_is_one(m)) { 661 if (BN_abs_is_word(m, 1)) {
662 ret = 1; 662 ret = 1;
663 BN_zero(rr); 663 BN_zero(rr);
664 } else 664 } else
@@ -843,7 +843,7 @@ BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, const BIGNUM *m,
843 bits = BN_num_bits(p); 843 bits = BN_num_bits(p);
844 if (bits == 0) { 844 if (bits == 0) {
845 /* x**0 mod 1 is still zero. */ 845 /* x**0 mod 1 is still zero. */
846 if (BN_is_one(m)) { 846 if (BN_abs_is_word(m, 1)) {
847 ret = 1; 847 ret = 1;
848 BN_zero(rr); 848 BN_zero(rr);
849 } else 849 } else
@@ -968,7 +968,7 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
968 bits = BN_num_bits(p); 968 bits = BN_num_bits(p);
969 if (bits == 0) { 969 if (bits == 0) {
970 /* x**0 mod 1 is still zero. */ 970 /* x**0 mod 1 is still zero. */
971 if (BN_is_one(m)) { 971 if (BN_abs_is_word(m, 1)) {
972 ret = 1; 972 ret = 1;
973 BN_zero(r); 973 BN_zero(r);
974 } else 974 } else