diff options
author | jsing <> | 2023-02-14 18:19:27 +0000 |
---|---|---|
committer | jsing <> | 2023-02-14 18:19:27 +0000 |
commit | 9ce34d33ab5e28ffa5d1cd29ccc09a8651396e96 (patch) | |
tree | 518ba504bb3bbd0ffd8b0f4c083c1f3d81b99dd7 /src | |
parent | c7a2e8ba6107b06cc3b3a4ac5577d2469643f574 (diff) | |
download | openbsd-9ce34d33ab5e28ffa5d1cd29ccc09a8651396e96.tar.gz openbsd-9ce34d33ab5e28ffa5d1cd29ccc09a8651396e96.tar.bz2 openbsd-9ce34d33ab5e28ffa5d1cd29ccc09a8651396e96.zip |
Fix a -0 corner case in BN_div_internal()
If the numerator is negative, the numerator and divisor are the same
length (in words) and the absolute value of the divisor > the absolute
value of the numerator, the "no_branch" case produces -0 since negative
has already been set. Call BN_set_negative() at the end of the function
to avoid this.
ok tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_div.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c index 7ada277402..686b957eb5 100644 --- a/src/lib/libcrypto/bn/bn_div.c +++ b/src/lib/libcrypto/bn/bn_div.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_div.c,v 1.37 2023/02/13 04:25:37 jsing Exp $ */ | 1 | /* $OpenBSD: bn_div.c,v 1.38 2023/02/14 18:19:27 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 | * |
@@ -237,7 +237,7 @@ static int | |||
237 | BN_div_internal(BIGNUM *quotient, BIGNUM *remainder, const BIGNUM *numerator, | 237 | BN_div_internal(BIGNUM *quotient, BIGNUM *remainder, const BIGNUM *numerator, |
238 | const BIGNUM *divisor, BN_CTX *ctx, int ct) | 238 | const BIGNUM *divisor, BN_CTX *ctx, int ct) |
239 | { | 239 | { |
240 | int norm_shift, i, loop; | 240 | int norm_shift, i, loop, r_neg; |
241 | BIGNUM *tmp, wnum, *snum, *sdiv, *res; | 241 | BIGNUM *tmp, wnum, *snum, *sdiv, *res; |
242 | BN_ULONG *resp, *wnump; | 242 | BN_ULONG *resp, *wnump; |
243 | BN_ULONG d0, d1; | 243 | BN_ULONG d0, d1; |
@@ -341,7 +341,7 @@ BN_div_internal(BIGNUM *quotient, BIGNUM *remainder, const BIGNUM *numerator, | |||
341 | if (!bn_wexpand(res, (loop + 1))) | 341 | if (!bn_wexpand(res, (loop + 1))) |
342 | goto err; | 342 | goto err; |
343 | res->top = loop - no_branch; | 343 | res->top = loop - no_branch; |
344 | BN_set_negative(res, numerator->neg ^ divisor->neg); | 344 | r_neg = numerator->neg ^ divisor->neg; |
345 | resp = &(res->d[loop - 1]); | 345 | resp = &(res->d[loop - 1]); |
346 | 346 | ||
347 | /* space for temp */ | 347 | /* space for temp */ |
@@ -420,6 +420,8 @@ BN_div_internal(BIGNUM *quotient, BIGNUM *remainder, const BIGNUM *numerator, | |||
420 | if (no_branch) | 420 | if (no_branch) |
421 | bn_correct_top(res); | 421 | bn_correct_top(res); |
422 | 422 | ||
423 | BN_set_negative(res, r_neg); | ||
424 | |||
423 | done: | 425 | done: |
424 | ret = 1; | 426 | ret = 1; |
425 | err: | 427 | err: |