diff options
author | tb <> | 2025-08-03 10:33:46 +0000 |
---|---|---|
committer | tb <> | 2025-08-03 10:33:46 +0000 |
commit | 0347e27fd9cf92b7115735c6b96945b6fb5658b6 (patch) | |
tree | 87ada305e3bec2a2abff7e69b7987a995c7a5ed5 /src | |
parent | e174a4e182177c20c0cde88525f3c84ed7c7d03a (diff) | |
download | openbsd-0347e27fd9cf92b7115735c6b96945b6fb5658b6.tar.gz openbsd-0347e27fd9cf92b7115735c6b96945b6fb5658b6.tar.bz2 openbsd-0347e27fd9cf92b7115735c6b96945b6fb5658b6.zip |
Avoid signed overflow in BN_MONT_CTX_set()
ri is an int, so the check relied on signed overflow (UB). It's not really
reachable, but shrug.
reported by smatch via jsg
ok beck jsing kenjiro
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_mont.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c index 950846fa5b..8280a8db27 100644 --- a/src/lib/libcrypto/bn/bn_mont.c +++ b/src/lib/libcrypto/bn/bn_mont.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_mont.c,v 1.68 2025/05/25 05:12:05 jsing Exp $ */ | 1 | /* $OpenBSD: bn_mont.c,v 1.69 2025/08/03 10:33:46 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 | * |
@@ -116,6 +116,7 @@ | |||
116 | * sections 3.8 and 4.2 in http://security.ece.orst.edu/koc/papers/r01rsasw.pdf | 116 | * sections 3.8 and 4.2 in http://security.ece.orst.edu/koc/papers/r01rsasw.pdf |
117 | */ | 117 | */ |
118 | 118 | ||
119 | #include <limits.h> | ||
119 | #include <stdio.h> | 120 | #include <stdio.h> |
120 | #include <stdint.h> | 121 | #include <stdint.h> |
121 | #include <string.h> | 122 | #include <string.h> |
@@ -214,7 +215,7 @@ BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx) | |||
214 | goto err; | 215 | goto err; |
215 | mont->N.neg = 0; | 216 | mont->N.neg = 0; |
216 | mont->ri = ((BN_num_bits(mod) + BN_BITS2 - 1) / BN_BITS2) * BN_BITS2; | 217 | mont->ri = ((BN_num_bits(mod) + BN_BITS2 - 1) / BN_BITS2) * BN_BITS2; |
217 | if (mont->ri * 2 < mont->ri) | 218 | if (mont->ri > INT_MAX / 2) |
218 | goto err; | 219 | goto err; |
219 | 220 | ||
220 | /* | 221 | /* |