diff options
| author | jsing <> | 2023-02-16 11:13:05 +0000 |
|---|---|---|
| committer | jsing <> | 2023-02-16 11:13:05 +0000 |
| commit | 02f91f3325f965a313f0cffe5053a084d05a84ea (patch) | |
| tree | a71844b7fce221564ef504741b86d1f18d98a9eb | |
| parent | 67bcdfeb3f62f73d8ba148704bccbfb2cff0f697 (diff) | |
| download | openbsd-02f91f3325f965a313f0cffe5053a084d05a84ea.tar.gz openbsd-02f91f3325f965a313f0cffe5053a084d05a84ea.tar.bz2 openbsd-02f91f3325f965a313f0cffe5053a084d05a84ea.zip | |
Enable s2n-bignum word_clz() on amd64.
The BN_num_bits_word() function is a hot path, being called more than
80 million times during a libcrypto regress run. The word_clz()
implementation uses five instructions to do the same as the generic code
that uses more than 60 instructions.
Discussed with tb@
| -rw-r--r-- | src/lib/libcrypto/arch/amd64/Makefile.inc | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/arch/amd64/bn_arch.c | 10 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/arch/amd64/bn_arch.h | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/bn_local.h | 4 |
4 files changed, 17 insertions, 4 deletions
diff --git a/src/lib/libcrypto/arch/amd64/Makefile.inc b/src/lib/libcrypto/arch/amd64/Makefile.inc index 5e433b572d..e9c7732691 100644 --- a/src/lib/libcrypto/arch/amd64/Makefile.inc +++ b/src/lib/libcrypto/arch/amd64/Makefile.inc | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.11 2023/01/29 14:00:41 jsing Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.12 2023/02/16 11:13:05 jsing Exp $ |
| 2 | 2 | ||
| 3 | # amd64-specific libcrypto build rules | 3 | # amd64-specific libcrypto build rules |
| 4 | 4 | ||
| @@ -39,6 +39,7 @@ SRCS += bignum_sqr.S | |||
| 39 | SRCS += bignum_sqr_4_8_alt.S | 39 | SRCS += bignum_sqr_4_8_alt.S |
| 40 | SRCS += bignum_sqr_8_16_alt.S | 40 | SRCS += bignum_sqr_8_16_alt.S |
| 41 | SRCS += bignum_sub.S | 41 | SRCS += bignum_sub.S |
| 42 | SRCS += word_clz.S | ||
| 42 | 43 | ||
| 43 | # camellia | 44 | # camellia |
| 44 | SRCS+= cmll_misc.c | 45 | SRCS+= cmll_misc.c |
diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.c b/src/lib/libcrypto/bn/arch/amd64/bn_arch.c index be2badc8a8..a4a2d93ada 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.4 2023/02/04 14:00:18 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.c,v 1.5 2023/02/16 11:13:05 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -118,3 +118,11 @@ bn_sqr_comba8(BN_ULONG *rd, const BN_ULONG *ad) | |||
| 118 | bignum_sqr_8_16_alt((uint64_t *)rd, (uint64_t *)ad); | 118 | bignum_sqr_8_16_alt((uint64_t *)rd, (uint64_t *)ad); |
| 119 | } | 119 | } |
| 120 | #endif | 120 | #endif |
| 121 | |||
| 122 | #ifdef HAVE_BN_WORD_CLZ | ||
| 123 | int | ||
| 124 | bn_word_clz(BN_ULONG w) | ||
| 125 | { | ||
| 126 | return word_clz(w); | ||
| 127 | } | ||
| 128 | #endif | ||
diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h index 80f73bf15f..f3653bcc40 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.12 2023/02/16 10:41:03 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.13 2023/02/16 11:13:05 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -39,6 +39,8 @@ | |||
| 39 | #define HAVE_BN_SUB | 39 | #define HAVE_BN_SUB |
| 40 | #define HAVE_BN_SUB_WORDS | 40 | #define HAVE_BN_SUB_WORDS |
| 41 | 41 | ||
| 42 | #define HAVE_BN_WORD_CLZ | ||
| 43 | |||
| 42 | #if defined(__GNUC__) | 44 | #if defined(__GNUC__) |
| 43 | #define HAVE_BN_DIV_REM_WORDS_INLINE | 45 | #define HAVE_BN_DIV_REM_WORDS_INLINE |
| 44 | 46 | ||
diff --git a/src/lib/libcrypto/bn/bn_local.h b/src/lib/libcrypto/bn/bn_local.h index 1830264fa2..51582f9833 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.9 2023/02/14 18:45:39 jsing Exp $ */ | 1 | /* $OpenBSD: bn_local.h,v 1.10 2023/02/16 11:13:05 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 | * |
| @@ -515,6 +515,8 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | |||
| 515 | int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, | 515 | int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, |
| 516 | const BN_ULONG *np, const BN_ULONG *n0, int num); | 516 | const BN_ULONG *np, const BN_ULONG *n0, int num); |
| 517 | 517 | ||
| 518 | int bn_word_clz(BN_ULONG w); | ||
| 519 | |||
| 518 | void bn_correct_top(BIGNUM *a); | 520 | void bn_correct_top(BIGNUM *a); |
| 519 | int bn_expand(BIGNUM *a, int bits); | 521 | int bn_expand(BIGNUM *a, int bits); |
| 520 | int bn_wexpand(BIGNUM *a, int words); | 522 | int bn_wexpand(BIGNUM *a, int words); |
