summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/bn_local.h20
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c43
2 files changed, 10 insertions, 53 deletions
diff --git a/src/lib/libcrypto/bn/bn_local.h b/src/lib/libcrypto/bn/bn_local.h
index 904eaa0f05..4ea54d2320 100644
--- a/src/lib/libcrypto/bn/bn_local.h
+++ b/src/lib/libcrypto/bn/bn_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_local.h,v 1.7 2023/02/03 04:47:59 jsing Exp $ */ 1/* $OpenBSD: bn_local.h,v 1.8 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 *
@@ -342,13 +342,6 @@ struct bn_gencb_st {
342 (c)= Hw(t); \ 342 (c)= Hw(t); \
343 } 343 }
344 344
345#define sqr(r0,r1,a) { \
346 BN_ULLONG t; \
347 t=(BN_ULLONG)(a)*(a); \
348 (r0)=Lw(t); \
349 (r1)=Hw(t); \
350 }
351
352#elif defined(BN_UMULT_LOHI) 345#elif defined(BN_UMULT_LOHI)
353#define mul_add(r,a,w,c) { \ 346#define mul_add(r,a,w,c) { \
354 BN_ULONG high,low,ret,tmp=(a); \ 347 BN_ULONG high,low,ret,tmp=(a); \
@@ -371,11 +364,6 @@ struct bn_gencb_st {
371 (r) = ret; \ 364 (r) = ret; \
372 } 365 }
373 366
374#define sqr(r0,r1,a) { \
375 BN_ULONG tmp=(a); \
376 BN_UMULT_LOHI(r0,r1,tmp,tmp); \
377 }
378
379#elif defined(BN_UMULT_HIGH) 367#elif defined(BN_UMULT_HIGH)
380#define mul_add(r,a,w,c) { \ 368#define mul_add(r,a,w,c) { \
381 BN_ULONG high,low,ret,tmp=(a); \ 369 BN_ULONG high,low,ret,tmp=(a); \
@@ -400,12 +388,6 @@ struct bn_gencb_st {
400 (r) = ret; \ 388 (r) = ret; \
401 } 389 }
402 390
403#define sqr(r0,r1,a) { \
404 BN_ULONG tmp=(a); \
405 (r0) = tmp * tmp; \
406 (r1) = BN_UMULT_HIGH(tmp,tmp); \
407 }
408
409#else 391#else
410/************************************************************* 392/*************************************************************
411 * No long long type 393 * No long long type
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