summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c9
-rw-r--r--src/lib/libcrypto/bn/bn_local.h15
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
256void
257bn_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 */
257static BN_ULONG * 264static BN_ULONG *
258bn_expand_internal(const BIGNUM *b, int words) 265bn_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);
510int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num); 510int 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
512void bn_correct_top(BIGNUM *a);
512int bn_expand(BIGNUM *a, int bits); 513int bn_expand(BIGNUM *a, int bits);
513int bn_wexpand(BIGNUM *a, int words); 514int 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
527BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); 516BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
528BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); 517BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
529void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num); 518void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num);