summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn
diff options
context:
space:
mode:
authorjsing <>2023-01-29 14:00:41 +0000
committerjsing <>2023-01-29 14:00:41 +0000
commit4e1fab63a267fba43456f4cf3909f8d17ca6aee7 (patch)
tree7e45e2611f536ee754d3ab8b0bc9d5c4e58f4593 /src/lib/libcrypto/bn
parentb0c52cade702e80c112f011dcb416a6b713592c2 (diff)
downloadopenbsd-4e1fab63a267fba43456f4cf3909f8d17ca6aee7.tar.gz
openbsd-4e1fab63a267fba43456f4cf3909f8d17ca6aee7.tar.bz2
openbsd-4e1fab63a267fba43456f4cf3909f8d17ca6aee7.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/lib/libcrypto/bn')
-rw-r--r--src/lib/libcrypto/bn/arch/amd64/bn_arch.c80
1 files changed, 79 insertions, 1 deletions
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