diff options
-rw-r--r-- | src/lib/libcrypto/bn/bn_mul.c | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c index 965c1ad036..1d56e57b76 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.32 2023/02/14 18:37:15 jsing Exp $ */ | 1 | /* $OpenBSD: bn_mul.c,v 1.33 2023/02/15 18:10:16 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 | * |
@@ -67,44 +67,6 @@ | |||
67 | #include "bn_local.h" | 67 | #include "bn_local.h" |
68 | 68 | ||
69 | /* | 69 | /* |
70 | * bn_mul_add_words() computes (carry:r[i]) = a[i] * w + r[i] + carry, where | ||
71 | * a is an array of words and w is a single word. This should really be called | ||
72 | * bn_mulw_add_words() since only one input is an array. This is used as a step | ||
73 | * in the multiplication of word arrays. | ||
74 | */ | ||
75 | #ifndef HAVE_BN_MUL_ADD_WORDS | ||
76 | BN_ULONG | ||
77 | bn_mul_add_words(BN_ULONG *r, const BN_ULONG *a, int num, BN_ULONG w) | ||
78 | { | ||
79 | BN_ULONG carry = 0; | ||
80 | |||
81 | assert(num >= 0); | ||
82 | if (num <= 0) | ||
83 | return 0; | ||
84 | |||
85 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
86 | while (num & ~3) { | ||
87 | bn_mulw_addw_addw(a[0], w, r[0], carry, &carry, &r[0]); | ||
88 | bn_mulw_addw_addw(a[1], w, r[1], carry, &carry, &r[1]); | ||
89 | bn_mulw_addw_addw(a[2], w, r[2], carry, &carry, &r[2]); | ||
90 | bn_mulw_addw_addw(a[3], w, r[3], carry, &carry, &r[3]); | ||
91 | a += 4; | ||
92 | r += 4; | ||
93 | num -= 4; | ||
94 | } | ||
95 | #endif | ||
96 | while (num) { | ||
97 | bn_mulw_addw_addw(a[0], w, r[0], carry, &carry, &r[0]); | ||
98 | a++; | ||
99 | r++; | ||
100 | num--; | ||
101 | } | ||
102 | |||
103 | return carry; | ||
104 | } | ||
105 | #endif | ||
106 | |||
107 | /* | ||
108 | * bn_mul_comba4() computes r[] = a[] * b[] using Comba multiplication | 70 | * bn_mul_comba4() computes r[] = a[] * b[] using Comba multiplication |
109 | * (https://everything2.com/title/Comba+multiplication), where a and b are both | 71 | * (https://everything2.com/title/Comba+multiplication), where a and b are both |
110 | * four word arrays, producing an eight word array result. | 72 | * four word arrays, producing an eight word array result. |
@@ -269,6 +231,44 @@ bn_mul_words(BN_ULONG *r, const BN_ULONG *a, int num, BN_ULONG w) | |||
269 | } | 231 | } |
270 | #endif | 232 | #endif |
271 | 233 | ||
234 | /* | ||
235 | * bn_mul_add_words() computes (carry:r[i]) = a[i] * w + r[i] + carry, where | ||
236 | * a is an array of words and w is a single word. This should really be called | ||
237 | * bn_mulw_add_words() since only one input is an array. This is used as a step | ||
238 | * in the multiplication of word arrays. | ||
239 | */ | ||
240 | #ifndef HAVE_BN_MUL_ADD_WORDS | ||
241 | BN_ULONG | ||
242 | bn_mul_add_words(BN_ULONG *r, const BN_ULONG *a, int num, BN_ULONG w) | ||
243 | { | ||
244 | BN_ULONG carry = 0; | ||
245 | |||
246 | assert(num >= 0); | ||
247 | if (num <= 0) | ||
248 | return 0; | ||
249 | |||
250 | #ifndef OPENSSL_SMALL_FOOTPRINT | ||
251 | while (num & ~3) { | ||
252 | bn_mulw_addw_addw(a[0], w, r[0], carry, &carry, &r[0]); | ||
253 | bn_mulw_addw_addw(a[1], w, r[1], carry, &carry, &r[1]); | ||
254 | bn_mulw_addw_addw(a[2], w, r[2], carry, &carry, &r[2]); | ||
255 | bn_mulw_addw_addw(a[3], w, r[3], carry, &carry, &r[3]); | ||
256 | a += 4; | ||
257 | r += 4; | ||
258 | num -= 4; | ||
259 | } | ||
260 | #endif | ||
261 | while (num) { | ||
262 | bn_mulw_addw_addw(a[0], w, r[0], carry, &carry, &r[0]); | ||
263 | a++; | ||
264 | r++; | ||
265 | num--; | ||
266 | } | ||
267 | |||
268 | return carry; | ||
269 | } | ||
270 | #endif | ||
271 | |||
272 | #if defined(OPENSSL_NO_ASM) || !defined(OPENSSL_BN_ASM_PART_WORDS) | 272 | #if defined(OPENSSL_NO_ASM) || !defined(OPENSSL_BN_ASM_PART_WORDS) |
273 | /* | 273 | /* |
274 | * Here follows a specialised variant of bn_sub_words(), which has the property | 274 | * Here follows a specialised variant of bn_sub_words(), which has the property |