UNPKG

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