diff options
| author | jsing <> | 2023-01-31 05:16:52 +0000 |
|---|---|---|
| committer | jsing <> | 2023-01-31 05:16:52 +0000 |
| commit | 1577bb088bd6ac8a2578ab2e8af7f0ed8cbb1584 (patch) | |
| tree | 89342ff559044bab73963cc74c1c24831e4c6592 /src/lib/libcrypto/bn/bn_add.c | |
| parent | 8c50252c9c3391d1cd80957def3445109748b50d (diff) | |
| download | openbsd-1577bb088bd6ac8a2578ab2e8af7f0ed8cbb1584.tar.gz openbsd-1577bb088bd6ac8a2578ab2e8af7f0ed8cbb1584.tar.bz2 openbsd-1577bb088bd6ac8a2578ab2e8af7f0ed8cbb1584.zip | |
Correctly detect b < a in BN_usub().
BN_usub() requires that a >= b and should return an error in the case that
b < a. This is currently only detected by checking the number of words in
a versus b - if they have the same number of words, the top word is not
checked and b < a, which then succeeds and produces an incorrect result.
Fix this by checking for the case where a and b have an equal number of
words, yet there is a borrow returned from bn_sub_words().
ok miod@ tb@
Diffstat (limited to 'src/lib/libcrypto/bn/bn_add.c')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_add.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c index c5bc024f3f..cfc04fd032 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.19 2023/01/23 10:34:21 jsing Exp $ */ | 1 | /* $OpenBSD: bn_add.c,v 1.20 2023/01/31 05:16:52 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 | * |
| @@ -291,6 +291,10 @@ BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | |||
| 291 | rp = r->d; | 291 | rp = r->d; |
| 292 | 292 | ||
| 293 | borrow = bn_sub_words(rp, ap, bp, min); | 293 | borrow = bn_sub_words(rp, ap, bp, min); |
| 294 | if (dif == 0 && borrow > 0) { | ||
| 295 | BNerror(BN_R_ARG2_LT_ARG3); | ||
| 296 | return 0; | ||
| 297 | } | ||
| 294 | ap += min; | 298 | ap += min; |
| 295 | rp += min; | 299 | rp += min; |
| 296 | 300 | ||
