From 3adccdb355e2f651255227b11a6324730cb85e48 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 30 Aug 2025 07:16:06 +0000 Subject: Rework bn_sqr() to use bn_sqr_words(). Rework some of the squaring code so that it calls bn_sqr_words() and use this as the integration point for assembly. Convert bn_sqr_normal() to bn_sqr_words(), which is then used on architectures that do not provide their own version. This means that we resume using the assembly version of bn_sqr_words() on i386, mips64 and powerpc, which can provide considerable performance gains. ok tb@ --- src/lib/libcrypto/bn/arch/amd64/bn_arch.c | 20 +++++++++----------- src/lib/libcrypto/bn/arch/amd64/bn_arch.h | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src/lib/libcrypto/bn/arch') diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.c b/src/lib/libcrypto/bn/arch/amd64/bn_arch.c index 9ff8920ca2..e4fbb4cfc3 100644 --- a/src/lib/libcrypto/bn/arch/amd64/bn_arch.c +++ b/src/lib/libcrypto/bn/arch/amd64/bn_arch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.c,v 1.12 2025/08/14 15:29:17 jsing Exp $ */ +/* $OpenBSD: bn_arch.c,v 1.13 2025/08/30 07:16:06 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -142,16 +142,6 @@ bn_mul_comba8(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) } #endif -#ifdef HAVE_BN_SQR -int -bn_sqr(BIGNUM *r, const BIGNUM *a, int r_len, BN_CTX *ctx) -{ - bignum_sqr(r_len, (uint64_t *)r->d, a->top, (const uint64_t *)a->d); - - return 1; -} -#endif - #ifdef HAVE_BN_SQR_COMBA4 void bn_sqr_comba4(BN_ULONG *rd, const BN_ULONG *ad) @@ -191,6 +181,14 @@ bn_sqr_comba8(BN_ULONG *rd, const BN_ULONG *ad) } #endif +#ifdef HAVE_BN_SQR_WORDS +void +bn_sqr_words(BN_ULONG *rd, const BN_ULONG *ad, int a_len) +{ + bignum_sqr(a_len * 2, (uint64_t *)rd, a_len, (const uint64_t *)ad); +} +#endif + #ifdef HAVE_BN_WORD_CLZ int bn_word_clz(BN_ULONG w) diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h index 7359f993a7..dd7abd3002 100644 --- a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h +++ b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.16 2025/08/14 15:22:54 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.17 2025/08/30 07:16:06 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -36,10 +36,10 @@ #define HAVE_BN_MUL_COMBA8 #define HAVE_BN_MUL_WORDS -#define HAVE_BN_SQR #define HAVE_BN_SQR_COMBA4 #define HAVE_BN_SQR_COMBA6 #define HAVE_BN_SQR_COMBA8 +#define HAVE_BN_SQR_WORDS #define HAVE_BN_SUB #define HAVE_BN_SUB_WORDS -- cgit v1.2.3-55-g6feb