]> andersk Git - moira.git/blob - util/gdss/include/BigNum.h
initial import of gdss from the Athena source tree
[moira.git] / util / gdss / include / BigNum.h
1 /*
2  * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
3  * ALL RIGHTS RESERVED
4  *
5  * "Digital Equipment Corporation authorizes the reproduction,
6  * distribution and modification of this software subject to the following
7  * restrictions:
8  * 
9  * 1.  Any partial or whole copy of this software, or any modification
10  * thereof, must include this copyright notice in its entirety.
11  *
12  * 2.  This software is supplied "as is" with no warranty of any kind,
13  * expressed or implied, for any purpose, including any warranty of fitness 
14  * or merchantibility.  DIGITAL assumes no responsibility for the use or
15  * reliability of this software, nor promises to provide any form of 
16  * support for it on any basis.
17  *
18  * 3.  Distribution of this software is authorized only if no profit or
19  * remuneration of any kind is received in exchange for such distribution.
20  * 
21  * 4.  This software produces public key authentication certificates
22  * bearing an expiration date established by DIGITAL and RSA Data
23  * Security, Inc.  It may cease to generate certificates after the expiration
24  * date.  Any modification of this software that changes or defeats
25  * the expiration date or its effect is unauthorized.
26  * 
27  * 5.  Software that will renew or extend the expiration date of
28  * authentication certificates produced by this software may be obtained
29  * from RSA Data Security, Inc., 10 Twin Dolphin Drive, Redwood City, CA
30  * 94065, (415)595-8782, or from DIGITAL"
31  *
32  */
33
34 /* BigN.h - Types and structures for clients of BigNum */
35
36
37
38                 /******** representation of a bignum ******/
39 /*
40 **  <--------------------------- nl ---------------------------->
41 **  |   Least                                           Most    |
42 **  |Significant|           |           |           |Significant|
43 **  |BigNumDigit|           |           |           |BigNumDigit|
44 **  |___________|___________|___________|___________|___________|
45 **        ^                                          (sometimes
46 **        |                                            is zero)
47 **       nn
48 */
49
50 /* signals BigNum.h already included */
51 #define BIGNUM
52
53                 /*************** sizes ********************/
54
55 #define BN_BYTE_SIZE                    8
56 #define BN_WORD_SIZE                    (sizeof (int) * BN_BYTE_SIZE)
57 #define BN_DIGIT_SIZE                   (sizeof (BigNumDigit) * BN_BYTE_SIZE)
58
59 /* notes: */
60 /* BN_BYTE_SIZE: number of bits in a byte */
61 /* BN_WORD_SIZE: number of bits in an "int" in the target language */
62 /* BN_DIGIT_SIZE: number of bits in a digit of a BigNum */
63
64
65                 /****** results of compare functions ******/
66
67  /* Note: we don't use "enum" to interface with Modula2+, Lisp, ... */
68 #define BN_LT                           -1
69 #define BN_EQ                           0
70 #define BN_GT                           1
71
72
73                 /*************** boolean ******************/
74 #ifndef TRUE
75 #define         TRUE                    1
76 #endif
77 #ifndef FALSE
78 #define         FALSE                   0
79 #endif
80
81 typedef short                           Boolean;
82
83
84                 /* if DIGITon16BITS is defined, a single digit is on 16 bits */
85                 /* otherwise (by default) a single digit is on 32 bits *****/
86
87 #ifdef DIGITon16BITS
88 typedef unsigned short                  BigNumDigit;
89 #else
90 typedef unsigned int                    BigNumDigit;
91 #endif
92
93
94                 /* bignum types: digits, big numbers, carries ... */
95
96 typedef BigNumDigit *   BigNum;         /* A big number is a digit pointer */
97 typedef unsigned short  BigNumCarry;    /* Either 0 or 1 */
98 typedef unsigned long   BigNumProduct;  /* The product of two digits */
99 typedef unsigned long   BigNumLength;   /* The length of a bignum */
100 typedef short           BigNumCmp;      /* result of comparison */
101
102 /*\f*/
103
104
105                 /************ functions of bn.c ***********/
106
107 extern void             BnnInit                         ();
108 extern void             BnnClose                        ();
109
110 extern Boolean          BnnIsZero                       ();
111 extern BigNumCarry      BnnMultiply                     ();
112 extern void             BnnDivide                       ();
113 extern BigNumCmp        BnnCompare                      ();
114
115
116                 /*********** functions of KerN.c **********/
117
118 extern void             BnnSetToZero                    ();
119 extern void             BnnAssign                       ();
120 extern void             BnnSetDigit                     ();
121 extern BigNumDigit      BnnGetDigit                     ();
122 extern BigNumLength     BnnNumDigits                    ();
123 extern BigNumDigit      BnnNumLeadingZeroBitsInDigit    ();
124 extern Boolean          BnnDoesDigitFitInWord           ();
125 extern Boolean          BnnIsDigitZero                  ();
126 extern Boolean          BnnIsDigitNormalized            ();
127 extern Boolean          BnnIsDigitOdd                   ();
128 extern BigNumCmp                BnnCompareDigits                ();
129 extern void             BnnComplement                   ();
130 extern void             BnnAndDigits                    ();
131 extern void             BnnOrDigits                     ();
132 extern void             BnnXorDigits                    ();
133 extern BigNumDigit      BnnShiftLeft                    ();
134 extern BigNumDigit      BnnShiftRight                   ();
135 extern BigNumCarry      BnnAddCarry                     ();
136 extern BigNumCarry      BnnAdd                          ();
137 extern BigNumCarry      BnnSubtractBorrow               ();
138 extern BigNumCarry      BnnSubtract                     ();
139 extern BigNumCarry      BnnMultiplyDigit                ();
140 extern BigNumDigit      BnnDivideDigit                  ();
141
142 /*\f*/
143
144                 /* some functions can be written with macro-procedures */
145
146
147 #ifndef BNNMACROS_OFF
148 /* the functions BnnIsZero and BnnCompareDigits are not macro procedures
149 since they use parameters twice, and that can produce some bugs if
150 you pass a parameter like x++, the increment will be executed twice ! */
151 #define BnnSetToZero(nn,nl)             memset (nn, 0, (nl)*BN_DIGIT_SIZE/BN_BYTE_SIZE)
152 #define BnnSetDigit(nn,d)               (*(nn) = (d))
153 #define BnnGetDigit(nn)                 ((unsigned)(*(nn)))
154 #define BnnDoesDigitFitInWord(d)        (BN_DIGIT_SIZE > BN_WORD_SIZE ? ((d) >= 1 << BN_WORD_SIZE ? FALSE : TRUE) : TRUE)
155 #define BnnIsDigitZero(d)               ((d) == 0)
156 #define BnnIsDigitNormalized(d)         ((d) & (1 << (BN_DIGIT_SIZE - 1)) ? TRUE : FALSE)
157 #define BnnIsDigitOdd(d)                ((d) & 1 ? TRUE : FALSE)
158 #define BnnAndDigits(nn, d)             (*(nn) &= (d))
159 #define BnnOrDigits(nn, d)              (*(nn) |= (d))
160 #define BnnXorDigits(nn, d)             (*(nn) ^= (d))
161
162 #endif
163
164
This page took 0.064614 seconds and 5 git commands to generate.