summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2025-05-25 04:16:36 +0000
committerjsing <>2025-05-25 04:16:36 +0000
commit53d43909d135b928ff58dfdf0554e5e6b2eef4ab (patch)
tree1d4816bddc9a0cb0376f952d4ccf4c4cf05bd1ce /src
parent05d2a9c66d6d77326bcdda5607d6a1cc119a16da (diff)
downloadopenbsd-53d43909d135b928ff58dfdf0554e5e6b2eef4ab.tar.gz
openbsd-53d43909d135b928ff58dfdf0554e5e6b2eef4ab.tar.bz2
openbsd-53d43909d135b928ff58dfdf0554e5e6b2eef4ab.zip
Fix handling of different length inputs in bn_sub().
In the diff_len < 0 case, it incorrectly uses 0 - b[0], which mishandles the borrow - fix this by using bn_subw_subw(). Do the same in the diff_len > 0 case for consistency. Note that this is never currently reached since BN_usub() requires a >= b. ok beck@ tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/bn_add.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
index 79fc1db41e..db1767ea55 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.27 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: bn_add.c,v 1.28 2025/05/25 04:16:36 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 *
@@ -207,7 +207,7 @@ bn_sub(BN_ULONG *r, int r_len, const BN_ULONG *a, int a_len, const BN_ULONG *b,
207 /* XXX - consider doing four at a time to match bn_sub_words. */ 207 /* XXX - consider doing four at a time to match bn_sub_words. */
208 while (diff_len < 0) { 208 while (diff_len < 0) {
209 /* Compute r[0] = 0 - b[0] - borrow. */ 209 /* Compute r[0] = 0 - b[0] - borrow. */
210 bn_subw(0 - b[0], borrow, &borrow, &r[0]); 210 bn_subw_subw(0, b[0], borrow, &borrow, &r[0]);
211 diff_len++; 211 diff_len++;
212 b++; 212 b++;
213 r++; 213 r++;
@@ -216,7 +216,7 @@ bn_sub(BN_ULONG *r, int r_len, const BN_ULONG *a, int a_len, const BN_ULONG *b,
216 /* XXX - consider doing four at a time to match bn_sub_words. */ 216 /* XXX - consider doing four at a time to match bn_sub_words. */
217 while (diff_len > 0) { 217 while (diff_len > 0) {
218 /* Compute r[0] = a[0] - 0 - borrow. */ 218 /* Compute r[0] = a[0] - 0 - borrow. */
219 bn_subw(a[0], borrow, &borrow, &r[0]); 219 bn_subw_subw(a[0], 0, borrow, &borrow, &r[0]);
220 diff_len--; 220 diff_len--;
221 a++; 221 a++;
222 r++; 222 r++;