summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_sqr.c
diff options
context:
space:
mode:
authorjsing <>2023-02-09 09:16:26 +0000
committerjsing <>2023-02-09 09:16:26 +0000
commit270a7fa5b0dcd84c8c8239f5abd043cfd7498ab6 (patch)
treeb8c6b193fe42cb99a80bb8f15b6b256747170588 /src/lib/libcrypto/bn/bn_sqr.c
parent8682251898e9d78e4b4fb68e97615ae3edc97fc4 (diff)
downloadopenbsd-270a7fa5b0dcd84c8c8239f5abd043cfd7498ab6.tar.gz
openbsd-270a7fa5b0dcd84c8c8239f5abd043cfd7498ab6.tar.bz2
openbsd-270a7fa5b0dcd84c8c8239f5abd043cfd7498ab6.zip
Clean up bn_sqr_words()
Currently there are two versions of bn_sqr_words(), which call the sqr or sqr64 macro. Replace this with a single version that calls bn_umul_hilo() and remove the various implementations of the sqr macro. The only slight downside is that sqr64 does three multiplications instead of four, given that the second and third terms are identical. However, this is a minimal gain for the amount of duplication and entanglement it introduces. ok tb@
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c43
1 files changed, 9 insertions, 34 deletions
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
index 74d5eded94..940cdd33bd 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.22 2023/01/23 12:09:06 jsing Exp $ */ 1/* $OpenBSD: bn_sqr.c,v 1.23 2023/02/09 09:16:26 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 *
@@ -180,33 +180,9 @@ bn_sqr_comba8(BN_ULONG *r, const BN_ULONG *a)
180#endif 180#endif
181 181
182#ifndef HAVE_BN_SQR_WORDS 182#ifndef HAVE_BN_SQR_WORDS
183#if defined(BN_LLONG) || defined(BN_UMULT_HIGH) 183/*
184void 184 * bn_sqr_words() computes (r[i*2+1]:r[i*2]) = a[i] * a[i].
185bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n) 185 */
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 186void
211bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n) 187bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
212{ 188{
@@ -216,24 +192,23 @@ bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
216 192
217#ifndef OPENSSL_SMALL_FOOTPRINT 193#ifndef OPENSSL_SMALL_FOOTPRINT
218 while (n & ~3) { 194 while (n & ~3) {
219 sqr64(r[0], r[1], a[0]); 195 bn_umul_hilo(a[0], a[0], &r[1], &r[0]);
220 sqr64(r[2], r[3], a[1]); 196 bn_umul_hilo(a[1], a[1], &r[3], &r[2]);
221 sqr64(r[4], r[5], a[2]); 197 bn_umul_hilo(a[2], a[2], &r[5], &r[4]);
222 sqr64(r[6], r[7], a[3]); 198 bn_umul_hilo(a[3], a[3], &r[7], &r[6]);
223 a += 4; 199 a += 4;
224 r += 8; 200 r += 8;
225 n -= 4; 201 n -= 4;
226 } 202 }
227#endif 203#endif
228 while (n) { 204 while (n) {
229 sqr64(r[0], r[1], a[0]); 205 bn_umul_hilo(a[0], a[0], &r[1], &r[0]);
230 a++; 206 a++;
231 r += 2; 207 r += 2;
232 n--; 208 n--;
233 } 209 }
234} 210}
235#endif 211#endif
236#endif
237 212
238/* tmp must have 2*n words */ 213/* tmp must have 2*n words */
239void 214void