diff options
author | jsing <> | 2022-11-30 03:08:39 +0000 |
---|---|---|
committer | jsing <> | 2022-11-30 03:08:39 +0000 |
commit | a506c8140d92cbd17760f5379c72bebfe62f7fa3 (patch) | |
tree | eeb863e14aa894689036334d78d54b975591d3c1 /src | |
parent | c4a74c3795e06bd2bab862ba1b51d811fb3937ef (diff) | |
download | openbsd-a506c8140d92cbd17760f5379c72bebfe62f7fa3.tar.gz openbsd-a506c8140d92cbd17760f5379c72bebfe62f7fa3.tar.bz2 openbsd-a506c8140d92cbd17760f5379c72bebfe62f7fa3.zip |
Rewrite bn_correct_top().
bn_correct_top() is currently a macro and far more complex than it needs
to be - rewrite it as a function.
ok tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_local.h | 15 |
2 files changed, 10 insertions, 14 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index df43da5db6..851c337ef0 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_lib.c,v 1.65 2022/11/30 02:52:25 jsing Exp $ */ | 1 | /* $OpenBSD: bn_lib.c,v 1.66 2022/11/30 03:08:39 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 | * |
@@ -253,6 +253,13 @@ BN_num_bits(const BIGNUM *a) | |||
253 | return ((i * BN_BITS2) + BN_num_bits_word(a->d[i])); | 253 | return ((i * BN_BITS2) + BN_num_bits_word(a->d[i])); |
254 | } | 254 | } |
255 | 255 | ||
256 | void | ||
257 | bn_correct_top(BIGNUM *a) | ||
258 | { | ||
259 | while (a->top > 0 && a->d[a->top - 1] == 0) | ||
260 | a->top--; | ||
261 | } | ||
262 | |||
256 | /* The caller MUST check that words > b->dmax before calling this */ | 263 | /* The caller MUST check that words > b->dmax before calling this */ |
257 | static BN_ULONG * | 264 | static BN_ULONG * |
258 | bn_expand_internal(const BIGNUM *b, int words) | 265 | bn_expand_internal(const BIGNUM *b, int words) |
diff --git a/src/lib/libcrypto/bn/bn_local.h b/src/lib/libcrypto/bn/bn_local.h index 7bddcb21b9..48d24c5a27 100644 --- a/src/lib/libcrypto/bn/bn_local.h +++ b/src/lib/libcrypto/bn/bn_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_local.h,v 1.2 2022/11/26 17:23:17 tb Exp $ */ | 1 | /* $OpenBSD: bn_local.h,v 1.3 2022/11/30 03:08:39 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 | * |
@@ -509,21 +509,10 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | |||
509 | int cl, int dl); | 509 | int cl, int dl); |
510 | int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num); | 510 | int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num); |
511 | 511 | ||
512 | void bn_correct_top(BIGNUM *a); | ||
512 | int bn_expand(BIGNUM *a, int bits); | 513 | int bn_expand(BIGNUM *a, int bits); |
513 | int bn_wexpand(BIGNUM *a, int words); | 514 | int bn_wexpand(BIGNUM *a, int words); |
514 | 515 | ||
515 | #define bn_correct_top(a) \ | ||
516 | { \ | ||
517 | BN_ULONG *ftl; \ | ||
518 | int tmp_top = (a)->top; \ | ||
519 | if (tmp_top > 0) \ | ||
520 | { \ | ||
521 | for (ftl= &((a)->d[tmp_top-1]); tmp_top > 0; tmp_top--) \ | ||
522 | if (*(ftl--)) break; \ | ||
523 | (a)->top = tmp_top; \ | ||
524 | } \ | ||
525 | } | ||
526 | |||
527 | BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); | 516 | BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); |
528 | BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); | 517 | BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); |
529 | void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num); | 518 | void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num); |