jsbn.js 15 KB

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