summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_mul.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_mul.c')
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c141
1 files changed, 140 insertions, 1 deletions
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
71BN_ULONG
72bn_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
103BN_ULONG
104bn_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
69void 140void
70bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) 141bn_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
290BN_ULONG
291bn_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
320BN_ULONG
321bn_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