summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2023-01-23 12:09:06 +0000
committerjsing <>2023-01-23 12:09:06 +0000
commit4da0d188e0e1d972397bcdd91fcf1bd43d78d844 (patch)
tree675028e3dc97f108d157c557689575c1e1e81682 /src
parent6dbbeae919d7043dba81294c451f76a1681ab6cc (diff)
downloadopenbsd-4da0d188e0e1d972397bcdd91fcf1bd43d78d844.tar.gz
openbsd-4da0d188e0e1d972397bcdd91fcf1bd43d78d844.tar.bz2
openbsd-4da0d188e0e1d972397bcdd91fcf1bd43d78d844.zip
Move bn_sqr_words from bn_asm.c to bn_sqr.c.
This is wrapped with #ifndef HAVE_BN_SQR_WORDS, which is then defined for architectures that provide their own assembly versions.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/arch/amd64/bn_arch.h3
-rw-r--r--src/lib/libcrypto/bn/arch/i386/bn_arch.h3
-rw-r--r--src/lib/libcrypto/bn/arch/mips64/bn_arch.h3
-rw-r--r--src/lib/libcrypto/bn/arch/powerpc/bn_arch.h3
-rw-r--r--src/lib/libcrypto/bn/arch/sparc/bn_arch.h3
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c54
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c59
7 files changed, 69 insertions, 59 deletions
diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h
index 2d11fbd7c2..e8c9986bb3 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.5 2023/01/23 12:02:48 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.6 2023/01/23 12:09: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 *
@@ -30,6 +30,7 @@
30#define HAVE_BN_SQR 30#define HAVE_BN_SQR
31#define HAVE_BN_SQR_COMBA4 31#define HAVE_BN_SQR_COMBA4
32#define HAVE_BN_SQR_COMBA8 32#define HAVE_BN_SQR_COMBA8
33#define HAVE_BN_SQR_WORDS
33 34
34#define HAVE_BN_SUB_WORDS 35#define HAVE_BN_SUB_WORDS
35 36
diff --git a/src/lib/libcrypto/bn/arch/i386/bn_arch.h b/src/lib/libcrypto/bn/arch/i386/bn_arch.h
index 18d7e519ec..eeb273583a 100644
--- a/src/lib/libcrypto/bn/arch/i386/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/i386/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.4 2023/01/23 12:02:48 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:09: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 *
@@ -29,6 +29,7 @@
29 29
30#define HAVE_BN_SQR_COMBA4 30#define HAVE_BN_SQR_COMBA4
31#define HAVE_BN_SQR_COMBA8 31#define HAVE_BN_SQR_COMBA8
32#define HAVE_BN_SQR_WORDS
32 33
33#define HAVE_BN_SUB_WORDS 34#define HAVE_BN_SUB_WORDS
34 35
diff --git a/src/lib/libcrypto/bn/arch/mips64/bn_arch.h b/src/lib/libcrypto/bn/arch/mips64/bn_arch.h
index f53c75472c..f7676611d7 100644
--- a/src/lib/libcrypto/bn/arch/mips64/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/mips64/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:02:48 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.6 2023/01/23 12:09: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 *
@@ -30,6 +30,7 @@
30 30
31#define HAVE_BN_SQR_COMBA4 31#define HAVE_BN_SQR_COMBA4
32#define HAVE_BN_SQR_COMBA8 32#define HAVE_BN_SQR_COMBA8
33#define HAVE_BN_SQR_WORDS
33 34
34#define HAVE_BN_SUB_WORDS 35#define HAVE_BN_SUB_WORDS
35 36
diff --git a/src/lib/libcrypto/bn/arch/powerpc/bn_arch.h b/src/lib/libcrypto/bn/arch/powerpc/bn_arch.h
index 18d7e519ec..eeb273583a 100644
--- a/src/lib/libcrypto/bn/arch/powerpc/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/powerpc/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.4 2023/01/23 12:02:48 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:09: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 *
@@ -29,6 +29,7 @@
29 29
30#define HAVE_BN_SQR_COMBA4 30#define HAVE_BN_SQR_COMBA4
31#define HAVE_BN_SQR_COMBA8 31#define HAVE_BN_SQR_COMBA8
32#define HAVE_BN_SQR_WORDS
32 33
33#define HAVE_BN_SUB_WORDS 34#define HAVE_BN_SUB_WORDS
34 35
diff --git a/src/lib/libcrypto/bn/arch/sparc/bn_arch.h b/src/lib/libcrypto/bn/arch/sparc/bn_arch.h
index 18d7e519ec..eeb273583a 100644
--- a/src/lib/libcrypto/bn/arch/sparc/bn_arch.h
+++ b/src/lib/libcrypto/bn/arch/sparc/bn_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_arch.h,v 1.4 2023/01/23 12:02:48 jsing Exp $ */ 1/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:09: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 *
@@ -29,6 +29,7 @@
29 29
30#define HAVE_BN_SQR_COMBA4 30#define HAVE_BN_SQR_COMBA4
31#define HAVE_BN_SQR_COMBA8 31#define HAVE_BN_SQR_COMBA8
32#define HAVE_BN_SQR_WORDS
32 33
33#define HAVE_BN_SUB_WORDS 34#define HAVE_BN_SUB_WORDS
34 35
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c
index a7f288fc1c..143c939367 100644
--- a/src/lib/libcrypto/bn/bn_asm.c
+++ b/src/lib/libcrypto/bn/bn_asm.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_asm.c,v 1.21 2023/01/23 12:02:48 jsing Exp $ */ 1/* $OpenBSD: bn_asm.c,v 1.22 2023/01/23 12:09:06 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 *
@@ -124,32 +124,6 @@ bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
124 return (c1); 124 return (c1);
125} 125}
126 126
127void
128bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
129{
130 assert(n >= 0);
131 if (n <= 0)
132 return;
133
134#ifndef OPENSSL_SMALL_FOOTPRINT
135 while (n & ~3) {
136 sqr(r[0], r[1], a[0]);
137 sqr(r[2], r[3], a[1]);
138 sqr(r[4], r[5], a[2]);
139 sqr(r[6], r[7], a[3]);
140 a += 4;
141 r += 8;
142 n -= 4;
143 }
144#endif
145 while (n) {
146 sqr(r[0], r[1], a[0]);
147 a++;
148 r += 2;
149 n--;
150 }
151}
152
153#else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ 127#else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
154 128
155BN_ULONG 129BN_ULONG
@@ -218,32 +192,6 @@ bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
218 return (carry); 192 return (carry);
219} 193}
220 194
221void
222bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
223{
224 assert(n >= 0);
225 if (n <= 0)
226 return;
227
228#ifndef OPENSSL_SMALL_FOOTPRINT
229 while (n & ~3) {
230 sqr64(r[0], r[1], a[0]);
231 sqr64(r[2], r[3], a[1]);
232 sqr64(r[4], r[5], a[2]);
233 sqr64(r[6], r[7], a[3]);
234 a += 4;
235 r += 8;
236 n -= 4;
237 }
238#endif
239 while (n) {
240 sqr64(r[0], r[1], a[0]);
241 a++;
242 r += 2;
243 n--;
244 }
245}
246
247#endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ 195#endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
248 196
249#if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT) 197#if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT)
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
index ff254764e3..74d5eded94 100644
--- a/src/lib/libcrypto/bn/bn_sqr.c
+++ b/src/lib/libcrypto/bn/bn_sqr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_sqr.c,v 1.21 2023/01/21 14:10:46 jsing Exp $ */ 1/* $OpenBSD: bn_sqr.c,v 1.22 2023/01/23 12:09:06 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 *
@@ -56,6 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <assert.h>
59#include <stdio.h> 60#include <stdio.h>
60#include <string.h> 61#include <string.h>
61 62
@@ -178,6 +179,62 @@ bn_sqr_comba8(BN_ULONG *r, const BN_ULONG *a)
178} 179}
179#endif 180#endif
180 181
182#ifndef HAVE_BN_SQR_WORDS
183#if defined(BN_LLONG) || defined(BN_UMULT_HIGH)
184void
185bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
186{
187 assert(n >= 0);
188 if (n <= 0)
189 return;
190
191#ifndef OPENSSL_SMALL_FOOTPRINT
192 while (n & ~3) {
193 sqr(r[0], r[1], a[0]);
194 sqr(r[2], r[3], a[1]);
195 sqr(r[4], r[5], a[2]);
196 sqr(r[6], r[7], a[3]);
197 a += 4;
198 r += 8;
199 n -= 4;
200 }
201#endif
202 while (n) {
203 sqr(r[0], r[1], a[0]);
204 a++;
205 r += 2;
206 n--;
207 }
208}
209#else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
210void
211bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
212{
213 assert(n >= 0);
214 if (n <= 0)
215 return;
216
217#ifndef OPENSSL_SMALL_FOOTPRINT
218 while (n & ~3) {
219 sqr64(r[0], r[1], a[0]);
220 sqr64(r[2], r[3], a[1]);
221 sqr64(r[4], r[5], a[2]);
222 sqr64(r[6], r[7], a[3]);
223 a += 4;
224 r += 8;
225 n -= 4;
226 }
227#endif
228 while (n) {
229 sqr64(r[0], r[1], a[0]);
230 a++;
231 r += 2;
232 n--;
233 }
234}
235#endif
236#endif
237
181/* tmp must have 2*n words */ 238/* tmp must have 2*n words */
182void 239void
183bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) 240bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)