diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/arch/amd64/bn_arch.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/i386/bn_arch.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/mips64/bn_arch.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/powerpc/bn_arch.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/sparc/bn_arch.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_asm.c | 133 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_mul.c | 141 |
7 files changed, 156 insertions, 138 deletions
diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h index e8c9986bb3..065f6b1c3b 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.6 2023/01/23 12:09:06 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.7 2023/01/23 12:17:57 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -24,8 +24,10 @@ | |||
24 | 24 | ||
25 | #define HAVE_BN_DIV_WORDS | 25 | #define HAVE_BN_DIV_WORDS |
26 | 26 | ||
27 | #define HAVE_BN_MUL_ADD_WORDS | ||
27 | #define HAVE_BN_MUL_COMBA4 | 28 | #define HAVE_BN_MUL_COMBA4 |
28 | #define HAVE_BN_MUL_COMBA8 | 29 | #define HAVE_BN_MUL_COMBA8 |
30 | #define HAVE_BN_MUL_WORDS | ||
29 | 31 | ||
30 | #define HAVE_BN_SQR | 32 | #define HAVE_BN_SQR |
31 | #define HAVE_BN_SQR_COMBA4 | 33 | #define HAVE_BN_SQR_COMBA4 |
diff --git a/src/lib/libcrypto/bn/arch/i386/bn_arch.h b/src/lib/libcrypto/bn/arch/i386/bn_arch.h index eeb273583a..681c2090a7 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.5 2023/01/23 12:09:06 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.6 2023/01/23 12:17:57 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -24,8 +24,10 @@ | |||
24 | 24 | ||
25 | #define HAVE_BN_DIV_WORDS | 25 | #define HAVE_BN_DIV_WORDS |
26 | 26 | ||
27 | #define HAVE_BN_MUL_ADD_WORDS | ||
27 | #define HAVE_BN_MUL_COMBA4 | 28 | #define HAVE_BN_MUL_COMBA4 |
28 | #define HAVE_BN_MUL_COMBA8 | 29 | #define HAVE_BN_MUL_COMBA8 |
30 | #define HAVE_BN_MUL_WORDS | ||
29 | 31 | ||
30 | #define HAVE_BN_SQR_COMBA4 | 32 | #define HAVE_BN_SQR_COMBA4 |
31 | #define HAVE_BN_SQR_COMBA8 | 33 | #define HAVE_BN_SQR_COMBA8 |
diff --git a/src/lib/libcrypto/bn/arch/mips64/bn_arch.h b/src/lib/libcrypto/bn/arch/mips64/bn_arch.h index f7676611d7..53771bce1e 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.6 2023/01/23 12:09:06 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.7 2023/01/23 12:17:58 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -25,8 +25,10 @@ | |||
25 | #define HAVE_BN_DIV_WORDS | 25 | #define HAVE_BN_DIV_WORDS |
26 | #define HAVE_BN_DIV_3_WORDS | 26 | #define HAVE_BN_DIV_3_WORDS |
27 | 27 | ||
28 | #define HAVE_BN_MUL_ADD_WORDS | ||
28 | #define HAVE_BN_MUL_COMBA4 | 29 | #define HAVE_BN_MUL_COMBA4 |
29 | #define HAVE_BN_MUL_COMBA8 | 30 | #define HAVE_BN_MUL_COMBA8 |
31 | #define HAVE_BN_MUL_WORDS | ||
30 | 32 | ||
31 | #define HAVE_BN_SQR_COMBA4 | 33 | #define HAVE_BN_SQR_COMBA4 |
32 | #define HAVE_BN_SQR_COMBA8 | 34 | #define HAVE_BN_SQR_COMBA8 |
diff --git a/src/lib/libcrypto/bn/arch/powerpc/bn_arch.h b/src/lib/libcrypto/bn/arch/powerpc/bn_arch.h index eeb273583a..46e932a2d5 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.5 2023/01/23 12:09:06 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.6 2023/01/23 12:17:58 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -24,8 +24,10 @@ | |||
24 | 24 | ||
25 | #define HAVE_BN_DIV_WORDS | 25 | #define HAVE_BN_DIV_WORDS |
26 | 26 | ||
27 | #define HAVE_BN_MUL_ADD_WORDS | ||
27 | #define HAVE_BN_MUL_COMBA4 | 28 | #define HAVE_BN_MUL_COMBA4 |
28 | #define HAVE_BN_MUL_COMBA8 | 29 | #define HAVE_BN_MUL_COMBA8 |
30 | #define HAVE_BN_MUL_WORDS | ||
29 | 31 | ||
30 | #define HAVE_BN_SQR_COMBA4 | 32 | #define HAVE_BN_SQR_COMBA4 |
31 | #define HAVE_BN_SQR_COMBA8 | 33 | #define HAVE_BN_SQR_COMBA8 |
diff --git a/src/lib/libcrypto/bn/arch/sparc/bn_arch.h b/src/lib/libcrypto/bn/arch/sparc/bn_arch.h index eeb273583a..46e932a2d5 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.5 2023/01/23 12:09:06 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.6 2023/01/23 12:17:58 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -24,8 +24,10 @@ | |||
24 | 24 | ||
25 | #define HAVE_BN_DIV_WORDS | 25 | #define HAVE_BN_DIV_WORDS |
26 | 26 | ||
27 | #define HAVE_BN_MUL_ADD_WORDS | ||
27 | #define HAVE_BN_MUL_COMBA4 | 28 | #define HAVE_BN_MUL_COMBA4 |
28 | #define HAVE_BN_MUL_COMBA8 | 29 | #define HAVE_BN_MUL_COMBA8 |
30 | #define HAVE_BN_MUL_WORDS | ||
29 | 31 | ||
30 | #define HAVE_BN_SQR_COMBA4 | 32 | #define HAVE_BN_SQR_COMBA4 |
31 | #define HAVE_BN_SQR_COMBA8 | 33 | #define HAVE_BN_SQR_COMBA8 |
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c index 143c939367..e2b584ee85 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.22 2023/01/23 12:09:06 jsing Exp $ */ | 1 | /* $OpenBSD: bn_asm.c,v 1.23 2023/01/23 12:17:57 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 | * |
@@ -63,137 +63,6 @@ | |||
63 | 63 | ||
64 | #include "bn_local.h" | 64 | #include "bn_local.h" |
65 | 65 | ||
66 | #if defined(BN_LLONG) || defined(BN_UMULT_HIGH) | ||
67 | |||
68 | BN_ULONG | ||
69 | bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) | ||
70 | { | ||
71 | BN_ULONG c1 = 0; | ||
72 | |||
73 | assert(num >= 0); | ||
74 | if (num <= 0) | ||
75 | return (c1); | ||
76 | |||
77 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
78 | while (num & ~3) { | ||
79 | mul_add(rp[0], ap[0], w, c1); | ||
80 | mul_add(rp[1], ap[1], w, c1); | ||
81 | mul_add(rp[2], ap[2], w, c1); | ||
82 | mul_add(rp[3], ap[3], w, c1); | ||
83 | ap += 4; | ||
84 | rp += 4; | ||
85 | num -= 4; | ||
86 | } | ||
87 | #endif | ||
88 | while (num) { | ||
89 | mul_add(rp[0], ap[0], w, c1); | ||
90 | ap++; | ||
91 | rp++; | ||
92 | num--; | ||
93 | } | ||
94 | |||
95 | return (c1); | ||
96 | } | ||
97 | |||
98 | BN_ULONG | ||
99 | bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) | ||
100 | { | ||
101 | BN_ULONG c1 = 0; | ||
102 | |||
103 | assert(num >= 0); | ||
104 | if (num <= 0) | ||
105 | return (c1); | ||
106 | |||
107 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
108 | while (num & ~3) { | ||
109 | mul(rp[0], ap[0], w, c1); | ||
110 | mul(rp[1], ap[1], w, c1); | ||
111 | mul(rp[2], ap[2], w, c1); | ||
112 | mul(rp[3], ap[3], w, c1); | ||
113 | ap += 4; | ||
114 | rp += 4; | ||
115 | num -= 4; | ||
116 | } | ||
117 | #endif | ||
118 | while (num) { | ||
119 | mul(rp[0], ap[0], w, c1); | ||
120 | ap++; | ||
121 | rp++; | ||
122 | num--; | ||
123 | } | ||
124 | return (c1); | ||
125 | } | ||
126 | |||
127 | #else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ | ||
128 | |||
129 | BN_ULONG | ||
130 | bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) | ||
131 | { | ||
132 | BN_ULONG c = 0; | ||
133 | BN_ULONG bl, bh; | ||
134 | |||
135 | assert(num >= 0); | ||
136 | if (num <= 0) | ||
137 | return ((BN_ULONG)0); | ||
138 | |||
139 | bl = LBITS(w); | ||
140 | bh = HBITS(w); | ||
141 | |||
142 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
143 | while (num & ~3) { | ||
144 | mul_add(rp[0], ap[0], bl, bh, c); | ||
145 | mul_add(rp[1], ap[1], bl, bh, c); | ||
146 | mul_add(rp[2], ap[2], bl, bh, c); | ||
147 | mul_add(rp[3], ap[3], bl, bh, c); | ||
148 | ap += 4; | ||
149 | rp += 4; | ||
150 | num -= 4; | ||
151 | } | ||
152 | #endif | ||
153 | while (num) { | ||
154 | mul_add(rp[0], ap[0], bl, bh, c); | ||
155 | ap++; | ||
156 | rp++; | ||
157 | num--; | ||
158 | } | ||
159 | return (c); | ||
160 | } | ||
161 | |||
162 | BN_ULONG | ||
163 | bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) | ||
164 | { | ||
165 | BN_ULONG carry = 0; | ||
166 | BN_ULONG bl, bh; | ||
167 | |||
168 | assert(num >= 0); | ||
169 | if (num <= 0) | ||
170 | return ((BN_ULONG)0); | ||
171 | |||
172 | bl = LBITS(w); | ||
173 | bh = HBITS(w); | ||
174 | |||
175 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
176 | while (num & ~3) { | ||
177 | mul(rp[0], ap[0], bl, bh, carry); | ||
178 | mul(rp[1], ap[1], bl, bh, carry); | ||
179 | mul(rp[2], ap[2], bl, bh, carry); | ||
180 | mul(rp[3], ap[3], bl, bh, carry); | ||
181 | ap += 4; | ||
182 | rp += 4; | ||
183 | num -= 4; | ||
184 | } | ||
185 | #endif | ||
186 | while (num) { | ||
187 | mul(rp[0], ap[0], bl, bh, carry); | ||
188 | ap++; | ||
189 | rp++; | ||
190 | num--; | ||
191 | } | ||
192 | return (carry); | ||
193 | } | ||
194 | |||
195 | #endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ | ||
196 | |||
197 | #if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT) | 66 | #if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT) |
198 | 67 | ||
199 | #ifdef OPENSSL_NO_ASM | 68 | #ifdef OPENSSL_NO_ASM |
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c index 3bf8ce6986..bd679108db 100644 --- a/src/lib/libcrypto/bn/bn_mul.c +++ b/src/lib/libcrypto/bn/bn_mul.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_mul.c,v 1.29 2023/01/21 15:40:13 jsing Exp $ */ | 1 | /* $OpenBSD: bn_mul.c,v 1.30 2023/01/23 12:17:57 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 | * |
@@ -65,6 +65,77 @@ | |||
65 | #include "bn_arch.h" | 65 | #include "bn_arch.h" |
66 | #include "bn_local.h" | 66 | #include "bn_local.h" |
67 | 67 | ||
68 | #ifndef HAVE_BN_MUL_ADD_WORDS | ||
69 | #if defined(BN_LLONG) || defined(BN_UMULT_HIGH) | ||
70 | |||
71 | BN_ULONG | ||
72 | bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) | ||
73 | { | ||
74 | BN_ULONG c1 = 0; | ||
75 | |||
76 | assert(num >= 0); | ||
77 | if (num <= 0) | ||
78 | return (c1); | ||
79 | |||
80 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
81 | while (num & ~3) { | ||
82 | mul_add(rp[0], ap[0], w, c1); | ||
83 | mul_add(rp[1], ap[1], w, c1); | ||
84 | mul_add(rp[2], ap[2], w, c1); | ||
85 | mul_add(rp[3], ap[3], w, c1); | ||
86 | ap += 4; | ||
87 | rp += 4; | ||
88 | num -= 4; | ||
89 | } | ||
90 | #endif | ||
91 | while (num) { | ||
92 | mul_add(rp[0], ap[0], w, c1); | ||
93 | ap++; | ||
94 | rp++; | ||
95 | num--; | ||
96 | } | ||
97 | |||
98 | return (c1); | ||
99 | } | ||
100 | |||
101 | #else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ | ||
102 | |||
103 | BN_ULONG | ||
104 | bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) | ||
105 | { | ||
106 | BN_ULONG c = 0; | ||
107 | BN_ULONG bl, bh; | ||
108 | |||
109 | assert(num >= 0); | ||
110 | if (num <= 0) | ||
111 | return ((BN_ULONG)0); | ||
112 | |||
113 | bl = LBITS(w); | ||
114 | bh = HBITS(w); | ||
115 | |||
116 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
117 | while (num & ~3) { | ||
118 | mul_add(rp[0], ap[0], bl, bh, c); | ||
119 | mul_add(rp[1], ap[1], bl, bh, c); | ||
120 | mul_add(rp[2], ap[2], bl, bh, c); | ||
121 | mul_add(rp[3], ap[3], bl, bh, c); | ||
122 | ap += 4; | ||
123 | rp += 4; | ||
124 | num -= 4; | ||
125 | } | ||
126 | #endif | ||
127 | while (num) { | ||
128 | mul_add(rp[0], ap[0], bl, bh, c); | ||
129 | ap++; | ||
130 | rp++; | ||
131 | num--; | ||
132 | } | ||
133 | return (c); | ||
134 | } | ||
135 | |||
136 | #endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ | ||
137 | #endif | ||
138 | |||
68 | #ifndef HAVE_BN_MUL_COMBA4 | 139 | #ifndef HAVE_BN_MUL_COMBA4 |
69 | void | 140 | void |
70 | bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | 141 | bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) |
@@ -213,6 +284,74 @@ bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | |||
213 | } | 284 | } |
214 | #endif | 285 | #endif |
215 | 286 | ||
287 | #ifndef HAVE_BN_MUL_WORDS | ||
288 | #if defined(BN_LLONG) || defined(BN_UMULT_HIGH) | ||
289 | |||
290 | BN_ULONG | ||
291 | bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) | ||
292 | { | ||
293 | BN_ULONG c1 = 0; | ||
294 | |||
295 | assert(num >= 0); | ||
296 | if (num <= 0) | ||
297 | return (c1); | ||
298 | |||
299 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
300 | while (num & ~3) { | ||
301 | mul(rp[0], ap[0], w, c1); | ||
302 | mul(rp[1], ap[1], w, c1); | ||
303 | mul(rp[2], ap[2], w, c1); | ||
304 | mul(rp[3], ap[3], w, c1); | ||
305 | ap += 4; | ||
306 | rp += 4; | ||
307 | num -= 4; | ||
308 | } | ||
309 | #endif | ||
310 | while (num) { | ||
311 | mul(rp[0], ap[0], w, c1); | ||
312 | ap++; | ||
313 | rp++; | ||
314 | num--; | ||
315 | } | ||
316 | return (c1); | ||
317 | } | ||
318 | #else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ | ||
319 | |||
320 | BN_ULONG | ||
321 | bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) | ||
322 | { | ||
323 | BN_ULONG carry = 0; | ||
324 | BN_ULONG bl, bh; | ||
325 | |||
326 | assert(num >= 0); | ||
327 | if (num <= 0) | ||
328 | return ((BN_ULONG)0); | ||
329 | |||
330 | bl = LBITS(w); | ||
331 | bh = HBITS(w); | ||
332 | |||
333 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
334 | while (num & ~3) { | ||
335 | mul(rp[0], ap[0], bl, bh, carry); | ||
336 | mul(rp[1], ap[1], bl, bh, carry); | ||
337 | mul(rp[2], ap[2], bl, bh, carry); | ||
338 | mul(rp[3], ap[3], bl, bh, carry); | ||
339 | ap += 4; | ||
340 | rp += 4; | ||
341 | num -= 4; | ||
342 | } | ||
343 | #endif | ||
344 | while (num) { | ||
345 | mul(rp[0], ap[0], bl, bh, carry); | ||
346 | ap++; | ||
347 | rp++; | ||
348 | num--; | ||
349 | } | ||
350 | return (carry); | ||
351 | } | ||
352 | #endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ | ||
353 | #endif | ||
354 | |||
216 | #if defined(OPENSSL_NO_ASM) || !defined(OPENSSL_BN_ASM_PART_WORDS) | 355 | #if defined(OPENSSL_NO_ASM) || !defined(OPENSSL_BN_ASM_PART_WORDS) |
217 | /* | 356 | /* |
218 | * Here follows a specialised variant of bn_sub_words(), which has the property | 357 | * Here follows a specialised variant of bn_sub_words(), which has the property |