1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/freebl/mpi/mpi_hp.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/* This file contains routines that perform vector multiplication. */ 1.9 + 1.10 +#include "mpi-priv.h" 1.11 +#include <unistd.h> 1.12 + 1.13 +#include <stddef.h> 1.14 +/* #include <sys/systeminfo.h> */ 1.15 +#include <strings.h> 1.16 + 1.17 +extern void multacc512( 1.18 + int length, /* doublewords in multiplicand vector. */ 1.19 + const mp_digit *scalaraddr, /* Address of scalar. */ 1.20 + const mp_digit *multiplicand, /* The multiplicand vector. */ 1.21 + mp_digit * result); /* Where to accumulate the result. */ 1.22 + 1.23 +extern void maxpy_little( 1.24 + int length, /* doublewords in multiplicand vector. */ 1.25 + const mp_digit *scalaraddr, /* Address of scalar. */ 1.26 + const mp_digit *multiplicand, /* The multiplicand vector. */ 1.27 + mp_digit * result); /* Where to accumulate the result. */ 1.28 + 1.29 +extern void add_diag_little( 1.30 + int length, /* doublewords in input vector. */ 1.31 + const mp_digit *root, /* The vector to square. */ 1.32 + mp_digit * result); /* Where to accumulate the result. */ 1.33 + 1.34 +void 1.35 +s_mpv_sqr_add_prop(const mp_digit *pa, mp_size a_len, mp_digit *ps) 1.36 +{ 1.37 + add_diag_little(a_len, pa, ps); 1.38 +} 1.39 + 1.40 +#define MAX_STACK_DIGITS 258 1.41 +#define MULTACC512_LEN (512 / MP_DIGIT_BIT) 1.42 +#define HP_MPY_ADD_FN (a_len == MULTACC512_LEN ? multacc512 : maxpy_little) 1.43 + 1.44 +/* c = a * b */ 1.45 +void 1.46 +s_mpv_mul_d(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) 1.47 +{ 1.48 + mp_digit x[MAX_STACK_DIGITS]; 1.49 + mp_digit *px = x; 1.50 + size_t xSize = 0; 1.51 + 1.52 + if (a == c) { 1.53 + if (a_len > MAX_STACK_DIGITS) { 1.54 + xSize = sizeof(mp_digit) * (a_len + 2); 1.55 + px = malloc(xSize); 1.56 + if (!px) 1.57 + return; 1.58 + } 1.59 + memcpy(px, a, a_len * sizeof(*a)); 1.60 + a = px; 1.61 + } 1.62 + s_mp_setz(c, a_len + 1); 1.63 + HP_MPY_ADD_FN(a_len, &b, a, c); 1.64 + if (px != x && px) { 1.65 + memset(px, 0, xSize); 1.66 + free(px); 1.67 + } 1.68 +} 1.69 + 1.70 +/* c += a * b, where a is a_len words long. */ 1.71 +void 1.72 +s_mpv_mul_d_add(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) 1.73 +{ 1.74 + c[a_len] = 0; /* so carry propagation stops here. */ 1.75 + HP_MPY_ADD_FN(a_len, &b, a, c); 1.76 +} 1.77 + 1.78 +/* c += a * b, where a is y words long. */ 1.79 +void 1.80 +s_mpv_mul_d_add_prop(const mp_digit *a, mp_size a_len, mp_digit b, 1.81 + mp_digit *c) 1.82 +{ 1.83 + HP_MPY_ADD_FN(a_len, &b, a, c); 1.84 +} 1.85 +