summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2023-03-11 14:13:11 +0000
committerjsing <>2023-03-11 14:13:11 +0000
commit2169aa7d8fb1fca93b35610fe1cce79730752235 (patch)
tree0e761bee36c1a19143b0930f375dcd4bbe41820a /src/lib
parentfc34d2e11e2863715e991553eaeef6c687ec8910 (diff)
downloadopenbsd-2169aa7d8fb1fca93b35610fe1cce79730752235.tar.gz
openbsd-2169aa7d8fb1fca93b35610fe1cce79730752235.tar.bz2
openbsd-2169aa7d8fb1fca93b35610fe1cce79730752235.zip
Correct sign handling in BN_add_word().
A sign handling bug was introduced to BN_add_word() in bn_word.c r1.18. When handling addition to a negative bignum, the BN_sub_word() call can result in the sign being flipped, which we need to account for. Use the same code in BN_sub_word() - while not technically needed here it keeps the code consistent. Issue discovered by tb@ ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/bn/bn_word.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
index a44221c35f..c900f9ee2e 100644
--- a/src/lib/libcrypto/bn/bn_word.c
+++ b/src/lib/libcrypto/bn/bn_word.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_word.c,v 1.18 2023/02/13 04:25:37 jsing Exp $ */ 1/* $OpenBSD: bn_word.c,v 1.19 2023/03/11 14:13:11 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 *
@@ -152,7 +152,7 @@ BN_add_word(BIGNUM *a, BN_ULONG w)
152 if (a->neg) { 152 if (a->neg) {
153 a->neg = 0; 153 a->neg = 0;
154 i = BN_sub_word(a, w); 154 i = BN_sub_word(a, w);
155 BN_set_negative(a, 1); 155 BN_set_negative(a, !a->neg);
156 return (i); 156 return (i);
157 } 157 }
158 for (i = 0; w != 0 && i < a->top; i++) { 158 for (i = 0; w != 0 && i < a->top; i++) {
@@ -189,7 +189,7 @@ BN_sub_word(BIGNUM *a, BN_ULONG w)
189 if (a->neg) { 189 if (a->neg) {
190 a->neg = 0; 190 a->neg = 0;
191 i = BN_add_word(a, w); 191 i = BN_add_word(a, w);
192 BN_set_negative(a, 1); 192 BN_set_negative(a, !a->neg);
193 return (i); 193 return (i);
194 } 194 }
195 195