]> andersk Git - moira.git/blob - util/gdss/lib/crypto/bignum/c/bn/bnMult.c
initial import of gdss from the Athena source tree
[moira.git] / util / gdss / lib / crypto / bignum / c / bn / bnMult.c
1 /* Copyright     Digital Equipment Corporation & INRIA     1988, 1989 */
2 /* Last modified_on Fri Mar 30  4:13:47 GMT+2:00 1990 by shand */
3 /*      modified_on Mon Mar 26 18:09:25 GMT+2:00 1990 by herve */
4
5
6 /* bnMult.c: a piece of the bignum kernel written in C */
7
8
9                 /***************************************/
10
11 #define BNNMACROS_OFF
12 #include "BigNum.h"
13
14                         /*** copyright ***/
15
16 static char copyright[]="@(#)bnMult.c: copyright Digital Equipment Corporation & INRIA 1988, 1989, 1990\n";
17
18 BigNumCarry BnnMultiply (pp, pl, mm, ml, nn, nl)
19
20 register BigNum         pp, nn;
21          BigNum         mm;
22 register BigNumLength   pl, nl;
23          BigNumLength   ml;
24
25 /*
26  * Performs the product:
27  *    Q = P + M * N
28  *    BB = BBase(P)
29  *    Q mod BB => P
30  *    Q div BB => CarryOut
31  *
32  * Returns the CarryOut.  
33  *
34  * Assumes: 
35  *    Size(P) >= Size(M) + Size(N), 
36  *    Size(M) >= Size(N).
37  */
38
39 {
40    BigNumCarry c;
41
42    /* Multiply one digit at a time */
43
44    /* the following code give higher performance squaring.
45    ** Unfortunately for small nl, procedure call overheads kills it
46    */
47 #ifndef mips
48     /* Squaring code provoke a mips optimizer bug in V1.31 */
49    if (mm == nn && ml == nl && nl > 6)
50    {
51        register n_prev = 0;
52        /* special case of squaring */
53        for (c = 0; nl > 0; )
54        {
55            register BigNumDigit n = *nn;
56            c += BnnMultiplyDigit(pp, pl, nn, 1, n);
57            if (n_prev)
58                c += BnnAdd(pp, pl, nn, 1, 0);
59            nl--, nn++;
60            pp += 2, pl -= 2;
61            c += BnnMultiplyDigit(pp-1, pl+1, nn, nl, n+n+n_prev);
62            n_prev = ((long) n) < 0;
63        }
64    }
65    else
66 #endif /* mips */
67        for (c = 0; nl-- > 0; pp++, nn++, pl--)
68           c += BnnMultiplyDigit (pp, pl, mm, ml, *nn);
69
70    return c;
71 }
This page took 0.041609 seconds and 5 git commands to generate.