]> andersk Git - moira.git/blob - util/gdss/lib/crypto/bignum/h/BntoBnn.h
initial import of gdss from the Athena source tree
[moira.git] / util / gdss / lib / crypto / bignum / h / BntoBnn.h
1 /* Copyright     Digital Equipment Corporation & INRIA     1988 */
2 /* Last modified_on Wed Feb 14 16:20:34 GMT+1:00 1990 by herve                */
3 /*      modified_on 17-OCT-1989 20:23:23.17 by Jim Lawton SDE/Galway          */
4
5 /* BntoBnn.h: allowing to use the new interfaces of KerN */
6
7
8 #ifndef VMS
9 extern char *malloc();
10 #endif
11
12
13                 /* old types of Bn */
14
15 typedef unsigned int    BigNumType;     /* A BigNum's type */
16
17 struct BigNumHeader                     /* The header of a BigNum */
18 {
19    BigNumType   type;
20    int          length;
21 };
22
23
24                 /* macros of old types of Bn */
25
26 #define BN_TYPE(n)      (((struct BigNumHeader *) n) - 1)->type
27 #define BN_LENGTH(n)    (((struct BigNumHeader *) n) - 1)->length
28
29
30                 /* macros of functions of Bn to functions Bnn */
31
32 #define BnIsZero(n, nd, nl)                             BnnIsZero ((n+nd), nl)
33 #define BnMultiply(p, pd, pl, m, md, ml, n, nd, nl)     BnnMultiply ((p+pd), pl, (m+md), ml, (n+nd), nl)
34 #define BnDivide(n, nd, nl, d, dd, dl)                  BnnDivide ((n+nd), nl, (d+dd), dl)
35 #define BnCompare(m, md, ml, n, nd, nl)                 BnnCompare ((m+md), ml, (n+nd), nl)
36 #define BnSetToZero(n, nd, nl)                          BnnSetToZero ((n+nd), nl) 
37 #define BnAssign(m, md, n, nd, nl)                      BnnAssign ((m+md), (n+nd), nl)
38 #define BnSetDigit(n, nd, d)                            BnnSetDigit ((n+nd), d) 
39 #define BnGetDigit(n, nd)                               BnnGetDigit ((n+nd))
40 #define BnNumDigits(n, nd, nl)                          BnnNumDigits ((n+nd), nl)
41 #define BnNumLeadingZeroBitsInDigit(n, nd)              BnnNumLeadingZeroBitsInDigit (*(n+nd))
42 #define BnDoesDigitFitInWord(n, nd)                     BnnDoesDigitFitInWord (*(n+nd))
43 #define BnIsDigitZero(n, nd)                            BnnIsDigitZero (*(n+nd))
44 #define BnIsDigitNormalized(n, nd)                      BnnIsDigitNormalized (*(n+nd))
45 #define BnIsDigitOdd(n, nd)                             BnnIsDigitOdd (*(n+nd))
46 #define BnCompareDigits(m, md, n, nd)                   BnnCompareDigits (*(m+md), *(n+nd))
47 #define BnComplement(n, nd, nl)                         BnnComplement ((n+nd), nl)
48 #define BnAndDigits(m, md, n, nd)                       BnnAndDigits ((m+md), *(n+nd))
49 #define BnOrDigits(m, md, n, nd)                        BnnOrDigits ((m+md), *(n+nd))
50 #define BnXorDigits(m, md, n, nd)                       BnnXorDigits ((m+md), *(n+nd))
51 #define BnShiftLeft(m, md, ml, n, nd, nbits)            *(n+nd) = BnnShiftLeft ((m+md), ml, nbits)
52 #define BnShiftRight(m, md, ml, n, nd, nbits)           *(n+nd) = BnnShiftRight ((m+md), ml, nbits)
53 #define BnAddCarry(n, nd, nl, carryin)                  BnnAddCarry ((n+nd), nl, carryin)
54 #define BnAdd(m, md, ml, n, nd, nl, carryin)            BnnAdd ((m+md), ml, (n+nd), nl, carryin)
55 #define BnSubtractBorrow(n, nd, nl, carryin)            BnnSubtractBorrow ((n+nd), nl, carryin)
56 #define BnSubtract(m, md, ml, n, nd, nl, carryin)       BnnSubtract ((m+md), ml, (n+nd), nl, carryin)
57 #define BnMultiplyDigit(p, pd, pl, m, md, ml, n, nd)    BnnMultiplyDigit ((p+pd), pl, (m+md), ml, *(n+nd))
58 #define BnDivideDigit(q, qd, r, rd, n, nd, nl, d, dd)   *(r+rd) = BnnDivideDigit ((q+qd), (n+nd), nl, *(d+dd))
59
60
61                 /* old functions of Bn */
62
63 /*
64  *      Creation and access to type and length fields.
65  */
66 extern char *malloc();
67 /* Allocates a BigNum structure and returns a pointer to it */
68 BigNum BnAlloc(size) int size; {
69         register BigNum n;
70  
71         n = (BigNum) (malloc(sizeof(struct BigNumHeader) +
72                                 size * sizeof(BigNumDigit))
73                         + sizeof(struct BigNumHeader));
74         BN_LENGTH(n) = size;
75         return(n);
76 }
77  
78 /* Allocates a BigNum, inserts its Type, and returns a pointer to it */
79 BigNum BnCreate(type, size) BigNumType type; int size; {
80         register BigNum n;
81  
82         n = BnAlloc(size);
83         BN_TYPE(n) = type;
84         BnSetToZero(n, 0, size);
85         return(n);
86 }
87  
88 /* Frees a BigNum structure */
89 BnFree(n) BigNum n; {
90         free(((struct BigNumHeader *) n) - 1);
91         return 1; 
92 }
93  
94 /* Returns the BigNum's Type */
95 BigNumType BnGetType(n) BigNum n; {
96         return(BN_TYPE(n));
97 }
98  
99 /* Sets the BigNum's Type */
100 BnSetType(n, type) BigNum n; BigNumType type; {
101         BN_TYPE(n) = type;
102 }
103  
104 /* Returns the number of digits allocated for the BigNum */
105 BnGetSize(n) BigNum n; {
106         return(BN_LENGTH(n));
107 }
108  
This page took 0.044544 seconds and 5 git commands to generate.