BigInteger.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.math.BigInteger"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.math.BigInteger"] = true;
  8. dojo.provide("dojox.math.BigInteger");
  9. dojo.getObject("math.BigInteger", true, dojox);
  10. dojo.experimental("dojox.math.BigInteger");
  11. // Contributed under CLA by Tom Wu <tjw@cs.Stanford.EDU>
  12. // See http://www-cs-students.stanford.edu/~tjw/jsbn/ for details.
  13. // Basic JavaScript BN library - subset useful for RSA encryption.
  14. // The API for dojox.math.BigInteger closely resembles that of the java.math.BigInteger class in Java.
  15. (function(){
  16. // Bits per digit
  17. var dbits;
  18. // JavaScript engine analysis
  19. var canary = 0xdeadbeefcafe;
  20. var j_lm = ((canary&0xffffff)==0xefcafe);
  21. // (public) Constructor
  22. function BigInteger(a,b,c) {
  23. if(a != null)
  24. if("number" == typeof a) this._fromNumber(a,b,c);
  25. else if(!b && "string" != typeof a) this._fromString(a,256);
  26. else this._fromString(a,b);
  27. }
  28. // return new, unset BigInteger
  29. function nbi() { return new BigInteger(null); }
  30. // am: Compute w_j += (x*this_i), propagate carries,
  31. // c is initial carry, returns final carry.
  32. // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
  33. // We need to select the fastest one that works in this environment.
  34. // am1: use a single mult and divide to get the high bits,
  35. // max digit bits should be 26 because
  36. // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
  37. function am1(i,x,w,j,c,n) {
  38. while(--n >= 0) {
  39. var v = x*this[i++]+w[j]+c;
  40. c = Math.floor(v/0x4000000);
  41. w[j++] = v&0x3ffffff;
  42. }
  43. return c;
  44. }
  45. // am2 avoids a big mult-and-extract completely.
  46. // Max digit bits should be <= 30 because we do bitwise ops
  47. // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
  48. function am2(i,x,w,j,c,n) {
  49. var xl = x&0x7fff, xh = x>>15;
  50. while(--n >= 0) {
  51. var l = this[i]&0x7fff;
  52. var h = this[i++]>>15;
  53. var m = xh*l+h*xl;
  54. l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
  55. c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
  56. w[j++] = l&0x3fffffff;
  57. }
  58. return c;
  59. }
  60. // Alternately, set max digit bits to 28 since some
  61. // browsers slow down when dealing with 32-bit numbers.
  62. function am3(i,x,w,j,c,n) {
  63. var xl = x&0x3fff, xh = x>>14;
  64. while(--n >= 0) {
  65. var l = this[i]&0x3fff;
  66. var h = this[i++]>>14;
  67. var m = xh*l+h*xl;
  68. l = xl*l+((m&0x3fff)<<14)+w[j]+c;
  69. c = (l>>28)+(m>>14)+xh*h;
  70. w[j++] = l&0xfffffff;
  71. }
  72. return c;
  73. }
  74. if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
  75. BigInteger.prototype.am = am2;
  76. dbits = 30;
  77. }
  78. else if(j_lm && (navigator.appName != "Netscape")) {
  79. BigInteger.prototype.am = am1;
  80. dbits = 26;
  81. }
  82. else { // Mozilla/Netscape seems to prefer am3
  83. BigInteger.prototype.am = am3;
  84. dbits = 28;
  85. }
  86. var BI_FP = 52;
  87. // Digit conversions
  88. var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
  89. var BI_RC = [];
  90. var rr,vv;
  91. rr = "0".charCodeAt(0);
  92. for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
  93. rr = "a".charCodeAt(0);
  94. for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
  95. rr = "A".charCodeAt(0);
  96. for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
  97. function int2char(n) { return BI_RM.charAt(n); }
  98. function intAt(s,i) {
  99. var c = BI_RC[s.charCodeAt(i)];
  100. return (c==null)?-1:c;
  101. }
  102. // (protected) copy this to r
  103. function bnpCopyTo(r) {
  104. for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
  105. r.t = this.t;
  106. r.s = this.s;
  107. }
  108. // (protected) set from integer value x, -DV <= x < DV
  109. function bnpFromInt(x) {
  110. this.t = 1;
  111. this.s = (x<0)?-1:0;
  112. if(x > 0) this[0] = x;
  113. else if(x < -1) this[0] = x+_DV;
  114. else this.t = 0;
  115. }
  116. // return bigint initialized to value
  117. function nbv(i) { var r = nbi(); r._fromInt(i); return r; }
  118. // (protected) set from string and radix
  119. function bnpFromString(s,b) {
  120. var k;
  121. if(b == 16) k = 4;
  122. else if(b == 8) k = 3;
  123. else if(b == 256) k = 8; // byte array
  124. else if(b == 2) k = 1;
  125. else if(b == 32) k = 5;
  126. else if(b == 4) k = 2;
  127. else { this.fromRadix(s,b); return; }
  128. this.t = 0;
  129. this.s = 0;
  130. var i = s.length, mi = false, sh = 0;
  131. while(--i >= 0) {
  132. var x = (k==8)?s[i]&0xff:intAt(s,i);
  133. if(x < 0) {
  134. if(s.charAt(i) == "-") mi = true;
  135. continue;
  136. }
  137. mi = false;
  138. if(sh == 0)
  139. this[this.t++] = x;
  140. else if(sh+k > this._DB) {
  141. this[this.t-1] |= (x&((1<<(this._DB-sh))-1))<<sh;
  142. this[this.t++] = (x>>(this._DB-sh));
  143. }
  144. else
  145. this[this.t-1] |= x<<sh;
  146. sh += k;
  147. if(sh >= this._DB) sh -= this._DB;
  148. }
  149. if(k == 8 && (s[0]&0x80) != 0) {
  150. this.s = -1;
  151. if(sh > 0) this[this.t-1] |= ((1<<(this._DB-sh))-1)<<sh;
  152. }
  153. this._clamp();
  154. if(mi) BigInteger.ZERO._subTo(this,this);
  155. }
  156. // (protected) clamp off excess high words
  157. function bnpClamp() {
  158. var c = this.s&this._DM;
  159. while(this.t > 0 && this[this.t-1] == c) --this.t;
  160. }
  161. // (public) return string representation in given radix
  162. function bnToString(b) {
  163. if(this.s < 0) return "-"+this.negate().toString(b);
  164. var k;
  165. if(b == 16) k = 4;
  166. else if(b == 8) k = 3;
  167. else if(b == 2) k = 1;
  168. else if(b == 32) k = 5;
  169. else if(b == 4) k = 2;
  170. else return this._toRadix(b);
  171. var km = (1<<k)-1, d, m = false, r = "", i = this.t;
  172. var p = this._DB-(i*this._DB)%k;
  173. if(i-- > 0) {
  174. if(p < this._DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
  175. while(i >= 0) {
  176. if(p < k) {
  177. d = (this[i]&((1<<p)-1))<<(k-p);
  178. d |= this[--i]>>(p+=this._DB-k);
  179. }
  180. else {
  181. d = (this[i]>>(p-=k))&km;
  182. if(p <= 0) { p += this._DB; --i; }
  183. }
  184. if(d > 0) m = true;
  185. if(m) r += int2char(d);
  186. }
  187. }
  188. return m?r:"0";
  189. }
  190. // (public) -this
  191. function bnNegate() { var r = nbi(); BigInteger.ZERO._subTo(this,r); return r; }
  192. // (public) |this|
  193. function bnAbs() { return (this.s<0)?this.negate():this; }
  194. // (public) return + if this > a, - if this < a, 0 if equal
  195. function bnCompareTo(a) {
  196. var r = this.s-a.s;
  197. if(r) return r;
  198. var i = this.t;
  199. r = i-a.t;
  200. if(r) return r;
  201. while(--i >= 0) if((r = this[i] - a[i])) return r;
  202. return 0;
  203. }
  204. // returns bit length of the integer x
  205. function nbits(x) {
  206. var r = 1, t;
  207. if((t=x>>>16)) { x = t; r += 16; }
  208. if((t=x>>8)) { x = t; r += 8; }
  209. if((t=x>>4)) { x = t; r += 4; }
  210. if((t=x>>2)) { x = t; r += 2; }
  211. if((t=x>>1)) { x = t; r += 1; }
  212. return r;
  213. }
  214. // (public) return the number of bits in "this"
  215. function bnBitLength() {
  216. if(this.t <= 0) return 0;
  217. return this._DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this._DM));
  218. }
  219. // (protected) r = this << n*DB
  220. function bnpDLShiftTo(n,r) {
  221. var i;
  222. for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
  223. for(i = n-1; i >= 0; --i) r[i] = 0;
  224. r.t = this.t+n;
  225. r.s = this.s;
  226. }
  227. // (protected) r = this >> n*DB
  228. function bnpDRShiftTo(n,r) {
  229. for(var i = n; i < this.t; ++i) r[i-n] = this[i];
  230. r.t = Math.max(this.t-n,0);
  231. r.s = this.s;
  232. }
  233. // (protected) r = this << n
  234. function bnpLShiftTo(n,r) {
  235. var bs = n%this._DB;
  236. var cbs = this._DB-bs;
  237. var bm = (1<<cbs)-1;
  238. var ds = Math.floor(n/this._DB), c = (this.s<<bs)&this._DM, i;
  239. for(i = this.t-1; i >= 0; --i) {
  240. r[i+ds+1] = (this[i]>>cbs)|c;
  241. c = (this[i]&bm)<<bs;
  242. }
  243. for(i = ds-1; i >= 0; --i) r[i] = 0;
  244. r[ds] = c;
  245. r.t = this.t+ds+1;
  246. r.s = this.s;
  247. r._clamp();
  248. }
  249. // (protected) r = this >> n
  250. function bnpRShiftTo(n,r) {
  251. r.s = this.s;
  252. var ds = Math.floor(n/this._DB);
  253. if(ds >= this.t) { r.t = 0; return; }
  254. var bs = n%this._DB;
  255. var cbs = this._DB-bs;
  256. var bm = (1<<bs)-1;
  257. r[0] = this[ds]>>bs;
  258. for(var i = ds+1; i < this.t; ++i) {
  259. r[i-ds-1] |= (this[i]&bm)<<cbs;
  260. r[i-ds] = this[i]>>bs;
  261. }
  262. if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
  263. r.t = this.t-ds;
  264. r._clamp();
  265. }
  266. // (protected) r = this - a
  267. function bnpSubTo(a,r) {
  268. var i = 0, c = 0, m = Math.min(a.t,this.t);
  269. while(i < m) {
  270. c += this[i]-a[i];
  271. r[i++] = c&this._DM;
  272. c >>= this._DB;
  273. }
  274. if(a.t < this.t) {
  275. c -= a.s;
  276. while(i < this.t) {
  277. c += this[i];
  278. r[i++] = c&this._DM;
  279. c >>= this._DB;
  280. }
  281. c += this.s;
  282. }
  283. else {
  284. c += this.s;
  285. while(i < a.t) {
  286. c -= a[i];
  287. r[i++] = c&this._DM;
  288. c >>= this._DB;
  289. }
  290. c -= a.s;
  291. }
  292. r.s = (c<0)?-1:0;
  293. if(c < -1) r[i++] = this._DV+c;
  294. else if(c > 0) r[i++] = c;
  295. r.t = i;
  296. r._clamp();
  297. }
  298. // (protected) r = this * a, r != this,a (HAC 14.12)
  299. // "this" should be the larger one if appropriate.
  300. function bnpMultiplyTo(a,r) {
  301. var x = this.abs(), y = a.abs();
  302. var i = x.t;
  303. r.t = i+y.t;
  304. while(--i >= 0) r[i] = 0;
  305. for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
  306. r.s = 0;
  307. r._clamp();
  308. if(this.s != a.s) BigInteger.ZERO._subTo(r,r);
  309. }
  310. // (protected) r = this^2, r != this (HAC 14.16)
  311. function bnpSquareTo(r) {
  312. var x = this.abs();
  313. var i = r.t = 2*x.t;
  314. while(--i >= 0) r[i] = 0;
  315. for(i = 0; i < x.t-1; ++i) {
  316. var c = x.am(i,x[i],r,2*i,0,1);
  317. if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x._DV) {
  318. r[i+x.t] -= x._DV;
  319. r[i+x.t+1] = 1;
  320. }
  321. }
  322. if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
  323. r.s = 0;
  324. r._clamp();
  325. }
  326. // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
  327. // r != q, this != m. q or r may be null.
  328. function bnpDivRemTo(m,q,r) {
  329. var pm = m.abs();
  330. if(pm.t <= 0) return;
  331. var pt = this.abs();
  332. if(pt.t < pm.t) {
  333. if(q != null) q._fromInt(0);
  334. if(r != null) this._copyTo(r);
  335. return;
  336. }
  337. if(r == null) r = nbi();
  338. var y = nbi(), ts = this.s, ms = m.s;
  339. var nsh = this._DB-nbits(pm[pm.t-1]); // normalize modulus
  340. if(nsh > 0) { pm._lShiftTo(nsh,y); pt._lShiftTo(nsh,r); }
  341. else { pm._copyTo(y); pt._copyTo(r); }
  342. var ys = y.t;
  343. var y0 = y[ys-1];
  344. if(y0 == 0) return;
  345. var yt = y0*(1<<this._F1)+((ys>1)?y[ys-2]>>this._F2:0);
  346. var d1 = this._FV/yt, d2 = (1<<this._F1)/yt, e = 1<<this._F2;
  347. var i = r.t, j = i-ys, t = (q==null)?nbi():q;
  348. y._dlShiftTo(j,t);
  349. if(r.compareTo(t) >= 0) {
  350. r[r.t++] = 1;
  351. r._subTo(t,r);
  352. }
  353. BigInteger.ONE._dlShiftTo(ys,t);
  354. t._subTo(y,y); // "negative" y so we can replace sub with am later
  355. while(y.t < ys) y[y.t++] = 0;
  356. while(--j >= 0) {
  357. // Estimate quotient digit
  358. var qd = (r[--i]==y0)?this._DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
  359. if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
  360. y._dlShiftTo(j,t);
  361. r._subTo(t,r);
  362. while(r[i] < --qd) r._subTo(t,r);
  363. }
  364. }
  365. if(q != null) {
  366. r._drShiftTo(ys,q);
  367. if(ts != ms) BigInteger.ZERO._subTo(q,q);
  368. }
  369. r.t = ys;
  370. r._clamp();
  371. if(nsh > 0) r._rShiftTo(nsh,r); // Denormalize remainder
  372. if(ts < 0) BigInteger.ZERO._subTo(r,r);
  373. }
  374. // (public) this mod a
  375. function bnMod(a) {
  376. var r = nbi();
  377. this.abs()._divRemTo(a,null,r);
  378. if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a._subTo(r,r);
  379. return r;
  380. }
  381. // Modular reduction using "classic" algorithm
  382. function Classic(m) { this.m = m; }
  383. function cConvert(x) {
  384. if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
  385. else return x;
  386. }
  387. function cRevert(x) { return x; }
  388. function cReduce(x) { x._divRemTo(this.m,null,x); }
  389. function cMulTo(x,y,r) { x._multiplyTo(y,r); this.reduce(r); }
  390. function cSqrTo(x,r) { x._squareTo(r); this.reduce(r); }
  391. dojo.extend(Classic, {
  392. convert: cConvert,
  393. revert: cRevert,
  394. reduce: cReduce,
  395. mulTo: cMulTo,
  396. sqrTo: cSqrTo
  397. });
  398. // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
  399. // justification:
  400. // xy == 1 (mod m)
  401. // xy = 1+km
  402. // xy(2-xy) = (1+km)(1-km)
  403. // x[y(2-xy)] = 1-k^2m^2
  404. // x[y(2-xy)] == 1 (mod m^2)
  405. // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
  406. // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
  407. // JS multiply "overflows" differently from C/C++, so care is needed here.
  408. function bnpInvDigit() {
  409. if(this.t < 1) return 0;
  410. var x = this[0];
  411. if((x&1) == 0) return 0;
  412. var y = x&3; // y == 1/x mod 2^2
  413. y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
  414. y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
  415. y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
  416. // last step - calculate inverse mod DV directly;
  417. // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
  418. y = (y*(2-x*y%this._DV))%this._DV; // y == 1/x mod 2^dbits
  419. // we really want the negative inverse, and -DV < y < DV
  420. return (y>0)?this._DV-y:-y;
  421. }
  422. // Montgomery reduction
  423. function Montgomery(m) {
  424. this.m = m;
  425. this.mp = m._invDigit();
  426. this.mpl = this.mp&0x7fff;
  427. this.mph = this.mp>>15;
  428. this.um = (1<<(m._DB-15))-1;
  429. this.mt2 = 2*m.t;
  430. }
  431. // xR mod m
  432. function montConvert(x) {
  433. var r = nbi();
  434. x.abs()._dlShiftTo(this.m.t,r);
  435. r._divRemTo(this.m,null,r);
  436. if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m._subTo(r,r);
  437. return r;
  438. }
  439. // x/R mod m
  440. function montRevert(x) {
  441. var r = nbi();
  442. x._copyTo(r);
  443. this.reduce(r);
  444. return r;
  445. }
  446. // x = x/R mod m (HAC 14.32)
  447. function montReduce(x) {
  448. while(x.t <= this.mt2) // pad x so am has enough room later
  449. x[x.t++] = 0;
  450. for(var i = 0; i < this.m.t; ++i) {
  451. // faster way of calculating u0 = x[i]*mp mod DV
  452. var j = x[i]&0x7fff;
  453. var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x._DM;
  454. // use am to combine the multiply-shift-add into one call
  455. j = i+this.m.t;
  456. x[j] += this.m.am(0,u0,x,i,0,this.m.t);
  457. // propagate carry
  458. while(x[j] >= x._DV) { x[j] -= x._DV; x[++j]++; }
  459. }
  460. x._clamp();
  461. x._drShiftTo(this.m.t,x);
  462. if(x.compareTo(this.m) >= 0) x._subTo(this.m,x);
  463. }
  464. // r = "x^2/R mod m"; x != r
  465. function montSqrTo(x,r) { x._squareTo(r); this.reduce(r); }
  466. // r = "xy/R mod m"; x,y != r
  467. function montMulTo(x,y,r) { x._multiplyTo(y,r); this.reduce(r); }
  468. dojo.extend(Montgomery, {
  469. convert: montConvert,
  470. revert: montRevert,
  471. reduce: montReduce,
  472. mulTo: montMulTo,
  473. sqrTo: montSqrTo
  474. });
  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. dojo.extend(BigInteger, {
  496. // protected, not part of the official API
  497. _DB: dbits,
  498. _DM: (1 << dbits) - 1,
  499. _DV: 1 << dbits,
  500. _FV: Math.pow(2, BI_FP),
  501. _F1: BI_FP - dbits,
  502. _F2: 2 * dbits-BI_FP,
  503. // protected
  504. _copyTo: bnpCopyTo,
  505. _fromInt: bnpFromInt,
  506. _fromString: bnpFromString,
  507. _clamp: bnpClamp,
  508. _dlShiftTo: bnpDLShiftTo,
  509. _drShiftTo: bnpDRShiftTo,
  510. _lShiftTo: bnpLShiftTo,
  511. _rShiftTo: bnpRShiftTo,
  512. _subTo: bnpSubTo,
  513. _multiplyTo: bnpMultiplyTo,
  514. _squareTo: bnpSquareTo,
  515. _divRemTo: bnpDivRemTo,
  516. _invDigit: bnpInvDigit,
  517. _isEven: bnpIsEven,
  518. _exp: bnpExp,
  519. // public
  520. toString: bnToString,
  521. negate: bnNegate,
  522. abs: bnAbs,
  523. compareTo: bnCompareTo,
  524. bitLength: bnBitLength,
  525. mod: bnMod,
  526. modPowInt: bnModPowInt
  527. });
  528. dojo._mixin(BigInteger, {
  529. // "constants"
  530. ZERO: nbv(0),
  531. ONE: nbv(1),
  532. // internal functions
  533. _nbi: nbi,
  534. _nbv: nbv,
  535. _nbits: nbits,
  536. // internal classes
  537. _Montgomery: Montgomery
  538. });
  539. // export to DojoX
  540. dojox.math.BigInteger = BigInteger;
  541. })();
  542. }