source: trip-planner-front/node_modules/node-forge/lib/jsbn.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 34.4 KB
Line 
1// Copyright (c) 2005 Tom Wu
2// All Rights Reserved.
3// See "LICENSE" for details.
4
5// Basic JavaScript BN library - subset useful for RSA encryption.
6
7/*
8Licensing (LICENSE)
9-------------------
10
11This software is covered under the following copyright:
12*/
13/*
14 * Copyright (c) 2003-2005 Tom Wu
15 * All Rights Reserved.
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
30 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
31 *
32 * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
33 * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
34 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
35 * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
36 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37 *
38 * In addition, the following condition applies:
39 *
40 * All redistributions must retain an intact copy of this copyright notice
41 * and disclaimer.
42 */
43/*
44Address all questions regarding this license to:
45
46 Tom Wu
47 tjw@cs.Stanford.EDU
48*/
49var forge = require('./forge');
50
51module.exports = forge.jsbn = forge.jsbn || {};
52
53// Bits per digit
54var dbits;
55
56// JavaScript engine analysis
57var canary = 0xdeadbeefcafe;
58var j_lm = ((canary&0xffffff)==0xefcafe);
59
60// (public) Constructor
61function BigInteger(a,b,c) {
62 this.data = [];
63 if(a != null)
64 if("number" == typeof a) this.fromNumber(a,b,c);
65 else if(b == null && "string" != typeof a) this.fromString(a,256);
66 else this.fromString(a,b);
67}
68forge.jsbn.BigInteger = BigInteger;
69
70// return new, unset BigInteger
71function nbi() { return new BigInteger(null); }
72
73// am: Compute w_j += (x*this_i), propagate carries,
74// c is initial carry, returns final carry.
75// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
76// We need to select the fastest one that works in this environment.
77
78// am1: use a single mult and divide to get the high bits,
79// max digit bits should be 26 because
80// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
81function am1(i,x,w,j,c,n) {
82 while(--n >= 0) {
83 var v = x*this.data[i++]+w.data[j]+c;
84 c = Math.floor(v/0x4000000);
85 w.data[j++] = v&0x3ffffff;
86 }
87 return c;
88}
89// am2 avoids a big mult-and-extract completely.
90// Max digit bits should be <= 30 because we do bitwise ops
91// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
92function am2(i,x,w,j,c,n) {
93 var xl = x&0x7fff, xh = x>>15;
94 while(--n >= 0) {
95 var l = this.data[i]&0x7fff;
96 var h = this.data[i++]>>15;
97 var m = xh*l+h*xl;
98 l = xl*l+((m&0x7fff)<<15)+w.data[j]+(c&0x3fffffff);
99 c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
100 w.data[j++] = l&0x3fffffff;
101 }
102 return c;
103}
104// Alternately, set max digit bits to 28 since some
105// browsers slow down when dealing with 32-bit numbers.
106function am3(i,x,w,j,c,n) {
107 var xl = x&0x3fff, xh = x>>14;
108 while(--n >= 0) {
109 var l = this.data[i]&0x3fff;
110 var h = this.data[i++]>>14;
111 var m = xh*l+h*xl;
112 l = xl*l+((m&0x3fff)<<14)+w.data[j]+c;
113 c = (l>>28)+(m>>14)+xh*h;
114 w.data[j++] = l&0xfffffff;
115 }
116 return c;
117}
118
119// node.js (no browser)
120if(typeof(navigator) === 'undefined')
121{
122 BigInteger.prototype.am = am3;
123 dbits = 28;
124} else if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
125 BigInteger.prototype.am = am2;
126 dbits = 30;
127} else if(j_lm && (navigator.appName != "Netscape")) {
128 BigInteger.prototype.am = am1;
129 dbits = 26;
130} else { // Mozilla/Netscape seems to prefer am3
131 BigInteger.prototype.am = am3;
132 dbits = 28;
133}
134
135BigInteger.prototype.DB = dbits;
136BigInteger.prototype.DM = ((1<<dbits)-1);
137BigInteger.prototype.DV = (1<<dbits);
138
139var BI_FP = 52;
140BigInteger.prototype.FV = Math.pow(2,BI_FP);
141BigInteger.prototype.F1 = BI_FP-dbits;
142BigInteger.prototype.F2 = 2*dbits-BI_FP;
143
144// Digit conversions
145var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
146var BI_RC = new Array();
147var rr,vv;
148rr = "0".charCodeAt(0);
149for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
150rr = "a".charCodeAt(0);
151for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
152rr = "A".charCodeAt(0);
153for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
154
155function int2char(n) { return BI_RM.charAt(n); }
156function intAt(s,i) {
157 var c = BI_RC[s.charCodeAt(i)];
158 return (c==null)?-1:c;
159}
160
161// (protected) copy this to r
162function bnpCopyTo(r) {
163 for(var i = this.t-1; i >= 0; --i) r.data[i] = this.data[i];
164 r.t = this.t;
165 r.s = this.s;
166}
167
168// (protected) set from integer value x, -DV <= x < DV
169function bnpFromInt(x) {
170 this.t = 1;
171 this.s = (x<0)?-1:0;
172 if(x > 0) this.data[0] = x;
173 else if(x < -1) this.data[0] = x+this.DV;
174 else this.t = 0;
175}
176
177// return bigint initialized to value
178function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
179
180// (protected) set from string and radix
181function bnpFromString(s,b) {
182 var k;
183 if(b == 16) k = 4;
184 else if(b == 8) k = 3;
185 else if(b == 256) k = 8; // byte array
186 else if(b == 2) k = 1;
187 else if(b == 32) k = 5;
188 else if(b == 4) k = 2;
189 else { this.fromRadix(s,b); return; }
190 this.t = 0;
191 this.s = 0;
192 var i = s.length, mi = false, sh = 0;
193 while(--i >= 0) {
194 var x = (k==8)?s[i]&0xff:intAt(s,i);
195 if(x < 0) {
196 if(s.charAt(i) == "-") mi = true;
197 continue;
198 }
199 mi = false;
200 if(sh == 0)
201 this.data[this.t++] = x;
202 else if(sh+k > this.DB) {
203 this.data[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
204 this.data[this.t++] = (x>>(this.DB-sh));
205 } else
206 this.data[this.t-1] |= x<<sh;
207 sh += k;
208 if(sh >= this.DB) sh -= this.DB;
209 }
210 if(k == 8 && (s[0]&0x80) != 0) {
211 this.s = -1;
212 if(sh > 0) this.data[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
213 }
214 this.clamp();
215 if(mi) BigInteger.ZERO.subTo(this,this);
216}
217
218// (protected) clamp off excess high words
219function bnpClamp() {
220 var c = this.s&this.DM;
221 while(this.t > 0 && this.data[this.t-1] == c) --this.t;
222}
223
224// (public) return string representation in given radix
225function bnToString(b) {
226 if(this.s < 0) return "-"+this.negate().toString(b);
227 var k;
228 if(b == 16) k = 4;
229 else if(b == 8) k = 3;
230 else if(b == 2) k = 1;
231 else if(b == 32) k = 5;
232 else if(b == 4) k = 2;
233 else return this.toRadix(b);
234 var km = (1<<k)-1, d, m = false, r = "", i = this.t;
235 var p = this.DB-(i*this.DB)%k;
236 if(i-- > 0) {
237 if(p < this.DB && (d = this.data[i]>>p) > 0) { m = true; r = int2char(d); }
238 while(i >= 0) {
239 if(p < k) {
240 d = (this.data[i]&((1<<p)-1))<<(k-p);
241 d |= this.data[--i]>>(p+=this.DB-k);
242 } else {
243 d = (this.data[i]>>(p-=k))&km;
244 if(p <= 0) { p += this.DB; --i; }
245 }
246 if(d > 0) m = true;
247 if(m) r += int2char(d);
248 }
249 }
250 return m?r:"0";
251}
252
253// (public) -this
254function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
255
256// (public) |this|
257function bnAbs() { return (this.s<0)?this.negate():this; }
258
259// (public) return + if this > a, - if this < a, 0 if equal
260function bnCompareTo(a) {
261 var r = this.s-a.s;
262 if(r != 0) return r;
263 var i = this.t;
264 r = i-a.t;
265 if(r != 0) return (this.s<0)?-r:r;
266 while(--i >= 0) if((r=this.data[i]-a.data[i]) != 0) return r;
267 return 0;
268}
269
270// returns bit length of the integer x
271function nbits(x) {
272 var r = 1, t;
273 if((t=x>>>16) != 0) { x = t; r += 16; }
274 if((t=x>>8) != 0) { x = t; r += 8; }
275 if((t=x>>4) != 0) { x = t; r += 4; }
276 if((t=x>>2) != 0) { x = t; r += 2; }
277 if((t=x>>1) != 0) { x = t; r += 1; }
278 return r;
279}
280
281// (public) return the number of bits in "this"
282function bnBitLength() {
283 if(this.t <= 0) return 0;
284 return this.DB*(this.t-1)+nbits(this.data[this.t-1]^(this.s&this.DM));
285}
286
287// (protected) r = this << n*DB
288function bnpDLShiftTo(n,r) {
289 var i;
290 for(i = this.t-1; i >= 0; --i) r.data[i+n] = this.data[i];
291 for(i = n-1; i >= 0; --i) r.data[i] = 0;
292 r.t = this.t+n;
293 r.s = this.s;
294}
295
296// (protected) r = this >> n*DB
297function bnpDRShiftTo(n,r) {
298 for(var i = n; i < this.t; ++i) r.data[i-n] = this.data[i];
299 r.t = Math.max(this.t-n,0);
300 r.s = this.s;
301}
302
303// (protected) r = this << n
304function bnpLShiftTo(n,r) {
305 var bs = n%this.DB;
306 var cbs = this.DB-bs;
307 var bm = (1<<cbs)-1;
308 var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
309 for(i = this.t-1; i >= 0; --i) {
310 r.data[i+ds+1] = (this.data[i]>>cbs)|c;
311 c = (this.data[i]&bm)<<bs;
312 }
313 for(i = ds-1; i >= 0; --i) r.data[i] = 0;
314 r.data[ds] = c;
315 r.t = this.t+ds+1;
316 r.s = this.s;
317 r.clamp();
318}
319
320// (protected) r = this >> n
321function bnpRShiftTo(n,r) {
322 r.s = this.s;
323 var ds = Math.floor(n/this.DB);
324 if(ds >= this.t) { r.t = 0; return; }
325 var bs = n%this.DB;
326 var cbs = this.DB-bs;
327 var bm = (1<<bs)-1;
328 r.data[0] = this.data[ds]>>bs;
329 for(var i = ds+1; i < this.t; ++i) {
330 r.data[i-ds-1] |= (this.data[i]&bm)<<cbs;
331 r.data[i-ds] = this.data[i]>>bs;
332 }
333 if(bs > 0) r.data[this.t-ds-1] |= (this.s&bm)<<cbs;
334 r.t = this.t-ds;
335 r.clamp();
336}
337
338// (protected) r = this - a
339function bnpSubTo(a,r) {
340 var i = 0, c = 0, m = Math.min(a.t,this.t);
341 while(i < m) {
342 c += this.data[i]-a.data[i];
343 r.data[i++] = c&this.DM;
344 c >>= this.DB;
345 }
346 if(a.t < this.t) {
347 c -= a.s;
348 while(i < this.t) {
349 c += this.data[i];
350 r.data[i++] = c&this.DM;
351 c >>= this.DB;
352 }
353 c += this.s;
354 } else {
355 c += this.s;
356 while(i < a.t) {
357 c -= a.data[i];
358 r.data[i++] = c&this.DM;
359 c >>= this.DB;
360 }
361 c -= a.s;
362 }
363 r.s = (c<0)?-1:0;
364 if(c < -1) r.data[i++] = this.DV+c;
365 else if(c > 0) r.data[i++] = c;
366 r.t = i;
367 r.clamp();
368}
369
370// (protected) r = this * a, r != this,a (HAC 14.12)
371// "this" should be the larger one if appropriate.
372function bnpMultiplyTo(a,r) {
373 var x = this.abs(), y = a.abs();
374 var i = x.t;
375 r.t = i+y.t;
376 while(--i >= 0) r.data[i] = 0;
377 for(i = 0; i < y.t; ++i) r.data[i+x.t] = x.am(0,y.data[i],r,i,0,x.t);
378 r.s = 0;
379 r.clamp();
380 if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
381}
382
383// (protected) r = this^2, r != this (HAC 14.16)
384function bnpSquareTo(r) {
385 var x = this.abs();
386 var i = r.t = 2*x.t;
387 while(--i >= 0) r.data[i] = 0;
388 for(i = 0; i < x.t-1; ++i) {
389 var c = x.am(i,x.data[i],r,2*i,0,1);
390 if((r.data[i+x.t]+=x.am(i+1,2*x.data[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
391 r.data[i+x.t] -= x.DV;
392 r.data[i+x.t+1] = 1;
393 }
394 }
395 if(r.t > 0) r.data[r.t-1] += x.am(i,x.data[i],r,2*i,0,1);
396 r.s = 0;
397 r.clamp();
398}
399
400// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
401// r != q, this != m. q or r may be null.
402function bnpDivRemTo(m,q,r) {
403 var pm = m.abs();
404 if(pm.t <= 0) return;
405 var pt = this.abs();
406 if(pt.t < pm.t) {
407 if(q != null) q.fromInt(0);
408 if(r != null) this.copyTo(r);
409 return;
410 }
411 if(r == null) r = nbi();
412 var y = nbi(), ts = this.s, ms = m.s;
413 var nsh = this.DB-nbits(pm.data[pm.t-1]); // normalize modulus
414 if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } else { pm.copyTo(y); pt.copyTo(r); }
415 var ys = y.t;
416 var y0 = y.data[ys-1];
417 if(y0 == 0) return;
418 var yt = y0*(1<<this.F1)+((ys>1)?y.data[ys-2]>>this.F2:0);
419 var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
420 var i = r.t, j = i-ys, t = (q==null)?nbi():q;
421 y.dlShiftTo(j,t);
422 if(r.compareTo(t) >= 0) {
423 r.data[r.t++] = 1;
424 r.subTo(t,r);
425 }
426 BigInteger.ONE.dlShiftTo(ys,t);
427 t.subTo(y,y); // "negative" y so we can replace sub with am later
428 while(y.t < ys) y.data[y.t++] = 0;
429 while(--j >= 0) {
430 // Estimate quotient digit
431 var qd = (r.data[--i]==y0)?this.DM:Math.floor(r.data[i]*d1+(r.data[i-1]+e)*d2);
432 if((r.data[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
433 y.dlShiftTo(j,t);
434 r.subTo(t,r);
435 while(r.data[i] < --qd) r.subTo(t,r);
436 }
437 }
438 if(q != null) {
439 r.drShiftTo(ys,q);
440 if(ts != ms) BigInteger.ZERO.subTo(q,q);
441 }
442 r.t = ys;
443 r.clamp();
444 if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
445 if(ts < 0) BigInteger.ZERO.subTo(r,r);
446}
447
448// (public) this mod a
449function bnMod(a) {
450 var r = nbi();
451 this.abs().divRemTo(a,null,r);
452 if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
453 return r;
454}
455
456// Modular reduction using "classic" algorithm
457function Classic(m) { this.m = m; }
458function cConvert(x) {
459 if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
460 else return x;
461}
462function cRevert(x) { return x; }
463function cReduce(x) { x.divRemTo(this.m,null,x); }
464function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
465function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
466
467Classic.prototype.convert = cConvert;
468Classic.prototype.revert = cRevert;
469Classic.prototype.reduce = cReduce;
470Classic.prototype.mulTo = cMulTo;
471Classic.prototype.sqrTo = cSqrTo;
472
473// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
474// justification:
475// xy == 1 (mod m)
476// xy = 1+km
477// xy(2-xy) = (1+km)(1-km)
478// x[y(2-xy)] = 1-k^2m^2
479// x[y(2-xy)] == 1 (mod m^2)
480// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
481// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
482// JS multiply "overflows" differently from C/C++, so care is needed here.
483function bnpInvDigit() {
484 if(this.t < 1) return 0;
485 var x = this.data[0];
486 if((x&1) == 0) return 0;
487 var y = x&3; // y == 1/x mod 2^2
488 y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
489 y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
490 y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
491 // last step - calculate inverse mod DV directly;
492 // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
493 y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
494 // we really want the negative inverse, and -DV < y < DV
495 return (y>0)?this.DV-y:-y;
496}
497
498// Montgomery reduction
499function Montgomery(m) {
500 this.m = m;
501 this.mp = m.invDigit();
502 this.mpl = this.mp&0x7fff;
503 this.mph = this.mp>>15;
504 this.um = (1<<(m.DB-15))-1;
505 this.mt2 = 2*m.t;
506}
507
508// xR mod m
509function montConvert(x) {
510 var r = nbi();
511 x.abs().dlShiftTo(this.m.t,r);
512 r.divRemTo(this.m,null,r);
513 if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
514 return r;
515}
516
517// x/R mod m
518function montRevert(x) {
519 var r = nbi();
520 x.copyTo(r);
521 this.reduce(r);
522 return r;
523}
524
525// x = x/R mod m (HAC 14.32)
526function montReduce(x) {
527 while(x.t <= this.mt2) // pad x so am has enough room later
528 x.data[x.t++] = 0;
529 for(var i = 0; i < this.m.t; ++i) {
530 // faster way of calculating u0 = x.data[i]*mp mod DV
531 var j = x.data[i]&0x7fff;
532 var u0 = (j*this.mpl+(((j*this.mph+(x.data[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
533 // use am to combine the multiply-shift-add into one call
534 j = i+this.m.t;
535 x.data[j] += this.m.am(0,u0,x,i,0,this.m.t);
536 // propagate carry
537 while(x.data[j] >= x.DV) { x.data[j] -= x.DV; x.data[++j]++; }
538 }
539 x.clamp();
540 x.drShiftTo(this.m.t,x);
541 if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
542}
543
544// r = "x^2/R mod m"; x != r
545function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
546
547// r = "xy/R mod m"; x,y != r
548function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
549
550Montgomery.prototype.convert = montConvert;
551Montgomery.prototype.revert = montRevert;
552Montgomery.prototype.reduce = montReduce;
553Montgomery.prototype.mulTo = montMulTo;
554Montgomery.prototype.sqrTo = montSqrTo;
555
556// (protected) true iff this is even
557function bnpIsEven() { return ((this.t>0)?(this.data[0]&1):this.s) == 0; }
558
559// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
560function bnpExp(e,z) {
561 if(e > 0xffffffff || e < 1) return BigInteger.ONE;
562 var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
563 g.copyTo(r);
564 while(--i >= 0) {
565 z.sqrTo(r,r2);
566 if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
567 else { var t = r; r = r2; r2 = t; }
568 }
569 return z.revert(r);
570}
571
572// (public) this^e % m, 0 <= e < 2^32
573function bnModPowInt(e,m) {
574 var z;
575 if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
576 return this.exp(e,z);
577}
578
579// protected
580BigInteger.prototype.copyTo = bnpCopyTo;
581BigInteger.prototype.fromInt = bnpFromInt;
582BigInteger.prototype.fromString = bnpFromString;
583BigInteger.prototype.clamp = bnpClamp;
584BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
585BigInteger.prototype.drShiftTo = bnpDRShiftTo;
586BigInteger.prototype.lShiftTo = bnpLShiftTo;
587BigInteger.prototype.rShiftTo = bnpRShiftTo;
588BigInteger.prototype.subTo = bnpSubTo;
589BigInteger.prototype.multiplyTo = bnpMultiplyTo;
590BigInteger.prototype.squareTo = bnpSquareTo;
591BigInteger.prototype.divRemTo = bnpDivRemTo;
592BigInteger.prototype.invDigit = bnpInvDigit;
593BigInteger.prototype.isEven = bnpIsEven;
594BigInteger.prototype.exp = bnpExp;
595
596// public
597BigInteger.prototype.toString = bnToString;
598BigInteger.prototype.negate = bnNegate;
599BigInteger.prototype.abs = bnAbs;
600BigInteger.prototype.compareTo = bnCompareTo;
601BigInteger.prototype.bitLength = bnBitLength;
602BigInteger.prototype.mod = bnMod;
603BigInteger.prototype.modPowInt = bnModPowInt;
604
605// "constants"
606BigInteger.ZERO = nbv(0);
607BigInteger.ONE = nbv(1);
608
609// jsbn2 lib
610
611//Copyright (c) 2005-2009 Tom Wu
612//All Rights Reserved.
613//See "LICENSE" for details (See jsbn.js for LICENSE).
614
615//Extended JavaScript BN functions, required for RSA private ops.
616
617//Version 1.1: new BigInteger("0", 10) returns "proper" zero
618
619//(public)
620function bnClone() { var r = nbi(); this.copyTo(r); return r; }
621
622//(public) return value as integer
623function bnIntValue() {
624if(this.s < 0) {
625 if(this.t == 1) return this.data[0]-this.DV;
626 else if(this.t == 0) return -1;
627} else if(this.t == 1) return this.data[0];
628else if(this.t == 0) return 0;
629// assumes 16 < DB < 32
630return ((this.data[1]&((1<<(32-this.DB))-1))<<this.DB)|this.data[0];
631}
632
633//(public) return value as byte
634function bnByteValue() { return (this.t==0)?this.s:(this.data[0]<<24)>>24; }
635
636//(public) return value as short (assumes DB>=16)
637function bnShortValue() { return (this.t==0)?this.s:(this.data[0]<<16)>>16; }
638
639//(protected) return x s.t. r^x < DV
640function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); }
641
642//(public) 0 if this == 0, 1 if this > 0
643function bnSigNum() {
644if(this.s < 0) return -1;
645else if(this.t <= 0 || (this.t == 1 && this.data[0] <= 0)) return 0;
646else return 1;
647}
648
649//(protected) convert to radix string
650function bnpToRadix(b) {
651if(b == null) b = 10;
652if(this.signum() == 0 || b < 2 || b > 36) return "0";
653var cs = this.chunkSize(b);
654var a = Math.pow(b,cs);
655var d = nbv(a), y = nbi(), z = nbi(), r = "";
656this.divRemTo(d,y,z);
657while(y.signum() > 0) {
658 r = (a+z.intValue()).toString(b).substr(1) + r;
659 y.divRemTo(d,y,z);
660}
661return z.intValue().toString(b) + r;
662}
663
664//(protected) convert from radix string
665function bnpFromRadix(s,b) {
666this.fromInt(0);
667if(b == null) b = 10;
668var cs = this.chunkSize(b);
669var d = Math.pow(b,cs), mi = false, j = 0, w = 0;
670for(var i = 0; i < s.length; ++i) {
671 var x = intAt(s,i);
672 if(x < 0) {
673 if(s.charAt(i) == "-" && this.signum() == 0) mi = true;
674 continue;
675 }
676 w = b*w+x;
677 if(++j >= cs) {
678 this.dMultiply(d);
679 this.dAddOffset(w,0);
680 j = 0;
681 w = 0;
682 }
683}
684if(j > 0) {
685 this.dMultiply(Math.pow(b,j));
686 this.dAddOffset(w,0);
687}
688if(mi) BigInteger.ZERO.subTo(this,this);
689}
690
691//(protected) alternate constructor
692function bnpFromNumber(a,b,c) {
693if("number" == typeof b) {
694 // new BigInteger(int,int,RNG)
695 if(a < 2) this.fromInt(1);
696 else {
697 this.fromNumber(a,c);
698 if(!this.testBit(a-1)) // force MSB set
699 this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this);
700 if(this.isEven()) this.dAddOffset(1,0); // force odd
701 while(!this.isProbablePrime(b)) {
702 this.dAddOffset(2,0);
703 if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this);
704 }
705 }
706} else {
707 // new BigInteger(int,RNG)
708 var x = new Array(), t = a&7;
709 x.length = (a>>3)+1;
710 b.nextBytes(x);
711 if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0;
712 this.fromString(x,256);
713}
714}
715
716//(public) convert to bigendian byte array
717function bnToByteArray() {
718var i = this.t, r = new Array();
719r[0] = this.s;
720var p = this.DB-(i*this.DB)%8, d, k = 0;
721if(i-- > 0) {
722 if(p < this.DB && (d = this.data[i]>>p) != (this.s&this.DM)>>p)
723 r[k++] = d|(this.s<<(this.DB-p));
724 while(i >= 0) {
725 if(p < 8) {
726 d = (this.data[i]&((1<<p)-1))<<(8-p);
727 d |= this.data[--i]>>(p+=this.DB-8);
728 } else {
729 d = (this.data[i]>>(p-=8))&0xff;
730 if(p <= 0) { p += this.DB; --i; }
731 }
732 if((d&0x80) != 0) d |= -256;
733 if(k == 0 && (this.s&0x80) != (d&0x80)) ++k;
734 if(k > 0 || d != this.s) r[k++] = d;
735 }
736}
737return r;
738}
739
740function bnEquals(a) { return(this.compareTo(a)==0); }
741function bnMin(a) { return(this.compareTo(a)<0)?this:a; }
742function bnMax(a) { return(this.compareTo(a)>0)?this:a; }
743
744//(protected) r = this op a (bitwise)
745function bnpBitwiseTo(a,op,r) {
746var i, f, m = Math.min(a.t,this.t);
747for(i = 0; i < m; ++i) r.data[i] = op(this.data[i],a.data[i]);
748if(a.t < this.t) {
749 f = a.s&this.DM;
750 for(i = m; i < this.t; ++i) r.data[i] = op(this.data[i],f);
751 r.t = this.t;
752} else {
753 f = this.s&this.DM;
754 for(i = m; i < a.t; ++i) r.data[i] = op(f,a.data[i]);
755 r.t = a.t;
756}
757r.s = op(this.s,a.s);
758r.clamp();
759}
760
761//(public) this & a
762function op_and(x,y) { return x&y; }
763function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; }
764
765//(public) this | a
766function op_or(x,y) { return x|y; }
767function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; }
768
769//(public) this ^ a
770function op_xor(x,y) { return x^y; }
771function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; }
772
773//(public) this & ~a
774function op_andnot(x,y) { return x&~y; }
775function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; }
776
777//(public) ~this
778function bnNot() {
779var r = nbi();
780for(var i = 0; i < this.t; ++i) r.data[i] = this.DM&~this.data[i];
781r.t = this.t;
782r.s = ~this.s;
783return r;
784}
785
786//(public) this << n
787function bnShiftLeft(n) {
788var r = nbi();
789if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r);
790return r;
791}
792
793//(public) this >> n
794function bnShiftRight(n) {
795var r = nbi();
796if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r);
797return r;
798}
799
800//return index of lowest 1-bit in x, x < 2^31
801function lbit(x) {
802if(x == 0) return -1;
803var r = 0;
804if((x&0xffff) == 0) { x >>= 16; r += 16; }
805if((x&0xff) == 0) { x >>= 8; r += 8; }
806if((x&0xf) == 0) { x >>= 4; r += 4; }
807if((x&3) == 0) { x >>= 2; r += 2; }
808if((x&1) == 0) ++r;
809return r;
810}
811
812//(public) returns index of lowest 1-bit (or -1 if none)
813function bnGetLowestSetBit() {
814for(var i = 0; i < this.t; ++i)
815 if(this.data[i] != 0) return i*this.DB+lbit(this.data[i]);
816if(this.s < 0) return this.t*this.DB;
817return -1;
818}
819
820//return number of 1 bits in x
821function cbit(x) {
822var r = 0;
823while(x != 0) { x &= x-1; ++r; }
824return r;
825}
826
827//(public) return number of set bits
828function bnBitCount() {
829var r = 0, x = this.s&this.DM;
830for(var i = 0; i < this.t; ++i) r += cbit(this.data[i]^x);
831return r;
832}
833
834//(public) true iff nth bit is set
835function bnTestBit(n) {
836var j = Math.floor(n/this.DB);
837if(j >= this.t) return(this.s!=0);
838return((this.data[j]&(1<<(n%this.DB)))!=0);
839}
840
841//(protected) this op (1<<n)
842function bnpChangeBit(n,op) {
843var r = BigInteger.ONE.shiftLeft(n);
844this.bitwiseTo(r,op,r);
845return r;
846}
847
848//(public) this | (1<<n)
849function bnSetBit(n) { return this.changeBit(n,op_or); }
850
851//(public) this & ~(1<<n)
852function bnClearBit(n) { return this.changeBit(n,op_andnot); }
853
854//(public) this ^ (1<<n)
855function bnFlipBit(n) { return this.changeBit(n,op_xor); }
856
857//(protected) r = this + a
858function bnpAddTo(a,r) {
859var i = 0, c = 0, m = Math.min(a.t,this.t);
860while(i < m) {
861 c += this.data[i]+a.data[i];
862 r.data[i++] = c&this.DM;
863 c >>= this.DB;
864}
865if(a.t < this.t) {
866 c += a.s;
867 while(i < this.t) {
868 c += this.data[i];
869 r.data[i++] = c&this.DM;
870 c >>= this.DB;
871 }
872 c += this.s;
873} else {
874 c += this.s;
875 while(i < a.t) {
876 c += a.data[i];
877 r.data[i++] = c&this.DM;
878 c >>= this.DB;
879 }
880 c += a.s;
881}
882r.s = (c<0)?-1:0;
883if(c > 0) r.data[i++] = c;
884else if(c < -1) r.data[i++] = this.DV+c;
885r.t = i;
886r.clamp();
887}
888
889//(public) this + a
890function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; }
891
892//(public) this - a
893function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; }
894
895//(public) this * a
896function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; }
897
898//(public) this / a
899function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; }
900
901//(public) this % a
902function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; }
903
904//(public) [this/a,this%a]
905function bnDivideAndRemainder(a) {
906var q = nbi(), r = nbi();
907this.divRemTo(a,q,r);
908return new Array(q,r);
909}
910
911//(protected) this *= n, this >= 0, 1 < n < DV
912function bnpDMultiply(n) {
913this.data[this.t] = this.am(0,n-1,this,0,0,this.t);
914++this.t;
915this.clamp();
916}
917
918//(protected) this += n << w words, this >= 0
919function bnpDAddOffset(n,w) {
920if(n == 0) return;
921while(this.t <= w) this.data[this.t++] = 0;
922this.data[w] += n;
923while(this.data[w] >= this.DV) {
924 this.data[w] -= this.DV;
925 if(++w >= this.t) this.data[this.t++] = 0;
926 ++this.data[w];
927}
928}
929
930//A "null" reducer
931function NullExp() {}
932function nNop(x) { return x; }
933function nMulTo(x,y,r) { x.multiplyTo(y,r); }
934function nSqrTo(x,r) { x.squareTo(r); }
935
936NullExp.prototype.convert = nNop;
937NullExp.prototype.revert = nNop;
938NullExp.prototype.mulTo = nMulTo;
939NullExp.prototype.sqrTo = nSqrTo;
940
941//(public) this^e
942function bnPow(e) { return this.exp(e,new NullExp()); }
943
944//(protected) r = lower n words of "this * a", a.t <= n
945//"this" should be the larger one if appropriate.
946function bnpMultiplyLowerTo(a,n,r) {
947var i = Math.min(this.t+a.t,n);
948r.s = 0; // assumes a,this >= 0
949r.t = i;
950while(i > 0) r.data[--i] = 0;
951var j;
952for(j = r.t-this.t; i < j; ++i) r.data[i+this.t] = this.am(0,a.data[i],r,i,0,this.t);
953for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a.data[i],r,i,0,n-i);
954r.clamp();
955}
956
957//(protected) r = "this * a" without lower n words, n > 0
958//"this" should be the larger one if appropriate.
959function bnpMultiplyUpperTo(a,n,r) {
960--n;
961var i = r.t = this.t+a.t-n;
962r.s = 0; // assumes a,this >= 0
963while(--i >= 0) r.data[i] = 0;
964for(i = Math.max(n-this.t,0); i < a.t; ++i)
965 r.data[this.t+i-n] = this.am(n-i,a.data[i],r,0,0,this.t+i-n);
966r.clamp();
967r.drShiftTo(1,r);
968}
969
970//Barrett modular reduction
971function Barrett(m) {
972// setup Barrett
973this.r2 = nbi();
974this.q3 = nbi();
975BigInteger.ONE.dlShiftTo(2*m.t,this.r2);
976this.mu = this.r2.divide(m);
977this.m = m;
978}
979
980function barrettConvert(x) {
981if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m);
982else if(x.compareTo(this.m) < 0) return x;
983else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; }
984}
985
986function barrettRevert(x) { return x; }
987
988//x = x mod m (HAC 14.42)
989function barrettReduce(x) {
990x.drShiftTo(this.m.t-1,this.r2);
991if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); }
992this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);
993this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);
994while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1);
995x.subTo(this.r2,x);
996while(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
997}
998
999//r = x^2 mod m; x != r
1000function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
1001
1002//r = x*y mod m; x,y != r
1003function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
1004
1005Barrett.prototype.convert = barrettConvert;
1006Barrett.prototype.revert = barrettRevert;
1007Barrett.prototype.reduce = barrettReduce;
1008Barrett.prototype.mulTo = barrettMulTo;
1009Barrett.prototype.sqrTo = barrettSqrTo;
1010
1011//(public) this^e % m (HAC 14.85)
1012function bnModPow(e,m) {
1013var i = e.bitLength(), k, r = nbv(1), z;
1014if(i <= 0) return r;
1015else if(i < 18) k = 1;
1016else if(i < 48) k = 3;
1017else if(i < 144) k = 4;
1018else if(i < 768) k = 5;
1019else k = 6;
1020if(i < 8)
1021 z = new Classic(m);
1022else if(m.isEven())
1023 z = new Barrett(m);
1024else
1025 z = new Montgomery(m);
1026
1027// precomputation
1028var g = new Array(), n = 3, k1 = k-1, km = (1<<k)-1;
1029g[1] = z.convert(this);
1030if(k > 1) {
1031 var g2 = nbi();
1032 z.sqrTo(g[1],g2);
1033 while(n <= km) {
1034 g[n] = nbi();
1035 z.mulTo(g2,g[n-2],g[n]);
1036 n += 2;
1037 }
1038}
1039
1040var j = e.t-1, w, is1 = true, r2 = nbi(), t;
1041i = nbits(e.data[j])-1;
1042while(j >= 0) {
1043 if(i >= k1) w = (e.data[j]>>(i-k1))&km;
1044 else {
1045 w = (e.data[j]&((1<<(i+1))-1))<<(k1-i);
1046 if(j > 0) w |= e.data[j-1]>>(this.DB+i-k1);
1047 }
1048
1049 n = k;
1050 while((w&1) == 0) { w >>= 1; --n; }
1051 if((i -= n) < 0) { i += this.DB; --j; }
1052 if(is1) { // ret == 1, don't bother squaring or multiplying it
1053 g[w].copyTo(r);
1054 is1 = false;
1055 } else {
1056 while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; }
1057 if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; }
1058 z.mulTo(r2,g[w],r);
1059 }
1060
1061 while(j >= 0 && (e.data[j]&(1<<i)) == 0) {
1062 z.sqrTo(r,r2); t = r; r = r2; r2 = t;
1063 if(--i < 0) { i = this.DB-1; --j; }
1064 }
1065}
1066return z.revert(r);
1067}
1068
1069//(public) gcd(this,a) (HAC 14.54)
1070function bnGCD(a) {
1071var x = (this.s<0)?this.negate():this.clone();
1072var y = (a.s<0)?a.negate():a.clone();
1073if(x.compareTo(y) < 0) { var t = x; x = y; y = t; }
1074var i = x.getLowestSetBit(), g = y.getLowestSetBit();
1075if(g < 0) return x;
1076if(i < g) g = i;
1077if(g > 0) {
1078 x.rShiftTo(g,x);
1079 y.rShiftTo(g,y);
1080}
1081while(x.signum() > 0) {
1082 if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x);
1083 if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y);
1084 if(x.compareTo(y) >= 0) {
1085 x.subTo(y,x);
1086 x.rShiftTo(1,x);
1087 } else {
1088 y.subTo(x,y);
1089 y.rShiftTo(1,y);
1090 }
1091}
1092if(g > 0) y.lShiftTo(g,y);
1093return y;
1094}
1095
1096//(protected) this % n, n < 2^26
1097function bnpModInt(n) {
1098if(n <= 0) return 0;
1099var d = this.DV%n, r = (this.s<0)?n-1:0;
1100if(this.t > 0)
1101 if(d == 0) r = this.data[0]%n;
1102 else for(var i = this.t-1; i >= 0; --i) r = (d*r+this.data[i])%n;
1103return r;
1104}
1105
1106//(public) 1/this % m (HAC 14.61)
1107function bnModInverse(m) {
1108var ac = m.isEven();
1109if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO;
1110var u = m.clone(), v = this.clone();
1111var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
1112while(u.signum() != 0) {
1113 while(u.isEven()) {
1114 u.rShiftTo(1,u);
1115 if(ac) {
1116 if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); }
1117 a.rShiftTo(1,a);
1118 } else if(!b.isEven()) b.subTo(m,b);
1119 b.rShiftTo(1,b);
1120 }
1121 while(v.isEven()) {
1122 v.rShiftTo(1,v);
1123 if(ac) {
1124 if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); }
1125 c.rShiftTo(1,c);
1126 } else if(!d.isEven()) d.subTo(m,d);
1127 d.rShiftTo(1,d);
1128 }
1129 if(u.compareTo(v) >= 0) {
1130 u.subTo(v,u);
1131 if(ac) a.subTo(c,a);
1132 b.subTo(d,b);
1133 } else {
1134 v.subTo(u,v);
1135 if(ac) c.subTo(a,c);
1136 d.subTo(b,d);
1137 }
1138}
1139if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO;
1140if(d.compareTo(m) >= 0) return d.subtract(m);
1141if(d.signum() < 0) d.addTo(m,d); else return d;
1142if(d.signum() < 0) return d.add(m); else return d;
1143}
1144
1145var lowprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509];
1146var lplim = (1<<26)/lowprimes[lowprimes.length-1];
1147
1148//(public) test primality with certainty >= 1-.5^t
1149function bnIsProbablePrime(t) {
1150var i, x = this.abs();
1151if(x.t == 1 && x.data[0] <= lowprimes[lowprimes.length-1]) {
1152 for(i = 0; i < lowprimes.length; ++i)
1153 if(x.data[0] == lowprimes[i]) return true;
1154 return false;
1155}
1156if(x.isEven()) return false;
1157i = 1;
1158while(i < lowprimes.length) {
1159 var m = lowprimes[i], j = i+1;
1160 while(j < lowprimes.length && m < lplim) m *= lowprimes[j++];
1161 m = x.modInt(m);
1162 while(i < j) if(m%lowprimes[i++] == 0) return false;
1163}
1164return x.millerRabin(t);
1165}
1166
1167//(protected) true if probably prime (HAC 4.24, Miller-Rabin)
1168function bnpMillerRabin(t) {
1169var n1 = this.subtract(BigInteger.ONE);
1170var k = n1.getLowestSetBit();
1171if(k <= 0) return false;
1172var r = n1.shiftRight(k);
1173var prng = bnGetPrng();
1174var a;
1175for(var i = 0; i < t; ++i) {
1176 // select witness 'a' at random from between 1 and n1
1177 do {
1178 a = new BigInteger(this.bitLength(), prng);
1179 }
1180 while(a.compareTo(BigInteger.ONE) <= 0 || a.compareTo(n1) >= 0);
1181 var y = a.modPow(r,this);
1182 if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
1183 var j = 1;
1184 while(j++ < k && y.compareTo(n1) != 0) {
1185 y = y.modPowInt(2,this);
1186 if(y.compareTo(BigInteger.ONE) == 0) return false;
1187 }
1188 if(y.compareTo(n1) != 0) return false;
1189 }
1190}
1191return true;
1192}
1193
1194// get pseudo random number generator
1195function bnGetPrng() {
1196 // create prng with api that matches BigInteger secure random
1197 return {
1198 // x is an array to fill with bytes
1199 nextBytes: function(x) {
1200 for(var i = 0; i < x.length; ++i) {
1201 x[i] = Math.floor(Math.random() * 0x0100);
1202 }
1203 }
1204 };
1205}
1206
1207//protected
1208BigInteger.prototype.chunkSize = bnpChunkSize;
1209BigInteger.prototype.toRadix = bnpToRadix;
1210BigInteger.prototype.fromRadix = bnpFromRadix;
1211BigInteger.prototype.fromNumber = bnpFromNumber;
1212BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
1213BigInteger.prototype.changeBit = bnpChangeBit;
1214BigInteger.prototype.addTo = bnpAddTo;
1215BigInteger.prototype.dMultiply = bnpDMultiply;
1216BigInteger.prototype.dAddOffset = bnpDAddOffset;
1217BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
1218BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
1219BigInteger.prototype.modInt = bnpModInt;
1220BigInteger.prototype.millerRabin = bnpMillerRabin;
1221
1222//public
1223BigInteger.prototype.clone = bnClone;
1224BigInteger.prototype.intValue = bnIntValue;
1225BigInteger.prototype.byteValue = bnByteValue;
1226BigInteger.prototype.shortValue = bnShortValue;
1227BigInteger.prototype.signum = bnSigNum;
1228BigInteger.prototype.toByteArray = bnToByteArray;
1229BigInteger.prototype.equals = bnEquals;
1230BigInteger.prototype.min = bnMin;
1231BigInteger.prototype.max = bnMax;
1232BigInteger.prototype.and = bnAnd;
1233BigInteger.prototype.or = bnOr;
1234BigInteger.prototype.xor = bnXor;
1235BigInteger.prototype.andNot = bnAndNot;
1236BigInteger.prototype.not = bnNot;
1237BigInteger.prototype.shiftLeft = bnShiftLeft;
1238BigInteger.prototype.shiftRight = bnShiftRight;
1239BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
1240BigInteger.prototype.bitCount = bnBitCount;
1241BigInteger.prototype.testBit = bnTestBit;
1242BigInteger.prototype.setBit = bnSetBit;
1243BigInteger.prototype.clearBit = bnClearBit;
1244BigInteger.prototype.flipBit = bnFlipBit;
1245BigInteger.prototype.add = bnAdd;
1246BigInteger.prototype.subtract = bnSubtract;
1247BigInteger.prototype.multiply = bnMultiply;
1248BigInteger.prototype.divide = bnDivide;
1249BigInteger.prototype.remainder = bnRemainder;
1250BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
1251BigInteger.prototype.modPow = bnModPow;
1252BigInteger.prototype.modInverse = bnModInverse;
1253BigInteger.prototype.pow = bnPow;
1254BigInteger.prototype.gcd = bnGCD;
1255BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
1256
1257//BigInteger interfaces not implemented in jsbn:
1258
1259//BigInteger(int signum, byte[] magnitude)
1260//double doubleValue()
1261//float floatValue()
1262//int hashCode()
1263//long longValue()
1264//static BigInteger valueOf(long val)
Note: See TracBrowser for help on using the repository browser.