]> andersk Git - moira.git/blob - util/gdss/lib/crypto/bignum/h/BigNum.h
initial import of gdss from the Athena source tree
[moira.git] / util / gdss / lib / crypto / bignum / h / BigNum.h
1 /* Copyright     Digital Equipment Corporation & INRIA     1988, 1989 */
2 /* Last modified_on Fri Aug 17 17:19:01 GMT+2:00 1990 by shand */
3 /*      modified_on Wed Jul  5 10:19:33 GMT+2:00 1989 by bertin */
4 /*      modified_on Fri Apr 28 20:03:23 GMT+2:00 1989 by herve */
5
6
7 /* BigN.h - Types and structures for clients of BigNum */
8
9
10
11                 /******** representation of a bignum ******/
12 /*
13 **  <--------------------------- nl ---------------------------->
14 **  |   Least                                           Most    |
15 **  |Significant|           |           |           |Significant|
16 **  |BigNumDigit|           |           |           |BigNumDigit|
17 **  |___________|___________|___________|___________|___________|
18 **        ^                                          (sometimes
19 **        |                                            is zero)
20 **       nn
21 */
22
23 /* signals BigNum.h already included */
24 #define BIGNUM
25
26                 /*************** sizes ********************/
27
28 #define BN_BYTE_SIZE                    8
29 #define BN_WORD_SIZE                    (sizeof (int) * BN_BYTE_SIZE)
30 #define BN_DIGIT_SIZE                   (sizeof (BigNumDigit) * BN_BYTE_SIZE)
31
32 /* notes: */
33 /* BN_BYTE_SIZE: number of bits in a byte */
34 /* BN_WORD_SIZE: number of bits in an "int" in the target language */
35 /* BN_DIGIT_SIZE: number of bits in a digit of a BigNum */
36
37
38                 /****** results of compare functions ******/
39
40  /* Note: we don't use "enum" to interface with Modula2+, Lisp, ... */
41 #define BN_LT                           -1
42 #define BN_EQ                           0
43 #define BN_GT                           1
44
45                 /*************** boolean ******************/
46
47 #define TRUE                            1
48 #define FALSE                           0
49
50
51                 /* if DIGITon16BITS is defined, a single digit is on 16 bits */
52                 /* otherwise (by default) a single digit is on 32 bits *****/
53                 /* Note: on 32 bit machine it makes little sense to mix */
54                 /* longs and short, so we define Boolean & BigNumCmp to be */
55                 /* int usually */
56
57 #ifdef DIGITon16BITS
58 typedef unsigned short                  BigNumDigit;
59 typedef short                           Boolean;
60 #else
61 typedef unsigned int                    BigNumDigit;
62 typedef int                             Boolean;
63 #endif
64
65
66                 /* bignum types: digits, big numbers, carries ... */
67
68 typedef BigNumDigit *   BigNum;         /* A big number is a digit pointer */
69 typedef BigNumDigit     BigNumCarry;    /* Either 0 or 1 */
70 typedef unsigned long   BigNumProduct;  /* The product of two digits */
71 typedef unsigned long   BigNumLength;   /* The length of a bignum */
72 #ifdef DIGITon16BITS
73 typedef short           BigNumCmp;      /* result of comparison */
74 #else
75 typedef int             BigNumCmp;      /* result of comparison */
76 #endif
77
78
79 /*\f*/
80
81
82                 /************ functions of bn.c ***********/
83
84 extern void             BnnInit                         ();
85 extern void             BnnClose                        ();
86
87 extern Boolean          BnnIsZero                       ();
88 extern BigNumCarry      BnnMultiply                     ();
89 extern void             BnnDivide                       ();
90 extern BigNumCmp        BnnCompare                      ();
91
92
93                 /*********** functions of KerN.c **********/
94
95 extern void             BnnSetToZero                    ();
96 extern void             BnnAssign                       ();
97 extern void             BnnSetDigit                     ();
98 extern BigNumDigit      BnnGetDigit                     ();
99 extern BigNumLength     BnnNumDigits                    ();
100 extern BigNumDigit      BnnNumLeadingZeroBitsInDigit    ();
101 extern Boolean          BnnDoesDigitFitInWord           ();
102 extern Boolean          BnnIsDigitZero                  ();
103 extern Boolean          BnnIsDigitNormalized            ();
104 extern Boolean          BnnIsDigitOdd                   ();
105 extern BigNumCmp                BnnCompareDigits                ();
106 extern void             BnnComplement                   ();
107 extern void             BnnAndDigits                    ();
108 extern void             BnnOrDigits                     ();
109 extern void             BnnXorDigits                    ();
110 extern BigNumDigit      BnnShiftLeft                    ();
111 extern BigNumDigit      BnnShiftRight                   ();
112 extern BigNumCarry      BnnAddCarry                     ();
113 extern BigNumCarry      BnnAdd                          ();
114 extern BigNumCarry      BnnSubtractBorrow               ();
115 extern BigNumCarry      BnnSubtract                     ();
116 extern BigNumCarry      BnnMultiplyDigit                ();
117 extern BigNumDigit      BnnDivideDigit                  ();
118
119 /*\f*/
120
121                 /* some functions can be written with macro-procedures */
122
123
124 #ifndef BNNMACROS_OFF
125 /* the functions BnnIsZero and BnnCompareDigits are not macro procedures
126 since they use parameters twice, and that can produce some bugs if
127 you pass a parameter like x++, the increment will be executed twice ! */
128 #define BnnSetDigit(nn,d)               (*(nn) = (d))
129 #define BnnGetDigit(nn)                 ((unsigned)(*(nn)))
130 #define BnnDoesDigitFitInWord(d)        (BN_DIGIT_SIZE > BN_WORD_SIZE ? ((d) >= 1 << BN_WORD_SIZE ? FALSE : TRUE) : TRUE)
131 #define BnnIsDigitZero(d)               ((d) == 0)
132 #define BnnIsDigitNormalized(d)         ((d) & (1 << (BN_DIGIT_SIZE - 1)) ? TRUE : FALSE)
133 #define BnnIsDigitOdd(d)                ((d) & 1 ? TRUE : FALSE)
134 #define BnnAndDigits(nn, d)             (*(nn) &= (d))
135 #define BnnOrDigits(nn, d)              (*(nn) |= (d))
136 #define BnnXorDigits(nn, d)             (*(nn) ^= (d))
137
138 #endif
139
140
This page took 0.048477 seconds and 5 git commands to generate.