2 * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
5 * "Digital Equipment Corporation authorizes the reproduction,
6 * distribution and modification of this software subject to the following
9 * 1. Any partial or whole copy of this software, or any modification
10 * thereof, must include this copyright notice in its entirety.
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.
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.
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.
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"
34 /* BigN.h - Types and structures for clients of BigNum */
38 /******** representation of a bignum ******/
40 ** <--------------------------- nl ---------------------------->
42 ** |Significant| | | |Significant|
43 ** |BigNumDigit| | | |BigNumDigit|
44 ** |___________|___________|___________|___________|___________|
50 /* signals BigNum.h already included */
53 /*************** sizes ********************/
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)
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 */
65 /****** results of compare functions ******/
67 /* Note: we don't use "enum" to interface with Modula2+, Lisp, ... */
73 /*************** boolean ******************/
81 typedef short Boolean;
84 /* if DIGITon16BITS is defined, a single digit is on 16 bits */
85 /* otherwise (by default) a single digit is on 32 bits *****/
88 typedef unsigned short BigNumDigit;
90 typedef unsigned int BigNumDigit;
94 /* bignum types: digits, big numbers, carries ... */
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 */
105 /************ functions of bn.c ***********/
107 extern void BnnInit ();
108 extern void BnnClose ();
110 extern Boolean BnnIsZero ();
111 extern BigNumCarry BnnMultiply ();
112 extern void BnnDivide ();
113 extern BigNumCmp BnnCompare ();
116 /*********** functions of KerN.c **********/
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 ();
144 /* some functions can be written with macro-procedures */
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))