diff options
author | jsing <> | 2023-02-13 04:25:37 +0000 |
---|---|---|
committer | jsing <> | 2023-02-13 04:25:37 +0000 |
commit | 59402a8926d023550549cfdb576bcecdb23bb2bc (patch) | |
tree | 3f4664b9d6259b538a970687b222189d9d59afb5 /src/lib/libcrypto/bn/bn_mpi.c | |
parent | b0f0ff7e648539633669f7fb4530b8d5fc901052 (diff) | |
download | openbsd-59402a8926d023550549cfdb576bcecdb23bb2bc.tar.gz openbsd-59402a8926d023550549cfdb576bcecdb23bb2bc.tar.bz2 openbsd-59402a8926d023550549cfdb576bcecdb23bb2bc.zip |
Avoid negative zero.
Whenever setting negative to one (or when it could potentially be one),
always use BN_set_negative() since it checks for a zero valued bignum and
will not permit negative to be set in this case. Since BN_is_zero()
currently relies on top == 0, call BN_set_negative() after top has been
set (or bn_correct_top() has been called).
This fixes a long standing issue where -0 and +0 have been permitted,
however multiple code paths (such as BN_cmp()) fail to treat these as
equivalent.
Prompted by Guido Vranken who is adding negative zero fuzzing to oss-fuzz.
ok tb@
Diffstat (limited to 'src/lib/libcrypto/bn/bn_mpi.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_mpi.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c index 9ad28b96c9..e3b9ba0dd9 100644 --- a/src/lib/libcrypto/bn/bn_mpi.c +++ b/src/lib/libcrypto/bn/bn_mpi.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_mpi.c,v 1.11 2022/11/26 16:08:51 tb Exp $ */ | 1 | /* $OpenBSD: bn_mpi.c,v 1.12 2023/02/13 04:25:37 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 | * |
@@ -127,7 +127,7 @@ BN_mpi2bn(const unsigned char *d, int n, BIGNUM *ain) | |||
127 | BN_free(a); | 127 | BN_free(a); |
128 | return (NULL); | 128 | return (NULL); |
129 | } | 129 | } |
130 | a->neg = neg; | 130 | BN_set_negative(a, neg); |
131 | if (neg) { | 131 | if (neg) { |
132 | BN_clear_bit(a, BN_num_bits(a) - 1); | 132 | BN_clear_bit(a, BN_num_bits(a) - 1); |
133 | } | 133 | } |