Skip to content

Commit 7c058c6

Browse files
committed
Prevent negative zero from being created via BN bit functions.
Both BN_clear_bit() and BN_mask_bits() can create zero values - in both cases ensure that the negative sign is correctly handled if the value becomes zero. Thanks to Guido Vranken for providing a reproducer. Fixes oss-fuzz #67901 ok tb@
1 parent ed75954 commit 7c058c6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/libcrypto/bn/bn_lib.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bn_lib.c,v 1.90 2023/07/28 10:35:14 tb Exp $ */
1+
/* $OpenBSD: bn_lib.c,v 1.91 2024/04/15 14:35:25 jsing Exp $ */
22
/* Copyright (C) 1995-1998 Eric Young ([email protected])
33
* All rights reserved.
44
*
@@ -438,6 +438,9 @@ BN_clear_bit(BIGNUM *a, int n)
438438

439439
a->d[i] &= (~(((BN_ULONG)1) << j));
440440
bn_correct_top(a);
441+
442+
BN_set_negative(a, a->neg);
443+
441444
return (1);
442445
}
443446
LCRYPTO_ALIAS(BN_clear_bit);
@@ -476,6 +479,9 @@ BN_mask_bits(BIGNUM *a, int n)
476479
a->d[w] &= ~(BN_MASK2 << b);
477480
}
478481
bn_correct_top(a);
482+
483+
BN_set_negative(a, a->neg);
484+
479485
return (1);
480486
}
481487
LCRYPTO_ALIAS(BN_mask_bits);

0 commit comments

Comments
 (0)