diff options
| author | jsing <> | 2024-04-16 13:14:46 +0000 |
|---|---|---|
| committer | jsing <> | 2024-04-16 13:14:46 +0000 |
| commit | 20b733dad0a708b937ef54aa3435a51f6ad6d75c (patch) | |
| tree | 8d7dd3ecdc913f4f39eec2b898eab4da3bca4117 | |
| parent | 3aa891e8442fec9e0f427d6a05cbcdf11c039294 (diff) | |
| download | openbsd-20b733dad0a708b937ef54aa3435a51f6ad6d75c.tar.gz openbsd-20b733dad0a708b937ef54aa3435a51f6ad6d75c.tar.bz2 openbsd-20b733dad0a708b937ef54aa3435a51f6ad6d75c.zip | |
Invert BN_BITS2 handling in bn_bin2bn_cbs() and bn_hex2bn_cbs().
This results in simpler code.
Suggested by tb@ during review.
| -rw-r--r-- | src/lib/libcrypto/bn/bn_convert.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/lib/libcrypto/bn/bn_convert.c b/src/lib/libcrypto/bn/bn_convert.c index 2b12670ea5..5c3c98b787 100644 --- a/src/lib/libcrypto/bn/bn_convert.c +++ b/src/lib/libcrypto/bn/bn_convert.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_convert.c,v 1.17 2024/04/16 13:11:37 jsing Exp $ */ | 1 | /* $OpenBSD: bn_convert.c,v 1.18 2024/04/16 13:14:46 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 | * |
| @@ -168,7 +168,7 @@ bn_bin2bn_cbs(BIGNUM **bnp, CBS *cbs) | |||
| 168 | if (!bn_expand_bytes(bn, CBS_len(cbs))) | 168 | if (!bn_expand_bytes(bn, CBS_len(cbs))) |
| 169 | goto err; | 169 | goto err; |
| 170 | 170 | ||
| 171 | b = BN_BITS2; | 171 | b = 0; |
| 172 | i = 0; | 172 | i = 0; |
| 173 | w = 0; | 173 | w = 0; |
| 174 | 174 | ||
| @@ -176,11 +176,11 @@ bn_bin2bn_cbs(BIGNUM **bnp, CBS *cbs) | |||
| 176 | if (!CBS_get_last_u8(cbs, &v)) | 176 | if (!CBS_get_last_u8(cbs, &v)) |
| 177 | goto err; | 177 | goto err; |
| 178 | 178 | ||
| 179 | w |= (BN_ULONG)v << (BN_BITS2 - b); | 179 | w |= (BN_ULONG)v << b; |
| 180 | b -= 8; | 180 | b += 8; |
| 181 | 181 | ||
| 182 | if (b == 0 || CBS_len(cbs) == 0) { | 182 | if (b == BN_BITS2 || CBS_len(cbs) == 0) { |
| 183 | b = BN_BITS2; | 183 | b = 0; |
| 184 | bn->d[i++] = w; | 184 | bn->d[i++] = w; |
| 185 | w = 0; | 185 | w = 0; |
| 186 | } | 186 | } |
| @@ -657,7 +657,7 @@ bn_hex2bn_cbs(BIGNUM **bnp, CBS *cbs) | |||
| 657 | if (!CBS_get_bytes(cbs, cbs, digits)) | 657 | if (!CBS_get_bytes(cbs, cbs, digits)) |
| 658 | goto err; | 658 | goto err; |
| 659 | 659 | ||
| 660 | b = BN_BITS2; | 660 | b = 0; |
| 661 | i = 0; | 661 | i = 0; |
| 662 | w = 0; | 662 | w = 0; |
| 663 | 663 | ||
| @@ -675,11 +675,11 @@ bn_hex2bn_cbs(BIGNUM **bnp, CBS *cbs) | |||
| 675 | else | 675 | else |
| 676 | goto err; | 676 | goto err; |
| 677 | 677 | ||
| 678 | w |= (BN_ULONG)v << (BN_BITS2 - b); | 678 | w |= (BN_ULONG)v << b; |
| 679 | b -= 4; | 679 | b += 4; |
| 680 | 680 | ||
| 681 | if (b == 0 || digits == 0) { | 681 | if (b == BN_BITS2 || digits == 0) { |
| 682 | b = BN_BITS2; | 682 | b = 0; |
| 683 | bn->d[i++] = w; | 683 | bn->d[i++] = w; |
| 684 | w = 0; | 684 | w = 0; |
| 685 | } | 685 | } |
