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 */
5 /* BntoBnn.h: allowing to use the new interfaces of KerN */
15 typedef unsigned int BigNumType; /* A BigNum's type */
17 struct BigNumHeader /* The header of a BigNum */
24 /* macros of old types of Bn */
26 #define BN_TYPE(n) (((struct BigNumHeader *) n) - 1)->type
27 #define BN_LENGTH(n) (((struct BigNumHeader *) n) - 1)->length
30 /* macros of functions of Bn to functions Bnn */
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))
61 /* old functions of Bn */
64 * Creation and access to type and length fields.
66 extern char *malloc();
67 /* Allocates a BigNum structure and returns a pointer to it */
68 BigNum BnAlloc(size) int size; {
71 n = (BigNum) (malloc(sizeof(struct BigNumHeader) +
72 size * sizeof(BigNumDigit))
73 + sizeof(struct BigNumHeader));
78 /* Allocates a BigNum, inserts its Type, and returns a pointer to it */
79 BigNum BnCreate(type, size) BigNumType type; int size; {
84 BnSetToZero(n, 0, size);
88 /* Frees a BigNum structure */
90 free(((struct BigNumHeader *) n) - 1);
94 /* Returns the BigNum's Type */
95 BigNumType BnGetType(n) BigNum n; {
99 /* Sets the BigNum's Type */
100 BnSetType(n, type) BigNum n; BigNumType type; {
104 /* Returns the number of digits allocated for the BigNum */
105 BnGetSize(n) BigNum n; {
106 return(BN_LENGTH(n));