index.js 43 KB

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