From 29e5785c829e5b26b1eac308e8e044c1879868e8 Mon Sep 17 00:00:00 2001 From: jsing Date: Wed, 23 Nov 2022 03:00:12 +0000 Subject: [PATCH] Turn bn_wexpand() into a function. Any sensible compiler will likely inline this anyway (and even if it does not, one extra function call/return is the least of the performance overhead for this code). ok tb@ --- lib/libcrypto/bn/bn_lcl.h | 5 ++--- lib/libcrypto/bn/bn_lib.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/libcrypto/bn/bn_lcl.h b/lib/libcrypto/bn/bn_lcl.h index 4fac4e7f55e..63289f66fb0 100644 --- a/lib/libcrypto/bn/bn_lcl.h +++ b/lib/libcrypto/bn/bn_lcl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_lcl.h,v 1.36 2022/11/23 02:44:01 jsing Exp $ */ +/* $OpenBSD: bn_lcl.h,v 1.37 2022/11/23 03:00:12 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -521,9 +521,8 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int cl, int dl); 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); -#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words))) -BIGNUM *bn_expand2(BIGNUM *a, int words); BIGNUM *bn_expand(BIGNUM *a, int bits); +BIGNUM *bn_wexpand(BIGNUM *a, int words); /* Bignum consistency macros * There is one "API" macro, bn_fix_top(), for stripping leading zeroes from diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c index 7ec338b9266..7c85e7ad081 100644 --- a/lib/libcrypto/bn/bn_lib.c +++ b/lib/libcrypto/bn/bn_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_lib.c,v 1.57 2022/11/23 02:46:09 jsing Exp $ */ +/* $OpenBSD: bn_lib.c,v 1.58 2022/11/23 03:00:12 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -334,7 +334,7 @@ bn_expand_internal(const BIGNUM *b, int words) * It is mostly used by the various BIGNUM routines. If there is an error, * NULL is returned. If not, 'b' is returned. */ -BIGNUM * +static BIGNUM * bn_expand2(BIGNUM *b, int words) { bn_check_top(b); @@ -386,6 +386,15 @@ bn_expand(BIGNUM *a, int bits) return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2); } +BIGNUM * +bn_wexpand(BIGNUM *a, int words) +{ + if (words <= a->dmax) + return a; + + return bn_expand2(a, words); +} + BIGNUM * BN_dup(const BIGNUM *a) { -- 2.20.1