tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

montmulf.h (3097B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /*  The functions that are to be called from outside of the .s file have the
      6 *  following interfaces and array size requirements:
      7 */
      8 
      9 void conv_i32_to_d32(double *d32, unsigned int *i32, int len);
     10 
     11 /*  Converts an array of int's to an array of doubles, so that each double
     12 *  corresponds to an int.  len is the number of items converted.
     13 *  Does not allocate the output array.
     14 *  The pointers d32 and i32 should point to arrays of size at least  len
     15 *  (doubles and unsigned ints, respectively)
     16 */
     17 
     18 void conv_i32_to_d16(double *d16, unsigned int *i32, int len);
     19 
     20 /*  Converts an array of int's to an array of doubles so that each element
     21 *  of the int array is converted to a pair of doubles, the first one
     22 *  corresponding to the lower (least significant) 16 bits of the int and
     23 *  the second one corresponding to the upper (most significant) 16 bits of
     24 *  the 32-bit int. len is the number of ints converted.
     25 *  Does not allocate the output array.
     26 *  The pointer d16 should point to an array of doubles of size at least
     27 *  2*len and i32 should point an array of ints of size at least  len
     28 */
     29 
     30 void conv_i32_to_d32_and_d16(double *d32, double *d16,
     31                             unsigned int *i32, int len);
     32 
     33 /*  Does the above two conversions together, it is much faster than doing
     34 *  both of those in succession
     35 */
     36 
     37 void mont_mulf_noconv(unsigned int *result,
     38                      double *dm1, double *dm2, double *dt,
     39                      double *dn, unsigned int *nint,
     40                      int nlen, double dn0);
     41 
     42 /*  Does the Montgomery multiplication of the numbers stored in the arrays
     43 *  pointed to by dm1 and dm2, writing the result to the array pointed to by
     44 *  result. It uses the array pointed to by dt as a temporary work area.
     45 *  nint should point to the modulus in the array-of-integers representation,
     46 *  dn should point to its array-of-doubles as obtained as a result of the
     47 *  function call   conv_i32_to_d32(dn, nint, nlen);
     48 *  nlen is the length of the array containing the modulus.
     49 *  The representation used for dm1 is the one that is a result of the function
     50 *  call   conv_i32_to_d32(dm1, m1, nlen), the representation for dm2 is the
     51 *  result of the function call   conv_i32_to_d16(dm2, m2, nlen).
     52 *  Note that m1 and m2 should both be of length nlen, so they should be
     53 *  padded with 0's if necessary before the conversion. The result comes in
     54 *  this form (int representation, padded with 0's).
     55 *  dn0 is the value of the 16 least significant bits of n0'.
     56 *  The function does not allocate memory for any of the arrays, so the
     57 *  pointers should point to arrays with the following minimal sizes:
     58 *  result - nlen+1
     59 *  dm1    - nlen
     60 *  dm2    - 2*nlen+1  ( the +1 is necessary for technical reasons )
     61 *  dt     - 4*nlen+2
     62 *  dn     - nlen
     63 *  nint   - nlen
     64 *  No two arrays should point to overlapping areas of memory.
     65 */