summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2023-02-16 11:13:05 +0000
committerjsing <>2023-02-16 11:13:05 +0000
commit78b6c67232479df5c8a2d1b39ea628f0341a4202 (patch)
treea71844b7fce221564ef504741b86d1f18d98a9eb /src
parent3c4a975cefd1abb53303b3878d5531bcd9212000 (diff)
downloadopenbsd-78b6c67232479df5c8a2d1b39ea628f0341a4202.tar.gz
openbsd-78b6c67232479df5c8a2d1b39ea628f0341a4202.tar.bz2
openbsd-78b6c67232479df5c8a2d1b39ea628f0341a4202.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@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/arch/amd64/Makefile.inc3
-rw-r--r--src/lib/libcrypto/bn/arch/amd64/bn_arch.c10
-rw-r--r--src/lib/libcrypto/bn/arch/amd64/bn_arch.h4
-rw-r--r--src/lib/libcrypto/bn/bn_local.h4
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
39SRCS += bignum_sqr_4_8_alt.S 39SRCS += bignum_sqr_4_8_alt.S
40SRCS += bignum_sqr_8_16_alt.S 40SRCS += bignum_sqr_8_16_alt.S
41SRCS += bignum_sub.S 41SRCS += bignum_sub.S
42SRCS += word_clz.S
42 43
43# camellia 44# camellia
44SRCS+= cmll_misc.c 45SRCS+= 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
123int
124bn_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,
515int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, 515int 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
518int bn_word_clz(BN_ULONG w);
519
518void bn_correct_top(BIGNUM *a); 520void bn_correct_top(BIGNUM *a);
519int bn_expand(BIGNUM *a, int bits); 521int bn_expand(BIGNUM *a, int bits);
520int bn_wexpand(BIGNUM *a, int words); 522int bn_wexpand(BIGNUM *a, int words);