diff options
| author | jsing <> | 2023-02-15 18:10:16 +0000 |
|---|---|---|
| committer | jsing <> | 2023-02-15 18:10:16 +0000 |
| commit | d5d57084c52a85f904031b46cae5e1c26448c38c (patch) | |
| tree | bfd94fdf507e2e5ca1301bdfc4e56ddfab856f63 /src | |
| parent | 6442c6e4fe83805c9e3e2cedef903f68c471b188 (diff) | |
| download | openbsd-d5d57084c52a85f904031b46cae5e1c26448c38c.tar.gz openbsd-d5d57084c52a85f904031b46cae5e1c26448c38c.tar.bz2 openbsd-d5d57084c52a85f904031b46cae5e1c26448c38c.zip | |
Place bn_mul_add_words() after bn_mul_words().
Diffstat (limited to 'src')
| -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 |
