From: jsing Date: Wed, 15 Feb 2023 18:10:16 +0000 (+0000) Subject: Place bn_mul_add_words() after bn_mul_words(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=03b14b3bcf877387e8962084c8e96f4ced567c00;p=openbsd Place bn_mul_add_words() after bn_mul_words(). --- diff --git a/lib/libcrypto/bn/bn_mul.c b/lib/libcrypto/bn/bn_mul.c index 965c1ad0365..1d56e57b76b 100644 --- a/lib/libcrypto/bn/bn_mul.c +++ b/lib/libcrypto/bn/bn_mul.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_mul.c,v 1.32 2023/02/14 18:37:15 jsing Exp $ */ +/* $OpenBSD: bn_mul.c,v 1.33 2023/02/15 18:10:16 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -66,44 +66,6 @@ #include "bn_internal.h" #include "bn_local.h" -/* - * bn_mul_add_words() computes (carry:r[i]) = a[i] * w + r[i] + carry, where - * a is an array of words and w is a single word. This should really be called - * bn_mulw_add_words() since only one input is an array. This is used as a step - * in the multiplication of word arrays. - */ -#ifndef HAVE_BN_MUL_ADD_WORDS -BN_ULONG -bn_mul_add_words(BN_ULONG *r, const BN_ULONG *a, int num, BN_ULONG w) -{ - BN_ULONG carry = 0; - - assert(num >= 0); - if (num <= 0) - return 0; - -#ifndef OPENSSL_SMALL_FOOTPRINT - while (num & ~3) { - bn_mulw_addw_addw(a[0], w, r[0], carry, &carry, &r[0]); - bn_mulw_addw_addw(a[1], w, r[1], carry, &carry, &r[1]); - bn_mulw_addw_addw(a[2], w, r[2], carry, &carry, &r[2]); - bn_mulw_addw_addw(a[3], w, r[3], carry, &carry, &r[3]); - a += 4; - r += 4; - num -= 4; - } -#endif - while (num) { - bn_mulw_addw_addw(a[0], w, r[0], carry, &carry, &r[0]); - a++; - r++; - num--; - } - - return carry; -} -#endif - /* * bn_mul_comba4() computes r[] = a[] * b[] using Comba multiplication * (https://everything2.com/title/Comba+multiplication), where a and b are both @@ -269,6 +231,44 @@ bn_mul_words(BN_ULONG *r, const BN_ULONG *a, int num, BN_ULONG w) } #endif +/* + * bn_mul_add_words() computes (carry:r[i]) = a[i] * w + r[i] + carry, where + * a is an array of words and w is a single word. This should really be called + * bn_mulw_add_words() since only one input is an array. This is used as a step + * in the multiplication of word arrays. + */ +#ifndef HAVE_BN_MUL_ADD_WORDS +BN_ULONG +bn_mul_add_words(BN_ULONG *r, const BN_ULONG *a, int num, BN_ULONG w) +{ + BN_ULONG carry = 0; + + assert(num >= 0); + if (num <= 0) + return 0; + +#ifndef OPENSSL_SMALL_FOOTPRINT + while (num & ~3) { + bn_mulw_addw_addw(a[0], w, r[0], carry, &carry, &r[0]); + bn_mulw_addw_addw(a[1], w, r[1], carry, &carry, &r[1]); + bn_mulw_addw_addw(a[2], w, r[2], carry, &carry, &r[2]); + bn_mulw_addw_addw(a[3], w, r[3], carry, &carry, &r[3]); + a += 4; + r += 4; + num -= 4; + } +#endif + while (num) { + bn_mulw_addw_addw(a[0], w, r[0], carry, &carry, &r[0]); + a++; + r++; + num--; + } + + return carry; +} +#endif + #if defined(OPENSSL_NO_ASM) || !defined(OPENSSL_BN_ASM_PART_WORDS) /* * Here follows a specialised variant of bn_sub_words(), which has the property