1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export interface RandomGenerator {
|
7 | nextBytes(bytes: number[]): void;
|
8 | }
|
9 |
|
10 | export class BigInteger {
|
11 | constructor(a: number, c: RandomGenerator);
|
12 | constructor(a: number, b: number, c: RandomGenerator);
|
13 | constructor(a: string, b?: number);
|
14 | constructor(a: number[], b?: number);
|
15 | constructor(a: BigInteger);
|
16 |
|
17 | s: number;
|
18 | t: number;
|
19 | data: number[]; // forge specific
|
20 |
|
21 | DB: number;
|
22 | DM: number;
|
23 | DV: number;
|
24 |
|
25 | FV: number;
|
26 | F1: number;
|
27 | F2: number;
|
28 |
|
29 | // am: Compute w_j += (x*this_i), propagate carries,
|
30 | am(i: number, x: number, w: BigInteger, j: number, c: number, n: number): number;
|
31 |
|
32 | // (protected) copy this to r
|
33 | copyTo(r: BigInteger): void;
|
34 |
|
35 | // (protected) set from integer value x, -DV <= x < DV
|
36 | fromInt(x: number): void;
|
37 |
|
38 | // (protected) set from string and radix
|
39 | fromString(x: string, b: number): void;
|
40 |
|
41 | // (protected) clamp off excess high words
|
42 | clamp(): void;
|
43 |
|
44 | // (public) return string representation in given radix
|
45 | toString(b?: number): string;
|
46 |
|
47 | // (public) -this
|
48 | negate(): BigInteger;
|
49 |
|
50 | // (public) |this|
|
51 | abs(): BigInteger;
|
52 |
|
53 | // (public) return + if this > a, - if this < a, 0 if equal
|
54 | compareTo(a: BigInteger): number;
|
55 |
|
56 | // (public) return the number of bits in "this"
|
57 | bitLength(): number;
|
58 |
|
59 | // (protected) r = this << n*DB
|
60 | dlShiftTo(n: number, r: BigInteger): void;
|
61 |
|
62 | // (protected) r = this >> n*DB
|
63 | drShiftTo(n: number, r: BigInteger): void;
|
64 |
|
65 | // (protected) r = this << n
|
66 | lShiftTo(n: number, r: BigInteger): void;
|
67 |
|
68 | // (protected) r = this >> n
|
69 | rShiftTo(n: number, r: BigInteger): void;
|
70 |
|
71 | // (protected) r = this - a
|
72 | subTo(a: BigInteger, r: BigInteger): void;
|
73 |
|
74 | // (protected) r = this * a, r != this,a (HAC 14.12)
|
75 | multiplyTo(a: BigInteger, r: BigInteger): void;
|
76 |
|
77 | // (protected) r = this^2, r != this (HAC 14.16)
|
78 | squareTo(r: BigInteger): void;
|
79 |
|
80 | // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
81 | // r != q, this != m. q or r may be null.
|
82 | divRemTo(m: BigInteger, q: BigInteger, r: BigInteger): void;
|
83 |
|
84 | // (public) this mod a
|
85 | mod(a: BigInteger): BigInteger;
|
86 |
|
87 | // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
88 | invDigit(): number;
|
89 |
|
90 | // (protected) true iff this is even
|
91 | isEven(): boolean;
|
92 |
|
93 | // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
94 | exp(e: number, z: Reduction): BigInteger;
|
95 |
|
96 | // (public) this^e % m, 0 <= e < 2^32
|
97 | modPowInt(e: number, m: BigInteger): BigInteger;
|
98 |
|
99 | // (public)
|
100 | clone(): BigInteger;
|
101 |
|
102 | // (public) return value as integer
|
103 | intValue(): number;
|
104 |
|
105 | // (public) return value as byte
|
106 | byteValue(): number;
|
107 |
|
108 | // (public) return value as short (assumes DB>=16)
|
109 | shortValue(): number;
|
110 |
|
111 | // (protected) return x s.t. r^x < DV
|
112 | chunkSize(r: number): number;
|
113 |
|
114 | // (public) 0 if this == 0, 1 if this > 0
|
115 | signum(): number;
|
116 |
|
117 | // (protected) convert to radix string
|
118 | toRadix(b: number): string;
|
119 |
|
120 | // (protected) convert from radix string
|
121 | fromRadix(s: string, b: number): void;
|
122 |
|
123 | // (protected) alternate constructor
|
124 | fromNumber(a: number, b?: number, c?: number): void;
|
125 |
|
126 | // (public) convert to bigendian byte array
|
127 | toByteArray(): number[];
|
128 |
|
129 | equals(a: BigInteger): boolean;
|
130 |
|
131 | min(a: BigInteger): BigInteger;
|
132 |
|
133 | max(a: BigInteger): BigInteger;
|
134 |
|
135 | // (protected) r = this op a (bitwise)
|
136 | bitwiseTo(a: BigInteger, op: (x: number, y: number) => number, r: BigInteger): void;
|
137 |
|
138 | // (public) this & a
|
139 | and(a: BigInteger): BigInteger;
|
140 |
|
141 | // (public) this | a
|
142 | or(a: BigInteger): BigInteger;
|
143 |
|
144 | // (public) this ^ a
|
145 | xor(a: BigInteger): BigInteger;
|
146 |
|
147 | // (public) this & ~a
|
148 | andNot(a: BigInteger): BigInteger;
|
149 |
|
150 | // (public) ~this
|
151 | not(): BigInteger;
|
152 |
|
153 | // (public) this << n
|
154 | shiftLeft(n: number): BigInteger;
|
155 |
|
156 | // (public) this >> n
|
157 | shiftRight(n: number): BigInteger;
|
158 |
|
159 | // (public) returns index of lowest 1-bit (or -1 if none)
|
160 | getLowestSetBit(): number;
|
161 |
|
162 | // (public) return number of set bits
|
163 | bitCount(): number;
|
164 |
|
165 | // (public) true iff nth bit is set
|
166 | testBit(n: number): boolean;
|
167 |
|
168 | // (protected) this op (1<<n)
|
169 | changeBit(n: number, op: (x: number, y: number) => number): BigInteger;
|
170 |
|
171 | // (protected) this op (1<<n)
|
172 | setBit(n: number): BigInteger;
|
173 |
|
174 | // (public) this & ~(1<<n)
|
175 | clearBit(n: number): BigInteger
|
176 |
|
177 | // (public) this ^ (1<<n)
|
178 | flipBit(n: number): BigInteger
|
179 |
|
180 | // (protected) r = this + a
|
181 | addTo(a: BigInteger, r: BigInteger): void;
|
182 |
|
183 | // (public) this + a
|
184 | add(a: BigInteger): BigInteger;
|
185 |
|
186 | // (public) this - a
|
187 | subtract(a: BigInteger): BigInteger;
|
188 |
|
189 | // (public) this * a
|
190 | multiply(a: BigInteger): BigInteger;
|
191 |
|
192 | // (public) this^2
|
193 | square(): BigInteger;
|
194 |
|
195 | // (public) this / a
|
196 | divide(a: BigInteger): BigInteger;
|
197 |
|
198 | // (public) this % a
|
199 | remainder(a: BigInteger): BigInteger;
|
200 |
|
201 | // (public) [this/a,this%a]
|
202 | divideAndRemainder(a: BigInteger): BigInteger[]; // Array of 2 items
|
203 |
|
204 | // (protected) this *= n, this >= 0, 1 < n < DV
|
205 | dMultiply(n: number): void;
|
206 |
|
207 | // (protected) this += n << w words, this >= 0
|
208 | dAddOffset(n: number, w: number): void;
|
209 |
|
210 | // (public) this^e
|
211 | pow(e: number): BigInteger;
|
212 |
|
213 | // (protected) r = lower n words of "this * a", a.t <= n
|
214 | multiplyLowerTo(a: BigInteger, n: number, r: BigInteger): void;
|
215 |
|
216 | // (protected) r = "this * a" without lower n words, n > 0
|
217 | multiplyUpperTo(a: BigInteger, n: number, r: BigInteger): void;
|
218 |
|
219 | // (public) this^e % m (HAC 14.85)
|
220 | modPow(e: BigInteger, m: BigInteger): BigInteger;
|
221 |
|
222 | // (public) gcd(this,a) (HAC 14.54)
|
223 | gcd(a: BigInteger): BigInteger;
|
224 |
|
225 | // (protected) this % n, n < 2^26
|
226 | modInt(n: number): number;
|
227 |
|
228 | // (public) 1/this % m (HAC 14.61)
|
229 | modInverse(m: BigInteger): BigInteger;
|
230 |
|
231 | // (public) test primality with certainty >= 1-.5^t
|
232 | isProbablePrime(t: number): boolean;
|
233 |
|
234 | // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
|
235 | millerRabin(t: number): boolean;
|
236 |
|
237 | static ZERO: BigInteger;
|
238 | static ONE: BigInteger;
|
239 | }
|
240 |
|
241 | export interface Reduction {
|
242 | convert(x: BigInteger): BigInteger;
|
243 | revert(x: BigInteger): BigInteger;
|
244 | reduce(x: BigInteger): void;
|
245 | mulTo(x: BigInteger, y: BigInteger, r: BigInteger): void;
|
246 | sqrTo(x: BigInteger, r: BigInteger): void;
|
247 | }
|
248 |
|
249 | export as namespace jsbn;
|