summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2023-03-15 04:30:20 +0000
committerjsing <>2023-03-15 04:30:20 +0000
commit14ed158fa9549e635683f2563b9a55d2819664e7 (patch)
tree5adcfc16e56c46e606243a66fc8f3bfcc59c4085 /src/lib
parent68d4a79dbefd9905bddd67b25a805bbe5ee1c220 (diff)
downloadopenbsd-14ed158fa9549e635683f2563b9a55d2819664e7.tar.gz
openbsd-14ed158fa9549e635683f2563b9a55d2819664e7.tar.bz2
openbsd-14ed158fa9549e635683f2563b9a55d2819664e7.zip
Ensure negative input to BN_mod_exp_mont_consttime() is correctly reduced.
A negative input to BN_mod_exp_mont_consttime() is not correctly reduced, remaining negative (when it should be in the range [0, m)). Fix this by unconditionally calling BN_nnmod() on the input. Fixes ossfuzz #55997. ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index 4011bb4890..9abf574b57 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.37 2023/02/03 05:30:49 jsing Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.38 2023/03/15 04:30:20 jsing 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 *
@@ -459,12 +459,9 @@ BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
459#endif 459#endif
460 460
461 /* prepare a^1 in Montgomery domain */ 461 /* prepare a^1 in Montgomery domain */
462 if (a->neg || BN_ucmp(a, m) >= 0) { 462 if (!BN_nnmod(&am, a, m, ctx))
463 if (!BN_mod_ct(&am, a,m, ctx)) 463 goto err;
464 goto err; 464 if (!BN_to_montgomery(&am, &am, mont, ctx))
465 if (!BN_to_montgomery(&am, &am, mont, ctx))
466 goto err;
467 } else if (!BN_to_montgomery(&am, a,mont, ctx))
468 goto err; 465 goto err;
469 466
470#if defined(OPENSSL_BN_ASM_MONT5) 467#if defined(OPENSSL_BN_ASM_MONT5)