summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2023-01-29 14:00:41 +0000
committerjsing <>2023-01-29 14:00:41 +0000
commitbbe5b1e2c136907ee38f7b612d2562cb2d6704d3 (patch)
tree7e45e2611f536ee754d3ab8b0bc9d5c4e58f4593 /src
parent2d39bdcb54c63d8e6f9a6cd26fc31ce17907a909 (diff)
downloadopenbsd-bbe5b1e2c136907ee38f7b612d2562cb2d6704d3.tar.gz
openbsd-bbe5b1e2c136907ee38f7b612d2562cb2d6704d3.tar.bz2
openbsd-bbe5b1e2c136907ee38f7b612d2562cb2d6704d3.zip
Use s2n-bignum assembly implementations for libcrypto bignum on amd64.
This switches the core bignum assembly implementations from x86_64-gcc.c to s2n-bignum for amd64. ok miod@ tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/arch/amd64/Makefile.inc13
-rw-r--r--src/lib/libcrypto/bn/arch/amd64/bn_arch.c80
2 files changed, 90 insertions, 3 deletions
diff --git a/src/lib/libcrypto/arch/amd64/Makefile.inc b/src/lib/libcrypto/arch/amd64/Makefile.inc
index 1fd9f68919..5e433b572d 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.10 2023/01/21 17:29:56 jsing Exp $ 1# $OpenBSD: Makefile.inc,v 1.11 2023/01/29 14:00:41 jsing Exp $
2 2
3# amd64-specific libcrypto build rules 3# amd64-specific libcrypto build rules
4 4
@@ -29,7 +29,16 @@ SSLASM+= bn x86_64-gf2m
29 29
30# bn s2n-bignum 30# bn s2n-bignum
31SRCS += bn_arch.c 31SRCS += bn_arch.c
32SRCS += bignum_add.S
33SRCS += bignum_cmadd.S
34SRCS += bignum_cmul.S
35SRCS += bignum_mul.S
36SRCS += bignum_mul_4_8_alt.S
37SRCS += bignum_mul_8_16_alt.S
32SRCS += bignum_sqr.S 38SRCS += bignum_sqr.S
39SRCS += bignum_sqr_4_8_alt.S
40SRCS += bignum_sqr_8_16_alt.S
41SRCS += bignum_sub.S
33 42
34# camellia 43# camellia
35SRCS+= cmll_misc.c 44SRCS+= cmll_misc.c
@@ -75,7 +84,7 @@ ${f}.S: ${LCRYPTO_SRC}/${dir}/asm/${f}.pl ${EXTRA_PL}
75.endfor 84.endfor
76 85
77CFLAGS+= -DOPENSSL_CPUID_OBJ 86CFLAGS+= -DOPENSSL_CPUID_OBJ
78SRCS+= x86_64cpuid.S x86_64-gcc.c 87SRCS+= x86_64cpuid.S
79GENERATED+=x86_64cpuid.S 88GENERATED+=x86_64cpuid.S
80 89
81x86_64cpuid.S: ${LCRYPTO_SRC}/x86_64cpuid.pl ${EXTRA_PL} 90x86_64cpuid.S: ${LCRYPTO_SRC}/x86_64cpuid.pl ${EXTRA_PL}
diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.c b/src/lib/libcrypto/bn/arch/amd64/bn_arch.c
index 240575955c..aedefc76e2 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.1 2023/01/21 17:29:56 jsing Exp $ */ 1/* $OpenBSD: bn_arch.c,v 1.2 2023/01/29 14:00:41 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -21,6 +21,58 @@
21#include "bn_local.h" 21#include "bn_local.h"
22#include "s2n_bignum.h" 22#include "s2n_bignum.h"
23 23
24#ifdef HAVE_BN_ADD_WORDS
25BN_ULONG
26bn_add_words(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd, int n)
27{
28 return bignum_add(n, (uint64_t *)rd, n, (uint64_t *)ad, n,
29 (uint64_t *)bd);
30}
31#endif
32
33#ifdef HAVE_BN_SUB_WORDS
34BN_ULONG
35bn_sub_words(BN_ULONG *rd, const BN_ULONG *ad, const BN_ULONG *bd, int n)
36{
37 return bignum_sub(n, (uint64_t *)rd, n, (uint64_t *)ad, n,
38 (uint64_t *)bd);
39}
40#endif
41
42#ifdef HAVE_BN_MUL_ADD_WORDS
43BN_ULONG
44bn_mul_add_words(BN_ULONG *rd, const BN_ULONG *ad, int num, BN_ULONG w)
45{
46 return bignum_cmadd(num, (uint64_t *)rd, w, num, (uint64_t *)ad);
47}
48#endif
49
50#ifdef HAVE_BN_MUL_WORDS
51BN_ULONG
52bn_mul_words(BN_ULONG *rd, const BN_ULONG *ad, int num, BN_ULONG w)
53{
54 return bignum_cmul(num, (uint64_t *)rd, w, num, (uint64_t *)ad);
55}
56#endif
57
58#ifdef HAVE_BN_MUL_COMBA4
59void
60bn_mul_comba4(BN_ULONG *rd, BN_ULONG *ad, BN_ULONG *bd)
61{
62 /* XXX - consider using non-alt on CPUs that have the ADX extension. */
63 bignum_mul_4_8_alt((uint64_t *)rd, (uint64_t *)ad, (uint64_t *)bd);
64}
65#endif
66
67#ifdef HAVE_BN_MUL_COMBA8
68void
69bn_mul_comba8(BN_ULONG *rd, BN_ULONG *ad, BN_ULONG *bd)
70{
71 /* XXX - consider using non-alt on CPUs that have the ADX extension. */
72 bignum_mul_8_16_alt((uint64_t *)rd, (uint64_t *)ad, (uint64_t *)bd);
73}
74#endif
75
24#ifdef HAVE_BN_SQR 76#ifdef HAVE_BN_SQR
25int 77int
26bn_sqr(BIGNUM *r, const BIGNUM *a, int rn, BN_CTX *ctx) 78bn_sqr(BIGNUM *r, const BIGNUM *a, int rn, BN_CTX *ctx)
@@ -30,3 +82,29 @@ bn_sqr(BIGNUM *r, const BIGNUM *a, int rn, BN_CTX *ctx)
30 return 1; 82 return 1;
31} 83}
32#endif 84#endif
85
86#ifdef HAVE_BN_SQR_COMBA4
87void
88bn_sqr_comba4(BN_ULONG *rd, const BN_ULONG *ad)
89{
90 /* XXX - consider using non-alt on CPUs that have the ADX extension. */
91 bignum_sqr_4_8_alt((uint64_t *)rd, (uint64_t *)ad);
92}
93#endif
94
95#ifdef HAVE_BN_SQR_COMBA8
96void
97bn_sqr_comba8(BN_ULONG *rd, const BN_ULONG *ad)
98{
99 /* XXX - consider using non-alt on CPUs that have the ADX extension. */
100 bignum_sqr_8_16_alt((uint64_t *)rd, (uint64_t *)ad);
101}
102#endif
103
104#ifdef HAVE_BN_SQR_WORDS
105void
106bn_sqr_words(BN_ULONG *rd, const BN_ULONG *ad, int num)
107{
108 bignum_sqr(num, (uint64_t *)rd, num, (uint64_t *)ad);
109}
110#endif