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_add.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_add.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_add.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c index dc525db084..8ae9bbe854 100644 --- a/src/lib/libcrypto/bn/bn_add.c +++ b/src/lib/libcrypto/bn/bn_add.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_add.c,v 1.21 2023/02/02 18:39:26 jsing Exp $ */ | 1 | /* $OpenBSD: bn_add.c,v 1.22 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 | * |
@@ -381,7 +381,8 @@ BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | |||
381 | } | 381 | } |
382 | } | 382 | } |
383 | 383 | ||
384 | r->neg = r_neg; | 384 | BN_set_negative(r, r_neg); |
385 | |||
385 | return ret; | 386 | return ret; |
386 | } | 387 | } |
387 | 388 | ||
@@ -409,6 +410,7 @@ BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | |||
409 | } | 410 | } |
410 | } | 411 | } |
411 | 412 | ||
412 | r->neg = r_neg; | 413 | BN_set_negative(r, r_neg); |
414 | |||
413 | return ret; | 415 | return ret; |
414 | } | 416 | } |