diff options
| author | jsing <> | 2025-08-30 07:16:06 +0000 |
|---|---|---|
| committer | jsing <> | 2025-08-30 07:16:06 +0000 |
| commit | 3adccdb355e2f651255227b11a6324730cb85e48 (patch) | |
| tree | fd3d5dda7990f2093417b07b765c94736fe90995 /src/lib/libcrypto/bn/arch | |
| parent | 1be59554e7c016fbcde4d8264e8db21d7efb3688 (diff) | |
| download | openbsd-3adccdb355e2f651255227b11a6324730cb85e48.tar.gz openbsd-3adccdb355e2f651255227b11a6324730cb85e48.tar.bz2 openbsd-3adccdb355e2f651255227b11a6324730cb85e48.zip | |
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@
Diffstat (limited to 'src/lib/libcrypto/bn/arch')
| -rw-r--r-- | src/lib/libcrypto/bn/arch/amd64/bn_arch.c | 20 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/arch/amd64/bn_arch.h | 4 |
2 files changed, 11 insertions, 13 deletions
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 @@ | |||
| 1 | /* $OpenBSD: bn_arch.c,v 1.12 2025/08/14 15:29:17 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.c,v 1.13 2025/08/30 07:16:06 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -142,16 +142,6 @@ bn_mul_comba8(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd) | |||
| 142 | } | 142 | } |
| 143 | #endif | 143 | #endif |
| 144 | 144 | ||
| 145 | #ifdef HAVE_BN_SQR | ||
| 146 | int | ||
| 147 | bn_sqr(BIGNUM *r, const BIGNUM *a, int r_len, BN_CTX *ctx) | ||
| 148 | { | ||
| 149 | bignum_sqr(r_len, (uint64_t *)r->d, a->top, (const uint64_t *)a->d); | ||
| 150 | |||
| 151 | return 1; | ||
| 152 | } | ||
| 153 | #endif | ||
| 154 | |||
| 155 | #ifdef HAVE_BN_SQR_COMBA4 | 145 | #ifdef HAVE_BN_SQR_COMBA4 |
| 156 | void | 146 | void |
| 157 | bn_sqr_comba4(BN_ULONG *rd, const BN_ULONG *ad) | 147 | bn_sqr_comba4(BN_ULONG *rd, const BN_ULONG *ad) |
| @@ -191,6 +181,14 @@ bn_sqr_comba8(BN_ULONG *rd, const BN_ULONG *ad) | |||
| 191 | } | 181 | } |
| 192 | #endif | 182 | #endif |
| 193 | 183 | ||
| 184 | #ifdef HAVE_BN_SQR_WORDS | ||
| 185 | void | ||
| 186 | bn_sqr_words(BN_ULONG *rd, const BN_ULONG *ad, int a_len) | ||
| 187 | { | ||
| 188 | bignum_sqr(a_len * 2, (uint64_t *)rd, a_len, (const uint64_t *)ad); | ||
| 189 | } | ||
| 190 | #endif | ||
| 191 | |||
| 194 | #ifdef HAVE_BN_WORD_CLZ | 192 | #ifdef HAVE_BN_WORD_CLZ |
| 195 | int | 193 | int |
| 196 | bn_word_clz(BN_ULONG w) | 194 | 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 @@ | |||
| 1 | /* $OpenBSD: bn_arch.h,v 1.16 2025/08/14 15:22:54 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.17 2025/08/30 07:16:06 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -36,10 +36,10 @@ | |||
| 36 | #define HAVE_BN_MUL_COMBA8 | 36 | #define HAVE_BN_MUL_COMBA8 |
| 37 | #define HAVE_BN_MUL_WORDS | 37 | #define HAVE_BN_MUL_WORDS |
| 38 | 38 | ||
| 39 | #define HAVE_BN_SQR | ||
| 40 | #define HAVE_BN_SQR_COMBA4 | 39 | #define HAVE_BN_SQR_COMBA4 |
| 41 | #define HAVE_BN_SQR_COMBA6 | 40 | #define HAVE_BN_SQR_COMBA6 |
| 42 | #define HAVE_BN_SQR_COMBA8 | 41 | #define HAVE_BN_SQR_COMBA8 |
| 42 | #define HAVE_BN_SQR_WORDS | ||
| 43 | 43 | ||
| 44 | #define HAVE_BN_SUB | 44 | #define HAVE_BN_SUB |
| 45 | #define HAVE_BN_SUB_WORDS | 45 | #define HAVE_BN_SUB_WORDS |
