node-forge
Advanced tools
@@ -1,2 +0,2 @@ | ||
| !function(t){var i={};function r(o){if(i[o])return i[o].exports;var s=i[o]={i:o,l:!1,exports:{}};return t[o].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=t,r.c=i,r.d=function(t,i,o){r.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,i){if(1&i&&(t=r(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var s in t)r.d(o,s,function(i){return t[i]}.bind(null,s));return o},r.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(i,"a",i),i},r.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},r.p="",r(r.s=1)}([function(t,i){t.exports={options:{usePureJavaScript:!1}}},function(t,i,r){r(2),t.exports=r(0)},function(t,i,r){var o=r(0);r(3);var s=[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],e=(1<<26)/s[s.length-1],a=o.jsbn.BigInteger;new a(null).fromInt(2),self.addEventListener("message",(function(t){var i=function(t){for(var i=new a(t.hex,16),r=0,o=t.workLoad,s=0;s<o;++s){if(h(i))return{found:!0,prime:i.toString(16)};i.dAddOffset(n[r++%8],0)}return{found:!1}}(t.data);self.postMessage(i)})),self.postMessage({found:!1});var n=[6,4,2,4,2,4,6,2];function h(t){for(var i=1;i<s.length;){for(var r=s[i],o=i+1;o<s.length&&r<e;)r*=s[o++];for(r=t.modInt(r);i<o;)if(r%s[i++]==0)return!1}return function(t){var i=t.subtract(a.ONE),r=i.getLowestSetBit();if(r<=0)return!1;for(var o,s=i.shiftRight(r),e=(p=t.bitLength(),p<=100?27:p<=150?18:p<=200?15:p<=250?12:p<=300?9:p<=350?8:p<=400?7:p<=500?6:p<=600?5:p<=800?4:p<=1250?3:2),n={nextBytes:function(t){for(var i=0;i<t.length;++i)t[i]=Math.floor(255*Math.random())}},h=0;h<e;++h){do{o=new a(t.bitLength(),n)}while(o.compareTo(a.ONE)<=0||o.compareTo(i)>=0);var u=o.modPow(s,t);if(0!==u.compareTo(a.ONE)&&0!==u.compareTo(i)){for(var f=r;--f;){if(0===(u=u.modPowInt(2,t)).compareTo(a.ONE))return!1;if(0===u.compareTo(i))break}if(0===f)return!1}}var p;return!0}(t)}},function(t,i,r){var o,s=r(0);t.exports=s.jsbn=s.jsbn||{};function e(t,i,r){this.data=[],null!=t&&("number"==typeof t?this.fromNumber(t,i,r):null==i&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,i))}function a(){return new e(null)}function n(t,i,r,o,s,e){for(var a=16383&i,n=i>>14;--e>=0;){var h=16383&this.data[t],u=this.data[t++]>>14,f=n*h+u*a;s=((h=a*h+((16383&f)<<14)+r.data[o]+s)>>28)+(f>>14)+n*u,r.data[o++]=268435455&h}return s}s.jsbn.BigInteger=e,"undefined"==typeof navigator?(e.prototype.am=n,o=28):"Microsoft Internet Explorer"==navigator.appName?(e.prototype.am=function(t,i,r,o,s,e){for(var a=32767&i,n=i>>15;--e>=0;){var h=32767&this.data[t],u=this.data[t++]>>15,f=n*h+u*a;s=((h=a*h+((32767&f)<<15)+r.data[o]+(1073741823&s))>>>30)+(f>>>15)+n*u+(s>>>30),r.data[o++]=1073741823&h}return s},o=30):"Netscape"!=navigator.appName?(e.prototype.am=function(t,i,r,o,s,e){for(;--e>=0;){var a=i*this.data[t++]+r.data[o]+s;s=Math.floor(a/67108864),r.data[o++]=67108863&a}return s},o=26):(e.prototype.am=n,o=28),e.prototype.DB=o,e.prototype.DM=(1<<o)-1,e.prototype.DV=1<<o;e.prototype.FV=Math.pow(2,52),e.prototype.F1=52-o,e.prototype.F2=2*o-52;var h,u,f=new Array;for(h="0".charCodeAt(0),u=0;u<=9;++u)f[h++]=u;for(h="a".charCodeAt(0),u=10;u<36;++u)f[h++]=u;for(h="A".charCodeAt(0),u=10;u<36;++u)f[h++]=u;function p(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function d(t,i){var r=f[t.charCodeAt(i)];return null==r?-1:r}function c(t){var i=a();return i.fromInt(t),i}function m(t){var i,r=1;return 0!=(i=t>>>16)&&(t=i,r+=16),0!=(i=t>>8)&&(t=i,r+=8),0!=(i=t>>4)&&(t=i,r+=4),0!=(i=t>>2)&&(t=i,r+=2),0!=(i=t>>1)&&(t=i,r+=1),r}function l(t){this.m=t}function v(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function T(t,i){return t&i}function y(t,i){return t|i}function b(t,i){return t^i}function g(t,i){return t&~i}function D(t){if(0==t)return-1;var i=0;return 0==(65535&t)&&(t>>=16,i+=16),0==(255&t)&&(t>>=8,i+=8),0==(15&t)&&(t>>=4,i+=4),0==(3&t)&&(t>>=2,i+=2),0==(1&t)&&++i,i}function B(t){for(var i=0;0!=t;)t&=t-1,++i;return i}function S(){}function M(t){return t}function w(t){this.r2=a(),this.q3=a(),e.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}l.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},l.prototype.revert=function(t){return t},l.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},l.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},l.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)},v.prototype.convert=function(t){var i=a();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(e.ZERO)>0&&this.m.subTo(i,i),i},v.prototype.revert=function(t){var i=a();return t.copyTo(i),this.reduce(i),i},v.prototype.reduce=function(t){for(;t.t<=this.mt2;)t.data[t.t++]=0;for(var i=0;i<this.m.t;++i){var r=32767&t.data[i],o=r*this.mpl+((r*this.mph+(t.data[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(r=i+this.m.t,t.data[r]+=this.m.am(0,o,t,i,0,this.m.t);t.data[r]>=t.DV;)t.data[r]-=t.DV,t.data[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},v.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},v.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)},e.prototype.copyTo=function(t){for(var i=this.t-1;i>=0;--i)t.data[i]=this.data[i];t.t=this.t,t.s=this.s},e.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this.data[0]=t:t<-1?this.data[0]=t+this.DV:this.t=0},e.prototype.fromString=function(t,i){var r;if(16==i)r=4;else if(8==i)r=3;else if(256==i)r=8;else if(2==i)r=1;else if(32==i)r=5;else{if(4!=i)return void this.fromRadix(t,i);r=2}this.t=0,this.s=0;for(var o=t.length,s=!1,a=0;--o>=0;){var n=8==r?255&t[o]:d(t,o);n<0?"-"==t.charAt(o)&&(s=!0):(s=!1,0==a?this.data[this.t++]=n:a+r>this.DB?(this.data[this.t-1]|=(n&(1<<this.DB-a)-1)<<a,this.data[this.t++]=n>>this.DB-a):this.data[this.t-1]|=n<<a,(a+=r)>=this.DB&&(a-=this.DB))}8==r&&0!=(128&t[0])&&(this.s=-1,a>0&&(this.data[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),s&&e.ZERO.subTo(this,this)},e.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this.data[this.t-1]==t;)--this.t},e.prototype.dlShiftTo=function(t,i){var r;for(r=this.t-1;r>=0;--r)i.data[r+t]=this.data[r];for(r=t-1;r>=0;--r)i.data[r]=0;i.t=this.t+t,i.s=this.s},e.prototype.drShiftTo=function(t,i){for(var r=t;r<this.t;++r)i.data[r-t]=this.data[r];i.t=Math.max(this.t-t,0),i.s=this.s},e.prototype.lShiftTo=function(t,i){var r,o=t%this.DB,s=this.DB-o,e=(1<<s)-1,a=Math.floor(t/this.DB),n=this.s<<o&this.DM;for(r=this.t-1;r>=0;--r)i.data[r+a+1]=this.data[r]>>s|n,n=(this.data[r]&e)<<o;for(r=a-1;r>=0;--r)i.data[r]=0;i.data[a]=n,i.t=this.t+a+1,i.s=this.s,i.clamp()},e.prototype.rShiftTo=function(t,i){i.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)i.t=0;else{var o=t%this.DB,s=this.DB-o,e=(1<<o)-1;i.data[0]=this.data[r]>>o;for(var a=r+1;a<this.t;++a)i.data[a-r-1]|=(this.data[a]&e)<<s,i.data[a-r]=this.data[a]>>o;o>0&&(i.data[this.t-r-1]|=(this.s&e)<<s),i.t=this.t-r,i.clamp()}},e.prototype.subTo=function(t,i){for(var r=0,o=0,s=Math.min(t.t,this.t);r<s;)o+=this.data[r]-t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;if(t.t<this.t){for(o-=t.s;r<this.t;)o+=this.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=this.s}else{for(o+=this.s;r<t.t;)o-=t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o-=t.s}i.s=o<0?-1:0,o<-1?i.data[r++]=this.DV+o:o>0&&(i.data[r++]=o),i.t=r,i.clamp()},e.prototype.multiplyTo=function(t,i){var r=this.abs(),o=t.abs(),s=r.t;for(i.t=s+o.t;--s>=0;)i.data[s]=0;for(s=0;s<o.t;++s)i.data[s+r.t]=r.am(0,o.data[s],i,s,0,r.t);i.s=0,i.clamp(),this.s!=t.s&&e.ZERO.subTo(i,i)},e.prototype.squareTo=function(t){for(var i=this.abs(),r=t.t=2*i.t;--r>=0;)t.data[r]=0;for(r=0;r<i.t-1;++r){var o=i.am(r,i.data[r],t,2*r,0,1);(t.data[r+i.t]+=i.am(r+1,2*i.data[r],t,2*r+1,o,i.t-r-1))>=i.DV&&(t.data[r+i.t]-=i.DV,t.data[r+i.t+1]=1)}t.t>0&&(t.data[t.t-1]+=i.am(r,i.data[r],t,2*r,0,1)),t.s=0,t.clamp()},e.prototype.divRemTo=function(t,i,r){var o=t.abs();if(!(o.t<=0)){var s=this.abs();if(s.t<o.t)return null!=i&&i.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=a());var n=a(),h=this.s,u=t.s,f=this.DB-m(o.data[o.t-1]);f>0?(o.lShiftTo(f,n),s.lShiftTo(f,r)):(o.copyTo(n),s.copyTo(r));var p=n.t,d=n.data[p-1];if(0!=d){var c=d*(1<<this.F1)+(p>1?n.data[p-2]>>this.F2:0),l=this.FV/c,v=(1<<this.F1)/c,T=1<<this.F2,y=r.t,b=y-p,g=null==i?a():i;for(n.dlShiftTo(b,g),r.compareTo(g)>=0&&(r.data[r.t++]=1,r.subTo(g,r)),e.ONE.dlShiftTo(p,g),g.subTo(n,n);n.t<p;)n.data[n.t++]=0;for(;--b>=0;){var D=r.data[--y]==d?this.DM:Math.floor(r.data[y]*l+(r.data[y-1]+T)*v);if((r.data[y]+=n.am(0,D,r,b,0,p))<D)for(n.dlShiftTo(b,g),r.subTo(g,r);r.data[y]<--D;)r.subTo(g,r)}null!=i&&(r.drShiftTo(p,i),h!=u&&e.ZERO.subTo(i,i)),r.t=p,r.clamp(),f>0&&r.rShiftTo(f,r),h<0&&e.ZERO.subTo(r,r)}}},e.prototype.invDigit=function(){if(this.t<1)return 0;var t=this.data[0];if(0==(1&t))return 0;var i=3&t;return(i=(i=(i=(i=i*(2-(15&t)*i)&15)*(2-(255&t)*i)&255)*(2-((65535&t)*i&65535))&65535)*(2-t*i%this.DV)%this.DV)>0?this.DV-i:-i},e.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},e.prototype.exp=function(t,i){if(t>4294967295||t<1)return e.ONE;var r=a(),o=a(),s=i.convert(this),n=m(t)-1;for(s.copyTo(r);--n>=0;)if(i.sqrTo(r,o),(t&1<<n)>0)i.mulTo(o,s,r);else{var h=r;r=o,o=h}return i.revert(r)},e.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var r,o=(1<<i)-1,s=!1,e="",a=this.t,n=this.DB-a*this.DB%i;if(a-- >0)for(n<this.DB&&(r=this.data[a]>>n)>0&&(s=!0,e=p(r));a>=0;)n<i?(r=(this.data[a]&(1<<n)-1)<<i-n,r|=this.data[--a]>>(n+=this.DB-i)):(r=this.data[a]>>(n-=i)&o,n<=0&&(n+=this.DB,--a)),r>0&&(s=!0),s&&(e+=p(r));return s?e:"0"},e.prototype.negate=function(){var t=a();return e.ZERO.subTo(this,t),t},e.prototype.abs=function(){return this.s<0?this.negate():this},e.prototype.compareTo=function(t){var i=this.s-t.s;if(0!=i)return i;var r=this.t;if(0!=(i=r-t.t))return this.s<0?-i:i;for(;--r>=0;)if(0!=(i=this.data[r]-t.data[r]))return i;return 0},e.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+m(this.data[this.t-1]^this.s&this.DM)},e.prototype.mod=function(t){var i=a();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(e.ZERO)>0&&t.subTo(i,i),i},e.prototype.modPowInt=function(t,i){var r;return r=t<256||i.isEven()?new l(i):new v(i),this.exp(t,r)},e.ZERO=c(0),e.ONE=c(1),S.prototype.convert=M,S.prototype.revert=M,S.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r)},S.prototype.sqrTo=function(t,i){t.squareTo(i)},w.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var i=a();return t.copyTo(i),this.reduce(i),i},w.prototype.revert=function(t){return t},w.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},w.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},w.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)};var E=[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],O=(1<<26)/E[E.length-1];e.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},e.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var i=this.chunkSize(t),r=Math.pow(t,i),o=c(r),s=a(),e=a(),n="";for(this.divRemTo(o,s,e);s.signum()>0;)n=(r+e.intValue()).toString(t).substr(1)+n,s.divRemTo(o,s,e);return e.intValue().toString(t)+n},e.prototype.fromRadix=function(t,i){this.fromInt(0),null==i&&(i=10);for(var r=this.chunkSize(i),o=Math.pow(i,r),s=!1,a=0,n=0,h=0;h<t.length;++h){var u=d(t,h);u<0?"-"==t.charAt(h)&&0==this.signum()&&(s=!0):(n=i*n+u,++a>=r&&(this.dMultiply(o),this.dAddOffset(n,0),a=0,n=0))}a>0&&(this.dMultiply(Math.pow(i,a)),this.dAddOffset(n,0)),s&&e.ZERO.subTo(this,this)},e.prototype.fromNumber=function(t,i,r){if("number"==typeof i)if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(e.ONE.shiftLeft(t-1),y,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(e.ONE.shiftLeft(t-1),this);else{var o=new Array,s=7&t;o.length=1+(t>>3),i.nextBytes(o),s>0?o[0]&=(1<<s)-1:o[0]=0,this.fromString(o,256)}},e.prototype.bitwiseTo=function(t,i,r){var o,s,e=Math.min(t.t,this.t);for(o=0;o<e;++o)r.data[o]=i(this.data[o],t.data[o]);if(t.t<this.t){for(s=t.s&this.DM,o=e;o<this.t;++o)r.data[o]=i(this.data[o],s);r.t=this.t}else{for(s=this.s&this.DM,o=e;o<t.t;++o)r.data[o]=i(s,t.data[o]);r.t=t.t}r.s=i(this.s,t.s),r.clamp()},e.prototype.changeBit=function(t,i){var r=e.ONE.shiftLeft(t);return this.bitwiseTo(r,i,r),r},e.prototype.addTo=function(t,i){for(var r=0,o=0,s=Math.min(t.t,this.t);r<s;)o+=this.data[r]+t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;if(t.t<this.t){for(o+=t.s;r<this.t;)o+=this.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=this.s}else{for(o+=this.s;r<t.t;)o+=t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=t.s}i.s=o<0?-1:0,o>0?i.data[r++]=o:o<-1&&(i.data[r++]=this.DV+o),i.t=r,i.clamp()},e.prototype.dMultiply=function(t){this.data[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},e.prototype.dAddOffset=function(t,i){if(0!=t){for(;this.t<=i;)this.data[this.t++]=0;for(this.data[i]+=t;this.data[i]>=this.DV;)this.data[i]-=this.DV,++i>=this.t&&(this.data[this.t++]=0),++this.data[i]}},e.prototype.multiplyLowerTo=function(t,i,r){var o,s=Math.min(this.t+t.t,i);for(r.s=0,r.t=s;s>0;)r.data[--s]=0;for(o=r.t-this.t;s<o;++s)r.data[s+this.t]=this.am(0,t.data[s],r,s,0,this.t);for(o=Math.min(t.t,i);s<o;++s)this.am(0,t.data[s],r,s,0,i-s);r.clamp()},e.prototype.multiplyUpperTo=function(t,i,r){--i;var o=r.t=this.t+t.t-i;for(r.s=0;--o>=0;)r.data[o]=0;for(o=Math.max(i-this.t,0);o<t.t;++o)r.data[this.t+o-i]=this.am(i-o,t.data[o],r,0,0,this.t+o-i);r.clamp(),r.drShiftTo(1,r)},e.prototype.modInt=function(t){if(t<=0)return 0;var i=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==i)r=this.data[0]%t;else for(var o=this.t-1;o>=0;--o)r=(i*r+this.data[o])%t;return r},e.prototype.millerRabin=function(t){var i=this.subtract(e.ONE),r=i.getLowestSetBit();if(r<=0)return!1;for(var o,s=i.shiftRight(r),a={nextBytes:function(t){for(var i=0;i<t.length;++i)t[i]=Math.floor(256*Math.random())}},n=0;n<t;++n){do{o=new e(this.bitLength(),a)}while(o.compareTo(e.ONE)<=0||o.compareTo(i)>=0);var h=o.modPow(s,this);if(0!=h.compareTo(e.ONE)&&0!=h.compareTo(i)){for(var u=1;u++<r&&0!=h.compareTo(i);)if(0==(h=h.modPowInt(2,this)).compareTo(e.ONE))return!1;if(0!=h.compareTo(i))return!1}}return!0},e.prototype.clone=function(){var t=a();return this.copyTo(t),t},e.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this.data[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this.data[0];if(0==this.t)return 0}return(this.data[1]&(1<<32-this.DB)-1)<<this.DB|this.data[0]},e.prototype.byteValue=function(){return 0==this.t?this.s:this.data[0]<<24>>24},e.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},e.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},e.prototype.toByteArray=function(){var t=this.t,i=new Array;i[0]=this.s;var r,o=this.DB-t*this.DB%8,s=0;if(t-- >0)for(o<this.DB&&(r=this.data[t]>>o)!=(this.s&this.DM)>>o&&(i[s++]=r|this.s<<this.DB-o);t>=0;)o<8?(r=(this.data[t]&(1<<o)-1)<<8-o,r|=this.data[--t]>>(o+=this.DB-8)):(r=this.data[t]>>(o-=8)&255,o<=0&&(o+=this.DB,--t)),0!=(128&r)&&(r|=-256),0==s&&(128&this.s)!=(128&r)&&++s,(s>0||r!=this.s)&&(i[s++]=r);return i},e.prototype.equals=function(t){return 0==this.compareTo(t)},e.prototype.min=function(t){return this.compareTo(t)<0?this:t},e.prototype.max=function(t){return this.compareTo(t)>0?this:t},e.prototype.and=function(t){var i=a();return this.bitwiseTo(t,T,i),i},e.prototype.or=function(t){var i=a();return this.bitwiseTo(t,y,i),i},e.prototype.xor=function(t){var i=a();return this.bitwiseTo(t,b,i),i},e.prototype.andNot=function(t){var i=a();return this.bitwiseTo(t,g,i),i},e.prototype.not=function(){for(var t=a(),i=0;i<this.t;++i)t.data[i]=this.DM&~this.data[i];return t.t=this.t,t.s=~this.s,t},e.prototype.shiftLeft=function(t){var i=a();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i},e.prototype.shiftRight=function(t){var i=a();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i},e.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this.data[t])return t*this.DB+D(this.data[t]);return this.s<0?this.t*this.DB:-1},e.prototype.bitCount=function(){for(var t=0,i=this.s&this.DM,r=0;r<this.t;++r)t+=B(this.data[r]^i);return t},e.prototype.testBit=function(t){var i=Math.floor(t/this.DB);return i>=this.t?0!=this.s:0!=(this.data[i]&1<<t%this.DB)},e.prototype.setBit=function(t){return this.changeBit(t,y)},e.prototype.clearBit=function(t){return this.changeBit(t,g)},e.prototype.flipBit=function(t){return this.changeBit(t,b)},e.prototype.add=function(t){var i=a();return this.addTo(t,i),i},e.prototype.subtract=function(t){var i=a();return this.subTo(t,i),i},e.prototype.multiply=function(t){var i=a();return this.multiplyTo(t,i),i},e.prototype.divide=function(t){var i=a();return this.divRemTo(t,i,null),i},e.prototype.remainder=function(t){var i=a();return this.divRemTo(t,null,i),i},e.prototype.divideAndRemainder=function(t){var i=a(),r=a();return this.divRemTo(t,i,r),new Array(i,r)},e.prototype.modPow=function(t,i){var r,o,s=t.bitLength(),e=c(1);if(s<=0)return e;r=s<18?1:s<48?3:s<144?4:s<768?5:6,o=s<8?new l(i):i.isEven()?new w(i):new v(i);var n=new Array,h=3,u=r-1,f=(1<<r)-1;if(n[1]=o.convert(this),r>1){var p=a();for(o.sqrTo(n[1],p);h<=f;)n[h]=a(),o.mulTo(p,n[h-2],n[h]),h+=2}var d,T,y=t.t-1,b=!0,g=a();for(s=m(t.data[y])-1;y>=0;){for(s>=u?d=t.data[y]>>s-u&f:(d=(t.data[y]&(1<<s+1)-1)<<u-s,y>0&&(d|=t.data[y-1]>>this.DB+s-u)),h=r;0==(1&d);)d>>=1,--h;if((s-=h)<0&&(s+=this.DB,--y),b)n[d].copyTo(e),b=!1;else{for(;h>1;)o.sqrTo(e,g),o.sqrTo(g,e),h-=2;h>0?o.sqrTo(e,g):(T=e,e=g,g=T),o.mulTo(g,n[d],e)}for(;y>=0&&0==(t.data[y]&1<<s);)o.sqrTo(e,g),T=e,e=g,g=T,--s<0&&(s=this.DB-1,--y)}return o.revert(e)},e.prototype.modInverse=function(t){var i=t.isEven();if(this.isEven()&&i||0==t.signum())return e.ZERO;for(var r=t.clone(),o=this.clone(),s=c(1),a=c(0),n=c(0),h=c(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),i?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);for(;o.isEven();)o.rShiftTo(1,o),i?(n.isEven()&&h.isEven()||(n.addTo(this,n),h.subTo(t,h)),n.rShiftTo(1,n)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);r.compareTo(o)>=0?(r.subTo(o,r),i&&s.subTo(n,s),a.subTo(h,a)):(o.subTo(r,o),i&&n.subTo(s,n),h.subTo(a,h))}return 0!=o.compareTo(e.ONE)?e.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h},e.prototype.pow=function(t){return this.exp(t,new S)},e.prototype.gcd=function(t){var i=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(i.compareTo(r)<0){var o=i;i=r,r=o}var s=i.getLowestSetBit(),e=r.getLowestSetBit();if(e<0)return i;for(s<e&&(e=s),e>0&&(i.rShiftTo(e,i),r.rShiftTo(e,r));i.signum()>0;)(s=i.getLowestSetBit())>0&&i.rShiftTo(s,i),(s=r.getLowestSetBit())>0&&r.rShiftTo(s,r),i.compareTo(r)>=0?(i.subTo(r,i),i.rShiftTo(1,i)):(r.subTo(i,r),r.rShiftTo(1,r));return e>0&&r.lShiftTo(e,r),r},e.prototype.isProbablePrime=function(t){var i,r=this.abs();if(1==r.t&&r.data[0]<=E[E.length-1]){for(i=0;i<E.length;++i)if(r.data[0]==E[i])return!0;return!1}if(r.isEven())return!1;for(i=1;i<E.length;){for(var o=E[i],s=i+1;s<E.length&&o<O;)o*=E[s++];for(o=r.modInt(o);i<s;)if(o%E[i++]==0)return!1}return r.millerRabin(t)}}]); | ||
| !function(t){var i={};function r(o){if(i[o])return i[o].exports;var s=i[o]={i:o,l:!1,exports:{}};return t[o].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=t,r.c=i,r.d=function(t,i,o){r.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,i){if(1&i&&(t=r(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var s in t)r.d(o,s,function(i){return t[i]}.bind(null,s));return o},r.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(i,"a",i),i},r.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},r.p="",r(r.s=1)}([function(t,i){t.exports={options:{usePureJavaScript:!1}}},function(t,i,r){r(2),t.exports=r(0)},function(t,i,r){var o=r(0);r(3);var s=[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],e=(1<<26)/s[s.length-1],a=o.jsbn.BigInteger;new a(null).fromInt(2),self.addEventListener("message",(function(t){var i=function(t){for(var i=new a(t.hex,16),r=0,o=t.workLoad,s=0;s<o;++s){if(h(i))return{found:!0,prime:i.toString(16)};i.dAddOffset(n[r++%8],0)}return{found:!1}}(t.data);self.postMessage(i)})),self.postMessage({found:!1});var n=[6,4,2,4,2,4,6,2];function h(t){for(var i=1;i<s.length;){for(var r=s[i],o=i+1;o<s.length&&r<e;)r*=s[o++];for(r=t.modInt(r);i<o;)if(r%s[i++]==0)return!1}return function(t){var i=t.subtract(a.ONE),r=i.getLowestSetBit();if(r<=0)return!1;for(var o,s=i.shiftRight(r),e=(p=t.bitLength(),p<=100?27:p<=150?18:p<=200?15:p<=250?12:p<=300?9:p<=350?8:p<=400?7:p<=500?6:p<=600?5:p<=800?4:p<=1250?3:2),n={nextBytes:function(t){for(var i=0;i<t.length;++i)t[i]=Math.floor(255*Math.random())}},h=0;h<e;++h){do{o=new a(t.bitLength(),n)}while(o.compareTo(a.ONE)<=0||o.compareTo(i)>=0);var u=o.modPow(s,t);if(0!==u.compareTo(a.ONE)&&0!==u.compareTo(i)){for(var f=r;--f;){if(0===(u=u.modPowInt(2,t)).compareTo(a.ONE))return!1;if(0===u.compareTo(i))break}if(0===f)return!1}}var p;return!0}(t)}},function(t,i,r){var o,s=r(0);t.exports=s.jsbn=s.jsbn||{};function e(t,i,r){this.data=[],null!=t&&("number"==typeof t?this.fromNumber(t,i,r):null==i&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,i))}function a(){return new e(null)}function n(t,i,r,o,s,e){for(var a=16383&i,n=i>>14;--e>=0;){var h=16383&this.data[t],u=this.data[t++]>>14,f=n*h+u*a;s=((h=a*h+((16383&f)<<14)+r.data[o]+s)>>28)+(f>>14)+n*u,r.data[o++]=268435455&h}return s}s.jsbn.BigInteger=e,"undefined"==typeof navigator?(e.prototype.am=n,o=28):"Microsoft Internet Explorer"==navigator.appName?(e.prototype.am=function(t,i,r,o,s,e){for(var a=32767&i,n=i>>15;--e>=0;){var h=32767&this.data[t],u=this.data[t++]>>15,f=n*h+u*a;s=((h=a*h+((32767&f)<<15)+r.data[o]+(1073741823&s))>>>30)+(f>>>15)+n*u+(s>>>30),r.data[o++]=1073741823&h}return s},o=30):"Netscape"!=navigator.appName?(e.prototype.am=function(t,i,r,o,s,e){for(;--e>=0;){var a=i*this.data[t++]+r.data[o]+s;s=Math.floor(a/67108864),r.data[o++]=67108863&a}return s},o=26):(e.prototype.am=n,o=28),e.prototype.DB=o,e.prototype.DM=(1<<o)-1,e.prototype.DV=1<<o;e.prototype.FV=Math.pow(2,52),e.prototype.F1=52-o,e.prototype.F2=2*o-52;var h,u,f=new Array;for(h="0".charCodeAt(0),u=0;u<=9;++u)f[h++]=u;for(h="a".charCodeAt(0),u=10;u<36;++u)f[h++]=u;for(h="A".charCodeAt(0),u=10;u<36;++u)f[h++]=u;function p(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function d(t,i){var r=f[t.charCodeAt(i)];return null==r?-1:r}function c(t){var i=a();return i.fromInt(t),i}function m(t){var i,r=1;return 0!=(i=t>>>16)&&(t=i,r+=16),0!=(i=t>>8)&&(t=i,r+=8),0!=(i=t>>4)&&(t=i,r+=4),0!=(i=t>>2)&&(t=i,r+=2),0!=(i=t>>1)&&(t=i,r+=1),r}function l(t){this.m=t}function v(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function T(t,i){return t&i}function y(t,i){return t|i}function b(t,i){return t^i}function g(t,i){return t&~i}function D(t){if(0==t)return-1;var i=0;return 0==(65535&t)&&(t>>=16,i+=16),0==(255&t)&&(t>>=8,i+=8),0==(15&t)&&(t>>=4,i+=4),0==(3&t)&&(t>>=2,i+=2),0==(1&t)&&++i,i}function B(t){for(var i=0;0!=t;)t&=t-1,++i;return i}function S(){}function M(t){return t}function w(t){this.r2=a(),this.q3=a(),e.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}l.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},l.prototype.revert=function(t){return t},l.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},l.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},l.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)},v.prototype.convert=function(t){var i=a();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(e.ZERO)>0&&this.m.subTo(i,i),i},v.prototype.revert=function(t){var i=a();return t.copyTo(i),this.reduce(i),i},v.prototype.reduce=function(t){for(;t.t<=this.mt2;)t.data[t.t++]=0;for(var i=0;i<this.m.t;++i){var r=32767&t.data[i],o=r*this.mpl+((r*this.mph+(t.data[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(r=i+this.m.t,t.data[r]+=this.m.am(0,o,t,i,0,this.m.t);t.data[r]>=t.DV;)t.data[r]-=t.DV,t.data[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},v.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},v.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)},e.prototype.copyTo=function(t){for(var i=this.t-1;i>=0;--i)t.data[i]=this.data[i];t.t=this.t,t.s=this.s},e.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this.data[0]=t:t<-1?this.data[0]=t+this.DV:this.t=0},e.prototype.fromString=function(t,i){var r;if(16==i)r=4;else if(8==i)r=3;else if(256==i)r=8;else if(2==i)r=1;else if(32==i)r=5;else{if(4!=i)return void this.fromRadix(t,i);r=2}this.t=0,this.s=0;for(var o=t.length,s=!1,a=0;--o>=0;){var n=8==r?255&t[o]:d(t,o);n<0?"-"==t.charAt(o)&&(s=!0):(s=!1,0==a?this.data[this.t++]=n:a+r>this.DB?(this.data[this.t-1]|=(n&(1<<this.DB-a)-1)<<a,this.data[this.t++]=n>>this.DB-a):this.data[this.t-1]|=n<<a,(a+=r)>=this.DB&&(a-=this.DB))}8==r&&0!=(128&t[0])&&(this.s=-1,a>0&&(this.data[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),s&&e.ZERO.subTo(this,this)},e.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this.data[this.t-1]==t;)--this.t},e.prototype.dlShiftTo=function(t,i){var r;for(r=this.t-1;r>=0;--r)i.data[r+t]=this.data[r];for(r=t-1;r>=0;--r)i.data[r]=0;i.t=this.t+t,i.s=this.s},e.prototype.drShiftTo=function(t,i){for(var r=t;r<this.t;++r)i.data[r-t]=this.data[r];i.t=Math.max(this.t-t,0),i.s=this.s},e.prototype.lShiftTo=function(t,i){var r,o=t%this.DB,s=this.DB-o,e=(1<<s)-1,a=Math.floor(t/this.DB),n=this.s<<o&this.DM;for(r=this.t-1;r>=0;--r)i.data[r+a+1]=this.data[r]>>s|n,n=(this.data[r]&e)<<o;for(r=a-1;r>=0;--r)i.data[r]=0;i.data[a]=n,i.t=this.t+a+1,i.s=this.s,i.clamp()},e.prototype.rShiftTo=function(t,i){i.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)i.t=0;else{var o=t%this.DB,s=this.DB-o,e=(1<<o)-1;i.data[0]=this.data[r]>>o;for(var a=r+1;a<this.t;++a)i.data[a-r-1]|=(this.data[a]&e)<<s,i.data[a-r]=this.data[a]>>o;o>0&&(i.data[this.t-r-1]|=(this.s&e)<<s),i.t=this.t-r,i.clamp()}},e.prototype.subTo=function(t,i){for(var r=0,o=0,s=Math.min(t.t,this.t);r<s;)o+=this.data[r]-t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;if(t.t<this.t){for(o-=t.s;r<this.t;)o+=this.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=this.s}else{for(o+=this.s;r<t.t;)o-=t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o-=t.s}i.s=o<0?-1:0,o<-1?i.data[r++]=this.DV+o:o>0&&(i.data[r++]=o),i.t=r,i.clamp()},e.prototype.multiplyTo=function(t,i){var r=this.abs(),o=t.abs(),s=r.t;for(i.t=s+o.t;--s>=0;)i.data[s]=0;for(s=0;s<o.t;++s)i.data[s+r.t]=r.am(0,o.data[s],i,s,0,r.t);i.s=0,i.clamp(),this.s!=t.s&&e.ZERO.subTo(i,i)},e.prototype.squareTo=function(t){for(var i=this.abs(),r=t.t=2*i.t;--r>=0;)t.data[r]=0;for(r=0;r<i.t-1;++r){var o=i.am(r,i.data[r],t,2*r,0,1);(t.data[r+i.t]+=i.am(r+1,2*i.data[r],t,2*r+1,o,i.t-r-1))>=i.DV&&(t.data[r+i.t]-=i.DV,t.data[r+i.t+1]=1)}t.t>0&&(t.data[t.t-1]+=i.am(r,i.data[r],t,2*r,0,1)),t.s=0,t.clamp()},e.prototype.divRemTo=function(t,i,r){var o=t.abs();if(!(o.t<=0)){var s=this.abs();if(s.t<o.t)return null!=i&&i.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=a());var n=a(),h=this.s,u=t.s,f=this.DB-m(o.data[o.t-1]);f>0?(o.lShiftTo(f,n),s.lShiftTo(f,r)):(o.copyTo(n),s.copyTo(r));var p=n.t,d=n.data[p-1];if(0!=d){var c=d*(1<<this.F1)+(p>1?n.data[p-2]>>this.F2:0),l=this.FV/c,v=(1<<this.F1)/c,T=1<<this.F2,y=r.t,b=y-p,g=null==i?a():i;for(n.dlShiftTo(b,g),r.compareTo(g)>=0&&(r.data[r.t++]=1,r.subTo(g,r)),e.ONE.dlShiftTo(p,g),g.subTo(n,n);n.t<p;)n.data[n.t++]=0;for(;--b>=0;){var D=r.data[--y]==d?this.DM:Math.floor(r.data[y]*l+(r.data[y-1]+T)*v);if((r.data[y]+=n.am(0,D,r,b,0,p))<D)for(n.dlShiftTo(b,g),r.subTo(g,r);r.data[y]<--D;)r.subTo(g,r)}null!=i&&(r.drShiftTo(p,i),h!=u&&e.ZERO.subTo(i,i)),r.t=p,r.clamp(),f>0&&r.rShiftTo(f,r),h<0&&e.ZERO.subTo(r,r)}}},e.prototype.invDigit=function(){if(this.t<1)return 0;var t=this.data[0];if(0==(1&t))return 0;var i=3&t;return(i=(i=(i=(i=i*(2-(15&t)*i)&15)*(2-(255&t)*i)&255)*(2-((65535&t)*i&65535))&65535)*(2-t*i%this.DV)%this.DV)>0?this.DV-i:-i},e.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},e.prototype.exp=function(t,i){if(t>4294967295||t<1)return e.ONE;var r=a(),o=a(),s=i.convert(this),n=m(t)-1;for(s.copyTo(r);--n>=0;)if(i.sqrTo(r,o),(t&1<<n)>0)i.mulTo(o,s,r);else{var h=r;r=o,o=h}return i.revert(r)},e.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var r,o=(1<<i)-1,s=!1,e="",a=this.t,n=this.DB-a*this.DB%i;if(a-- >0)for(n<this.DB&&(r=this.data[a]>>n)>0&&(s=!0,e=p(r));a>=0;)n<i?(r=(this.data[a]&(1<<n)-1)<<i-n,r|=this.data[--a]>>(n+=this.DB-i)):(r=this.data[a]>>(n-=i)&o,n<=0&&(n+=this.DB,--a)),r>0&&(s=!0),s&&(e+=p(r));return s?e:"0"},e.prototype.negate=function(){var t=a();return e.ZERO.subTo(this,t),t},e.prototype.abs=function(){return this.s<0?this.negate():this},e.prototype.compareTo=function(t){var i=this.s-t.s;if(0!=i)return i;var r=this.t;if(0!=(i=r-t.t))return this.s<0?-i:i;for(;--r>=0;)if(0!=(i=this.data[r]-t.data[r]))return i;return 0},e.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+m(this.data[this.t-1]^this.s&this.DM)},e.prototype.mod=function(t){var i=a();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(e.ZERO)>0&&t.subTo(i,i),i},e.prototype.modPowInt=function(t,i){var r;return r=t<256||i.isEven()?new l(i):new v(i),this.exp(t,r)},e.ZERO=c(0),e.ONE=c(1),S.prototype.convert=M,S.prototype.revert=M,S.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r)},S.prototype.sqrTo=function(t,i){t.squareTo(i)},w.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var i=a();return t.copyTo(i),this.reduce(i),i},w.prototype.revert=function(t){return t},w.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},w.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},w.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)};var E=[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],O=(1<<26)/E[E.length-1];e.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},e.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var i=this.chunkSize(t),r=Math.pow(t,i),o=c(r),s=a(),e=a(),n="";for(this.divRemTo(o,s,e);s.signum()>0;)n=(r+e.intValue()).toString(t).substr(1)+n,s.divRemTo(o,s,e);return e.intValue().toString(t)+n},e.prototype.fromRadix=function(t,i){this.fromInt(0),null==i&&(i=10);for(var r=this.chunkSize(i),o=Math.pow(i,r),s=!1,a=0,n=0,h=0;h<t.length;++h){var u=d(t,h);u<0?"-"==t.charAt(h)&&0==this.signum()&&(s=!0):(n=i*n+u,++a>=r&&(this.dMultiply(o),this.dAddOffset(n,0),a=0,n=0))}a>0&&(this.dMultiply(Math.pow(i,a)),this.dAddOffset(n,0)),s&&e.ZERO.subTo(this,this)},e.prototype.fromNumber=function(t,i,r){if("number"==typeof i)if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(e.ONE.shiftLeft(t-1),y,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(e.ONE.shiftLeft(t-1),this);else{var o=new Array,s=7&t;o.length=1+(t>>3),i.nextBytes(o),s>0?o[0]&=(1<<s)-1:o[0]=0,this.fromString(o,256)}},e.prototype.bitwiseTo=function(t,i,r){var o,s,e=Math.min(t.t,this.t);for(o=0;o<e;++o)r.data[o]=i(this.data[o],t.data[o]);if(t.t<this.t){for(s=t.s&this.DM,o=e;o<this.t;++o)r.data[o]=i(this.data[o],s);r.t=this.t}else{for(s=this.s&this.DM,o=e;o<t.t;++o)r.data[o]=i(s,t.data[o]);r.t=t.t}r.s=i(this.s,t.s),r.clamp()},e.prototype.changeBit=function(t,i){var r=e.ONE.shiftLeft(t);return this.bitwiseTo(r,i,r),r},e.prototype.addTo=function(t,i){for(var r=0,o=0,s=Math.min(t.t,this.t);r<s;)o+=this.data[r]+t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;if(t.t<this.t){for(o+=t.s;r<this.t;)o+=this.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=this.s}else{for(o+=this.s;r<t.t;)o+=t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=t.s}i.s=o<0?-1:0,o>0?i.data[r++]=o:o<-1&&(i.data[r++]=this.DV+o),i.t=r,i.clamp()},e.prototype.dMultiply=function(t){this.data[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},e.prototype.dAddOffset=function(t,i){if(0!=t){for(;this.t<=i;)this.data[this.t++]=0;for(this.data[i]+=t;this.data[i]>=this.DV;)this.data[i]-=this.DV,++i>=this.t&&(this.data[this.t++]=0),++this.data[i]}},e.prototype.multiplyLowerTo=function(t,i,r){var o,s=Math.min(this.t+t.t,i);for(r.s=0,r.t=s;s>0;)r.data[--s]=0;for(o=r.t-this.t;s<o;++s)r.data[s+this.t]=this.am(0,t.data[s],r,s,0,this.t);for(o=Math.min(t.t,i);s<o;++s)this.am(0,t.data[s],r,s,0,i-s);r.clamp()},e.prototype.multiplyUpperTo=function(t,i,r){--i;var o=r.t=this.t+t.t-i;for(r.s=0;--o>=0;)r.data[o]=0;for(o=Math.max(i-this.t,0);o<t.t;++o)r.data[this.t+o-i]=this.am(i-o,t.data[o],r,0,0,this.t+o-i);r.clamp(),r.drShiftTo(1,r)},e.prototype.modInt=function(t){if(t<=0)return 0;var i=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==i)r=this.data[0]%t;else for(var o=this.t-1;o>=0;--o)r=(i*r+this.data[o])%t;return r},e.prototype.millerRabin=function(t){var i=this.subtract(e.ONE),r=i.getLowestSetBit();if(r<=0)return!1;for(var o,s=i.shiftRight(r),a={nextBytes:function(t){for(var i=0;i<t.length;++i)t[i]=Math.floor(256*Math.random())}},n=0;n<t;++n){do{o=new e(this.bitLength(),a)}while(o.compareTo(e.ONE)<=0||o.compareTo(i)>=0);var h=o.modPow(s,this);if(0!=h.compareTo(e.ONE)&&0!=h.compareTo(i)){for(var u=1;u++<r&&0!=h.compareTo(i);)if(0==(h=h.modPowInt(2,this)).compareTo(e.ONE))return!1;if(0!=h.compareTo(i))return!1}}return!0},e.prototype.clone=function(){var t=a();return this.copyTo(t),t},e.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this.data[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this.data[0];if(0==this.t)return 0}return(this.data[1]&(1<<32-this.DB)-1)<<this.DB|this.data[0]},e.prototype.byteValue=function(){return 0==this.t?this.s:this.data[0]<<24>>24},e.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},e.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},e.prototype.toByteArray=function(){var t=this.t,i=new Array;i[0]=this.s;var r,o=this.DB-t*this.DB%8,s=0;if(t-- >0)for(o<this.DB&&(r=this.data[t]>>o)!=(this.s&this.DM)>>o&&(i[s++]=r|this.s<<this.DB-o);t>=0;)o<8?(r=(this.data[t]&(1<<o)-1)<<8-o,r|=this.data[--t]>>(o+=this.DB-8)):(r=this.data[t]>>(o-=8)&255,o<=0&&(o+=this.DB,--t)),0!=(128&r)&&(r|=-256),0==s&&(128&this.s)!=(128&r)&&++s,(s>0||r!=this.s)&&(i[s++]=r);return i},e.prototype.equals=function(t){return 0==this.compareTo(t)},e.prototype.min=function(t){return this.compareTo(t)<0?this:t},e.prototype.max=function(t){return this.compareTo(t)>0?this:t},e.prototype.and=function(t){var i=a();return this.bitwiseTo(t,T,i),i},e.prototype.or=function(t){var i=a();return this.bitwiseTo(t,y,i),i},e.prototype.xor=function(t){var i=a();return this.bitwiseTo(t,b,i),i},e.prototype.andNot=function(t){var i=a();return this.bitwiseTo(t,g,i),i},e.prototype.not=function(){for(var t=a(),i=0;i<this.t;++i)t.data[i]=this.DM&~this.data[i];return t.t=this.t,t.s=~this.s,t},e.prototype.shiftLeft=function(t){var i=a();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i},e.prototype.shiftRight=function(t){var i=a();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i},e.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this.data[t])return t*this.DB+D(this.data[t]);return this.s<0?this.t*this.DB:-1},e.prototype.bitCount=function(){for(var t=0,i=this.s&this.DM,r=0;r<this.t;++r)t+=B(this.data[r]^i);return t},e.prototype.testBit=function(t){var i=Math.floor(t/this.DB);return i>=this.t?0!=this.s:0!=(this.data[i]&1<<t%this.DB)},e.prototype.setBit=function(t){return this.changeBit(t,y)},e.prototype.clearBit=function(t){return this.changeBit(t,g)},e.prototype.flipBit=function(t){return this.changeBit(t,b)},e.prototype.add=function(t){var i=a();return this.addTo(t,i),i},e.prototype.subtract=function(t){var i=a();return this.subTo(t,i),i},e.prototype.multiply=function(t){var i=a();return this.multiplyTo(t,i),i},e.prototype.divide=function(t){var i=a();return this.divRemTo(t,i,null),i},e.prototype.remainder=function(t){var i=a();return this.divRemTo(t,null,i),i},e.prototype.divideAndRemainder=function(t){var i=a(),r=a();return this.divRemTo(t,i,r),new Array(i,r)},e.prototype.modPow=function(t,i){var r,o,s=t.bitLength(),e=c(1);if(s<=0)return e;r=s<18?1:s<48?3:s<144?4:s<768?5:6,o=s<8?new l(i):i.isEven()?new w(i):new v(i);var n=new Array,h=3,u=r-1,f=(1<<r)-1;if(n[1]=o.convert(this),r>1){var p=a();for(o.sqrTo(n[1],p);h<=f;)n[h]=a(),o.mulTo(p,n[h-2],n[h]),h+=2}var d,T,y=t.t-1,b=!0,g=a();for(s=m(t.data[y])-1;y>=0;){for(s>=u?d=t.data[y]>>s-u&f:(d=(t.data[y]&(1<<s+1)-1)<<u-s,y>0&&(d|=t.data[y-1]>>this.DB+s-u)),h=r;0==(1&d);)d>>=1,--h;if((s-=h)<0&&(s+=this.DB,--y),b)n[d].copyTo(e),b=!1;else{for(;h>1;)o.sqrTo(e,g),o.sqrTo(g,e),h-=2;h>0?o.sqrTo(e,g):(T=e,e=g,g=T),o.mulTo(g,n[d],e)}for(;y>=0&&0==(t.data[y]&1<<s);)o.sqrTo(e,g),T=e,e=g,g=T,--s<0&&(s=this.DB-1,--y)}return o.revert(e)},e.prototype.modInverse=function(t){if(0==this.signum())return e.ZERO;var i=t.isEven();if(this.isEven()&&i||0==t.signum())return e.ZERO;for(var r=t.clone(),o=this.clone(),s=c(1),a=c(0),n=c(0),h=c(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),i?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);for(;o.isEven();)o.rShiftTo(1,o),i?(n.isEven()&&h.isEven()||(n.addTo(this,n),h.subTo(t,h)),n.rShiftTo(1,n)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);r.compareTo(o)>=0?(r.subTo(o,r),i&&s.subTo(n,s),a.subTo(h,a)):(o.subTo(r,o),i&&n.subTo(s,n),h.subTo(a,h))}return 0!=o.compareTo(e.ONE)?e.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h},e.prototype.pow=function(t){return this.exp(t,new S)},e.prototype.gcd=function(t){var i=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(i.compareTo(r)<0){var o=i;i=r,r=o}var s=i.getLowestSetBit(),e=r.getLowestSetBit();if(e<0)return i;for(s<e&&(e=s),e>0&&(i.rShiftTo(e,i),r.rShiftTo(e,r));i.signum()>0;)(s=i.getLowestSetBit())>0&&i.rShiftTo(s,i),(s=r.getLowestSetBit())>0&&r.rShiftTo(s,r),i.compareTo(r)>=0?(i.subTo(r,i),i.rShiftTo(1,i)):(r.subTo(i,r),r.rShiftTo(1,r));return e>0&&r.lShiftTo(e,r),r},e.prototype.isProbablePrime=function(t){var i,r=this.abs();if(1==r.t&&r.data[0]<=E[E.length-1]){for(i=0;i<E.length;++i)if(r.data[0]==E[i])return!0;return!1}if(r.isEven())return!1;for(i=1;i<E.length;){for(var o=E[i],s=i+1;s<E.length&&o<O;)o*=E[s++];for(o=r.modInt(o);i<s;)if(o%E[i++]==0)return!1}return r.millerRabin(t)},e.prototype.square=function(){var t=a();return this.squareTo(t),t}}]); | ||
| //# sourceMappingURL=prime.worker.min.js.map |
+19
-0
@@ -383,2 +383,6 @@ /** | ||
| if(!_isCanonicalSignatureScalar(sm, 32)) { | ||
| return -1; | ||
| } | ||
| for(i = 0; i < n; ++i) { | ||
@@ -413,2 +417,17 @@ m[i] = sm[i]; | ||
| function _isCanonicalSignatureScalar(bytes, offset) { | ||
| var i; | ||
| // Compare little-endian scalar S against group order L and require S < L. | ||
| for(i = 31; i >= 0; --i) { | ||
| if(bytes[offset + i] < L[i]) { | ||
| return true; | ||
| } | ||
| if(bytes[offset + i] > L[i]) { | ||
| return false; | ||
| } | ||
| } | ||
| // S == L is non-canonical. | ||
| return false; | ||
| } | ||
| function modL(r, x) { | ||
@@ -415,0 +434,0 @@ var carry, i, j, k; |
+462
-432
@@ -127,6 +127,8 @@ // Copyright (c) 2005 Tom Wu | ||
| dbits = 30; | ||
| } else if(j_lm && (navigator.appName != "Netscape")) { | ||
| } | ||
| else if(j_lm && (navigator.appName != "Netscape")) { | ||
| BigInteger.prototype.am = am1; | ||
| dbits = 26; | ||
| } else { // Mozilla/Netscape seems to prefer am3 | ||
| } | ||
| else { // Mozilla/Netscape seems to prefer am3 | ||
| BigInteger.prototype.am = am3; | ||
@@ -206,3 +208,4 @@ dbits = 28; | ||
| this.data[this.t++] = (x>>(this.DB-sh)); | ||
| } else | ||
| } | ||
| else | ||
| this.data[this.t-1] |= x<<sh; | ||
@@ -244,3 +247,4 @@ sh += k; | ||
| d |= this.data[--i]>>(p+=this.DB-k); | ||
| } else { | ||
| } | ||
| else { | ||
| d = (this.data[i]>>(p-=k))&km; | ||
@@ -357,3 +361,4 @@ if(p <= 0) { p += this.DB; --i; } | ||
| c += this.s; | ||
| } else { | ||
| } | ||
| else { | ||
| c += this.s; | ||
@@ -418,3 +423,4 @@ while(i < a.t) { | ||
| var nsh = this.DB-nbits(pm.data[pm.t-1]); // normalize modulus | ||
| if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } else { pm.copyTo(y); pt.copyTo(r); } | ||
| if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } | ||
| else { pm.copyTo(y); pt.copyTo(r); } | ||
| var ys = y.t; | ||
@@ -616,130 +622,134 @@ var y0 = y.data[ys-1]; | ||
| //Copyright (c) 2005-2009 Tom Wu | ||
| //All Rights Reserved. | ||
| //See "LICENSE" for details (See jsbn.js for LICENSE). | ||
| // Copyright (c) 2005-2009 Tom Wu | ||
| // All Rights Reserved. | ||
| // See "LICENSE" for details (See jsbn.js for LICENSE). | ||
| //Extended JavaScript BN functions, required for RSA private ops. | ||
| // Extended JavaScript BN functions, required for RSA private ops. | ||
| //Version 1.1: new BigInteger("0", 10) returns "proper" zero | ||
| // Version 1.1: new BigInteger("0", 10) returns "proper" zero | ||
| // Version 1.2: square() API, isProbablePrime fix | ||
| //(public) | ||
| // (public) | ||
| function bnClone() { var r = nbi(); this.copyTo(r); return r; } | ||
| //(public) return value as integer | ||
| // (public) return value as integer | ||
| function bnIntValue() { | ||
| if(this.s < 0) { | ||
| if(this.t == 1) return this.data[0]-this.DV; | ||
| else if(this.t == 0) return -1; | ||
| } else if(this.t == 1) return this.data[0]; | ||
| else if(this.t == 0) return 0; | ||
| // assumes 16 < DB < 32 | ||
| return ((this.data[1]&((1<<(32-this.DB))-1))<<this.DB)|this.data[0]; | ||
| if(this.s < 0) { | ||
| if(this.t == 1) return this.data[0]-this.DV; | ||
| else if(this.t == 0) return -1; | ||
| } | ||
| else if(this.t == 1) return this.data[0]; | ||
| else if(this.t == 0) return 0; | ||
| // assumes 16 < DB < 32 | ||
| return ((this.data[1]&((1<<(32-this.DB))-1))<<this.DB)|this.data[0]; | ||
| } | ||
| //(public) return value as byte | ||
| // (public) return value as byte | ||
| function bnByteValue() { return (this.t==0)?this.s:(this.data[0]<<24)>>24; } | ||
| //(public) return value as short (assumes DB>=16) | ||
| // (public) return value as short (assumes DB>=16) | ||
| function bnShortValue() { return (this.t==0)?this.s:(this.data[0]<<16)>>16; } | ||
| //(protected) return x s.t. r^x < DV | ||
| // (protected) return x s.t. r^x < DV | ||
| function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); } | ||
| //(public) 0 if this == 0, 1 if this > 0 | ||
| // (public) 0 if this == 0, 1 if this > 0 | ||
| function bnSigNum() { | ||
| if(this.s < 0) return -1; | ||
| else if(this.t <= 0 || (this.t == 1 && this.data[0] <= 0)) return 0; | ||
| else return 1; | ||
| if(this.s < 0) return -1; | ||
| else if(this.t <= 0 || (this.t == 1 && this.data[0] <= 0)) return 0; | ||
| else return 1; | ||
| } | ||
| //(protected) convert to radix string | ||
| // (protected) convert to radix string | ||
| function bnpToRadix(b) { | ||
| if(b == null) b = 10; | ||
| if(this.signum() == 0 || b < 2 || b > 36) return "0"; | ||
| var cs = this.chunkSize(b); | ||
| var a = Math.pow(b,cs); | ||
| var d = nbv(a), y = nbi(), z = nbi(), r = ""; | ||
| this.divRemTo(d,y,z); | ||
| while(y.signum() > 0) { | ||
| r = (a+z.intValue()).toString(b).substr(1) + r; | ||
| y.divRemTo(d,y,z); | ||
| if(b == null) b = 10; | ||
| if(this.signum() == 0 || b < 2 || b > 36) return "0"; | ||
| var cs = this.chunkSize(b); | ||
| var a = Math.pow(b,cs); | ||
| var d = nbv(a), y = nbi(), z = nbi(), r = ""; | ||
| this.divRemTo(d,y,z); | ||
| while(y.signum() > 0) { | ||
| r = (a+z.intValue()).toString(b).substr(1) + r; | ||
| y.divRemTo(d,y,z); | ||
| } | ||
| return z.intValue().toString(b) + r; | ||
| } | ||
| return z.intValue().toString(b) + r; | ||
| } | ||
| //(protected) convert from radix string | ||
| // (protected) convert from radix string | ||
| function bnpFromRadix(s,b) { | ||
| this.fromInt(0); | ||
| if(b == null) b = 10; | ||
| var cs = this.chunkSize(b); | ||
| var d = Math.pow(b,cs), mi = false, j = 0, w = 0; | ||
| for(var i = 0; i < s.length; ++i) { | ||
| var x = intAt(s,i); | ||
| if(x < 0) { | ||
| if(s.charAt(i) == "-" && this.signum() == 0) mi = true; | ||
| continue; | ||
| } | ||
| w = b*w+x; | ||
| if(++j >= cs) { | ||
| this.dMultiply(d); | ||
| this.dAddOffset(w,0); | ||
| j = 0; | ||
| w = 0; | ||
| } | ||
| this.fromInt(0); | ||
| if(b == null) b = 10; | ||
| var cs = this.chunkSize(b); | ||
| var d = Math.pow(b,cs), mi = false, j = 0, w = 0; | ||
| for(var i = 0; i < s.length; ++i) { | ||
| var x = intAt(s,i); | ||
| if(x < 0) { | ||
| if(s.charAt(i) == "-" && this.signum() == 0) mi = true; | ||
| continue; | ||
| } | ||
| w = b*w+x; | ||
| if(++j >= cs) { | ||
| this.dMultiply(d); | ||
| this.dAddOffset(w,0); | ||
| j = 0; | ||
| w = 0; | ||
| } | ||
| } | ||
| if(j > 0) { | ||
| this.dMultiply(Math.pow(b,j)); | ||
| this.dAddOffset(w,0); | ||
| } | ||
| if(mi) BigInteger.ZERO.subTo(this,this); | ||
| } | ||
| if(j > 0) { | ||
| this.dMultiply(Math.pow(b,j)); | ||
| this.dAddOffset(w,0); | ||
| } | ||
| if(mi) BigInteger.ZERO.subTo(this,this); | ||
| } | ||
| //(protected) alternate constructor | ||
| // (protected) alternate constructor | ||
| function bnpFromNumber(a,b,c) { | ||
| if("number" == typeof b) { | ||
| // new BigInteger(int,int,RNG) | ||
| if(a < 2) this.fromInt(1); | ||
| else { | ||
| this.fromNumber(a,c); | ||
| if(!this.testBit(a-1)) // force MSB set | ||
| this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this); | ||
| if(this.isEven()) this.dAddOffset(1,0); // force odd | ||
| while(!this.isProbablePrime(b)) { | ||
| this.dAddOffset(2,0); | ||
| if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this); | ||
| } | ||
| } | ||
| } else { | ||
| // new BigInteger(int,RNG) | ||
| var x = new Array(), t = a&7; | ||
| x.length = (a>>3)+1; | ||
| b.nextBytes(x); | ||
| if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0; | ||
| this.fromString(x,256); | ||
| if("number" == typeof b) { | ||
| // new BigInteger(int,int,RNG) | ||
| if(a < 2) this.fromInt(1); | ||
| else { | ||
| this.fromNumber(a,c); | ||
| if(!this.testBit(a-1)) // force MSB set | ||
| this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this); | ||
| if(this.isEven()) this.dAddOffset(1,0); // force odd | ||
| while(!this.isProbablePrime(b)) { | ||
| this.dAddOffset(2,0); | ||
| if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this); | ||
| } | ||
| } | ||
| } | ||
| else { | ||
| // new BigInteger(int,RNG) | ||
| var x = new Array(), t = a&7; | ||
| x.length = (a>>3)+1; | ||
| b.nextBytes(x); | ||
| if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0; | ||
| this.fromString(x,256); | ||
| } | ||
| } | ||
| } | ||
| //(public) convert to bigendian byte array | ||
| // (public) convert to bigendian byte array | ||
| function bnToByteArray() { | ||
| var i = this.t, r = new Array(); | ||
| r[0] = this.s; | ||
| var p = this.DB-(i*this.DB)%8, d, k = 0; | ||
| if(i-- > 0) { | ||
| if(p < this.DB && (d = this.data[i]>>p) != (this.s&this.DM)>>p) | ||
| r[k++] = d|(this.s<<(this.DB-p)); | ||
| while(i >= 0) { | ||
| if(p < 8) { | ||
| d = (this.data[i]&((1<<p)-1))<<(8-p); | ||
| d |= this.data[--i]>>(p+=this.DB-8); | ||
| } else { | ||
| d = (this.data[i]>>(p-=8))&0xff; | ||
| if(p <= 0) { p += this.DB; --i; } | ||
| } | ||
| if((d&0x80) != 0) d |= -256; | ||
| if(k == 0 && (this.s&0x80) != (d&0x80)) ++k; | ||
| if(k > 0 || d != this.s) r[k++] = d; | ||
| } | ||
| var i = this.t, r = new Array(); | ||
| r[0] = this.s; | ||
| var p = this.DB-(i*this.DB)%8, d, k = 0; | ||
| if(i-- > 0) { | ||
| if(p < this.DB && (d = this.data[i]>>p) != (this.s&this.DM)>>p) | ||
| r[k++] = d|(this.s<<(this.DB-p)); | ||
| while(i >= 0) { | ||
| if(p < 8) { | ||
| d = (this.data[i]&((1<<p)-1))<<(8-p); | ||
| d |= this.data[--i]>>(p+=this.DB-8); | ||
| } | ||
| else { | ||
| d = (this.data[i]>>(p-=8))&0xff; | ||
| if(p <= 0) { p += this.DB; --i; } | ||
| } | ||
| if((d&0x80) != 0) d |= -256; | ||
| if(k == 0 && (this.s&0x80) != (d&0x80)) ++k; | ||
| if(k > 0 || d != this.s) r[k++] = d; | ||
| } | ||
| } | ||
| return r; | ||
| } | ||
| return r; | ||
| } | ||
@@ -750,189 +760,194 @@ function bnEquals(a) { return(this.compareTo(a)==0); } | ||
| //(protected) r = this op a (bitwise) | ||
| // (protected) r = this op a (bitwise) | ||
| function bnpBitwiseTo(a,op,r) { | ||
| var i, f, m = Math.min(a.t,this.t); | ||
| for(i = 0; i < m; ++i) r.data[i] = op(this.data[i],a.data[i]); | ||
| if(a.t < this.t) { | ||
| f = a.s&this.DM; | ||
| for(i = m; i < this.t; ++i) r.data[i] = op(this.data[i],f); | ||
| r.t = this.t; | ||
| } else { | ||
| f = this.s&this.DM; | ||
| for(i = m; i < a.t; ++i) r.data[i] = op(f,a.data[i]); | ||
| r.t = a.t; | ||
| var i, f, m = Math.min(a.t,this.t); | ||
| for(i = 0; i < m; ++i) r.data[i] = op(this.data[i],a.data[i]); | ||
| if(a.t < this.t) { | ||
| f = a.s&this.DM; | ||
| for(i = m; i < this.t; ++i) r.data[i] = op(this.data[i],f); | ||
| r.t = this.t; | ||
| } | ||
| else { | ||
| f = this.s&this.DM; | ||
| for(i = m; i < a.t; ++i) r.data[i] = op(f,a.data[i]); | ||
| r.t = a.t; | ||
| } | ||
| r.s = op(this.s,a.s); | ||
| r.clamp(); | ||
| } | ||
| r.s = op(this.s,a.s); | ||
| r.clamp(); | ||
| } | ||
| //(public) this & a | ||
| // (public) this & a | ||
| function op_and(x,y) { return x&y; } | ||
| function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; } | ||
| //(public) this | a | ||
| // (public) this | a | ||
| function op_or(x,y) { return x|y; } | ||
| function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; } | ||
| //(public) this ^ a | ||
| // (public) this ^ a | ||
| function op_xor(x,y) { return x^y; } | ||
| function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; } | ||
| //(public) this & ~a | ||
| // (public) this & ~a | ||
| function op_andnot(x,y) { return x&~y; } | ||
| function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; } | ||
| //(public) ~this | ||
| // (public) ~this | ||
| function bnNot() { | ||
| var r = nbi(); | ||
| for(var i = 0; i < this.t; ++i) r.data[i] = this.DM&~this.data[i]; | ||
| r.t = this.t; | ||
| r.s = ~this.s; | ||
| return r; | ||
| var r = nbi(); | ||
| for(var i = 0; i < this.t; ++i) r.data[i] = this.DM&~this.data[i]; | ||
| r.t = this.t; | ||
| r.s = ~this.s; | ||
| return r; | ||
| } | ||
| //(public) this << n | ||
| // (public) this << n | ||
| function bnShiftLeft(n) { | ||
| var r = nbi(); | ||
| if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r); | ||
| return r; | ||
| var r = nbi(); | ||
| if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r); | ||
| return r; | ||
| } | ||
| //(public) this >> n | ||
| // (public) this >> n | ||
| function bnShiftRight(n) { | ||
| var r = nbi(); | ||
| if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r); | ||
| return r; | ||
| var r = nbi(); | ||
| if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r); | ||
| return r; | ||
| } | ||
| //return index of lowest 1-bit in x, x < 2^31 | ||
| // return index of lowest 1-bit in x, x < 2^31 | ||
| function lbit(x) { | ||
| if(x == 0) return -1; | ||
| var r = 0; | ||
| if((x&0xffff) == 0) { x >>= 16; r += 16; } | ||
| if((x&0xff) == 0) { x >>= 8; r += 8; } | ||
| if((x&0xf) == 0) { x >>= 4; r += 4; } | ||
| if((x&3) == 0) { x >>= 2; r += 2; } | ||
| if((x&1) == 0) ++r; | ||
| return r; | ||
| if(x == 0) return -1; | ||
| var r = 0; | ||
| if((x&0xffff) == 0) { x >>= 16; r += 16; } | ||
| if((x&0xff) == 0) { x >>= 8; r += 8; } | ||
| if((x&0xf) == 0) { x >>= 4; r += 4; } | ||
| if((x&3) == 0) { x >>= 2; r += 2; } | ||
| if((x&1) == 0) ++r; | ||
| return r; | ||
| } | ||
| //(public) returns index of lowest 1-bit (or -1 if none) | ||
| // (public) returns index of lowest 1-bit (or -1 if none) | ||
| function bnGetLowestSetBit() { | ||
| for(var i = 0; i < this.t; ++i) | ||
| if(this.data[i] != 0) return i*this.DB+lbit(this.data[i]); | ||
| if(this.s < 0) return this.t*this.DB; | ||
| return -1; | ||
| for(var i = 0; i < this.t; ++i) | ||
| if(this.data[i] != 0) return i*this.DB+lbit(this.data[i]); | ||
| if(this.s < 0) return this.t*this.DB; | ||
| return -1; | ||
| } | ||
| //return number of 1 bits in x | ||
| // return number of 1 bits in x | ||
| function cbit(x) { | ||
| var r = 0; | ||
| while(x != 0) { x &= x-1; ++r; } | ||
| return r; | ||
| var r = 0; | ||
| while(x != 0) { x &= x-1; ++r; } | ||
| return r; | ||
| } | ||
| //(public) return number of set bits | ||
| // (public) return number of set bits | ||
| function bnBitCount() { | ||
| var r = 0, x = this.s&this.DM; | ||
| for(var i = 0; i < this.t; ++i) r += cbit(this.data[i]^x); | ||
| return r; | ||
| var r = 0, x = this.s&this.DM; | ||
| for(var i = 0; i < this.t; ++i) r += cbit(this.data[i]^x); | ||
| return r; | ||
| } | ||
| //(public) true iff nth bit is set | ||
| // (public) true iff nth bit is set | ||
| function bnTestBit(n) { | ||
| var j = Math.floor(n/this.DB); | ||
| if(j >= this.t) return(this.s!=0); | ||
| return((this.data[j]&(1<<(n%this.DB)))!=0); | ||
| var j = Math.floor(n/this.DB); | ||
| if(j >= this.t) return(this.s!=0); | ||
| return((this.data[j]&(1<<(n%this.DB)))!=0); | ||
| } | ||
| //(protected) this op (1<<n) | ||
| // (protected) this op (1<<n) | ||
| function bnpChangeBit(n,op) { | ||
| var r = BigInteger.ONE.shiftLeft(n); | ||
| this.bitwiseTo(r,op,r); | ||
| return r; | ||
| var r = BigInteger.ONE.shiftLeft(n); | ||
| this.bitwiseTo(r,op,r); | ||
| return r; | ||
| } | ||
| //(public) this | (1<<n) | ||
| // (public) this | (1<<n) | ||
| function bnSetBit(n) { return this.changeBit(n,op_or); } | ||
| //(public) this & ~(1<<n) | ||
| // (public) this & ~(1<<n) | ||
| function bnClearBit(n) { return this.changeBit(n,op_andnot); } | ||
| //(public) this ^ (1<<n) | ||
| // (public) this ^ (1<<n) | ||
| function bnFlipBit(n) { return this.changeBit(n,op_xor); } | ||
| //(protected) r = this + a | ||
| // (protected) r = this + a | ||
| function bnpAddTo(a,r) { | ||
| var i = 0, c = 0, m = Math.min(a.t,this.t); | ||
| while(i < m) { | ||
| c += this.data[i]+a.data[i]; | ||
| r.data[i++] = c&this.DM; | ||
| c >>= this.DB; | ||
| var i = 0, c = 0, m = Math.min(a.t,this.t); | ||
| while(i < m) { | ||
| c += this.data[i]+a.data[i]; | ||
| r.data[i++] = c&this.DM; | ||
| c >>= this.DB; | ||
| } | ||
| if(a.t < this.t) { | ||
| c += a.s; | ||
| while(i < this.t) { | ||
| c += this.data[i]; | ||
| r.data[i++] = c&this.DM; | ||
| c >>= this.DB; | ||
| } | ||
| c += this.s; | ||
| } | ||
| else { | ||
| c += this.s; | ||
| while(i < a.t) { | ||
| c += a.data[i]; | ||
| r.data[i++] = c&this.DM; | ||
| c >>= this.DB; | ||
| } | ||
| c += a.s; | ||
| } | ||
| r.s = (c<0)?-1:0; | ||
| if(c > 0) r.data[i++] = c; | ||
| else if(c < -1) r.data[i++] = this.DV+c; | ||
| r.t = i; | ||
| r.clamp(); | ||
| } | ||
| if(a.t < this.t) { | ||
| c += a.s; | ||
| while(i < this.t) { | ||
| c += this.data[i]; | ||
| r.data[i++] = c&this.DM; | ||
| c >>= this.DB; | ||
| } | ||
| c += this.s; | ||
| } else { | ||
| c += this.s; | ||
| while(i < a.t) { | ||
| c += a.data[i]; | ||
| r.data[i++] = c&this.DM; | ||
| c >>= this.DB; | ||
| } | ||
| c += a.s; | ||
| } | ||
| r.s = (c<0)?-1:0; | ||
| if(c > 0) r.data[i++] = c; | ||
| else if(c < -1) r.data[i++] = this.DV+c; | ||
| r.t = i; | ||
| r.clamp(); | ||
| } | ||
| //(public) this + a | ||
| // (public) this + a | ||
| function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; } | ||
| //(public) this - a | ||
| // (public) this - a | ||
| function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; } | ||
| //(public) this * a | ||
| // (public) this * a | ||
| function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; } | ||
| //(public) this / a | ||
| // (public) this^2 | ||
| function bnSquare() { var r = nbi(); this.squareTo(r); return r; } | ||
| // (public) this / a | ||
| function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; } | ||
| //(public) this % a | ||
| // (public) this % a | ||
| function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; } | ||
| //(public) [this/a,this%a] | ||
| // (public) [this/a,this%a] | ||
| function bnDivideAndRemainder(a) { | ||
| var q = nbi(), r = nbi(); | ||
| this.divRemTo(a,q,r); | ||
| return new Array(q,r); | ||
| var q = nbi(), r = nbi(); | ||
| this.divRemTo(a,q,r); | ||
| return new Array(q,r); | ||
| } | ||
| //(protected) this *= n, this >= 0, 1 < n < DV | ||
| // (protected) this *= n, this >= 0, 1 < n < DV | ||
| function bnpDMultiply(n) { | ||
| this.data[this.t] = this.am(0,n-1,this,0,0,this.t); | ||
| ++this.t; | ||
| this.clamp(); | ||
| this.data[this.t] = this.am(0,n-1,this,0,0,this.t); | ||
| ++this.t; | ||
| this.clamp(); | ||
| } | ||
| //(protected) this += n << w words, this >= 0 | ||
| // (protected) this += n << w words, this >= 0 | ||
| function bnpDAddOffset(n,w) { | ||
| if(n == 0) return; | ||
| while(this.t <= w) this.data[this.t++] = 0; | ||
| this.data[w] += n; | ||
| while(this.data[w] >= this.DV) { | ||
| this.data[w] -= this.DV; | ||
| if(++w >= this.t) this.data[this.t++] = 0; | ||
| ++this.data[w]; | ||
| if(n == 0) return; | ||
| while(this.t <= w) this.data[this.t++] = 0; | ||
| this.data[w] += n; | ||
| while(this.data[w] >= this.DV) { | ||
| this.data[w] -= this.DV; | ||
| if(++w >= this.t) this.data[this.t++] = 0; | ||
| ++this.data[w]; | ||
| } | ||
| } | ||
| } | ||
| //A "null" reducer | ||
| // A "null" reducer | ||
| function NullExp() {} | ||
@@ -948,45 +963,45 @@ function nNop(x) { return x; } | ||
| //(public) this^e | ||
| // (public) this^e | ||
| function bnPow(e) { return this.exp(e,new NullExp()); } | ||
| //(protected) r = lower n words of "this * a", a.t <= n | ||
| //"this" should be the larger one if appropriate. | ||
| // (protected) r = lower n words of "this * a", a.t <= n | ||
| // "this" should be the larger one if appropriate. | ||
| function bnpMultiplyLowerTo(a,n,r) { | ||
| var i = Math.min(this.t+a.t,n); | ||
| r.s = 0; // assumes a,this >= 0 | ||
| r.t = i; | ||
| while(i > 0) r.data[--i] = 0; | ||
| var j; | ||
| for(j = r.t-this.t; i < j; ++i) r.data[i+this.t] = this.am(0,a.data[i],r,i,0,this.t); | ||
| for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a.data[i],r,i,0,n-i); | ||
| r.clamp(); | ||
| var i = Math.min(this.t+a.t,n); | ||
| r.s = 0; // assumes a,this >= 0 | ||
| r.t = i; | ||
| while(i > 0) r.data[--i] = 0; | ||
| var j; | ||
| for(j = r.t-this.t; i < j; ++i) r.data[i+this.t] = this.am(0,a.data[i],r,i,0,this.t); | ||
| for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a.data[i],r,i,0,n-i); | ||
| r.clamp(); | ||
| } | ||
| //(protected) r = "this * a" without lower n words, n > 0 | ||
| //"this" should be the larger one if appropriate. | ||
| // (protected) r = "this * a" without lower n words, n > 0 | ||
| // "this" should be the larger one if appropriate. | ||
| function bnpMultiplyUpperTo(a,n,r) { | ||
| --n; | ||
| var i = r.t = this.t+a.t-n; | ||
| r.s = 0; // assumes a,this >= 0 | ||
| while(--i >= 0) r.data[i] = 0; | ||
| for(i = Math.max(n-this.t,0); i < a.t; ++i) | ||
| r.data[this.t+i-n] = this.am(n-i,a.data[i],r,0,0,this.t+i-n); | ||
| r.clamp(); | ||
| r.drShiftTo(1,r); | ||
| --n; | ||
| var i = r.t = this.t+a.t-n; | ||
| r.s = 0; // assumes a,this >= 0 | ||
| while(--i >= 0) r.data[i] = 0; | ||
| for(i = Math.max(n-this.t,0); i < a.t; ++i) | ||
| r.data[this.t+i-n] = this.am(n-i,a.data[i],r,0,0,this.t+i-n); | ||
| r.clamp(); | ||
| r.drShiftTo(1,r); | ||
| } | ||
| //Barrett modular reduction | ||
| // Barrett modular reduction | ||
| function Barrett(m) { | ||
| // setup Barrett | ||
| this.r2 = nbi(); | ||
| this.q3 = nbi(); | ||
| BigInteger.ONE.dlShiftTo(2*m.t,this.r2); | ||
| this.mu = this.r2.divide(m); | ||
| this.m = m; | ||
| // setup Barrett | ||
| this.r2 = nbi(); | ||
| this.q3 = nbi(); | ||
| BigInteger.ONE.dlShiftTo(2*m.t,this.r2); | ||
| this.mu = this.r2.divide(m); | ||
| this.m = m; | ||
| } | ||
| function barrettConvert(x) { | ||
| if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m); | ||
| else if(x.compareTo(this.m) < 0) return x; | ||
| else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; } | ||
| if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m); | ||
| else if(x.compareTo(this.m) < 0) return x; | ||
| else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; } | ||
| } | ||
@@ -996,17 +1011,17 @@ | ||
| //x = x mod m (HAC 14.42) | ||
| // x = x mod m (HAC 14.42) | ||
| function barrettReduce(x) { | ||
| x.drShiftTo(this.m.t-1,this.r2); | ||
| if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); } | ||
| this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3); | ||
| this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2); | ||
| while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1); | ||
| x.subTo(this.r2,x); | ||
| while(x.compareTo(this.m) >= 0) x.subTo(this.m,x); | ||
| x.drShiftTo(this.m.t-1,this.r2); | ||
| if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); } | ||
| this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3); | ||
| this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2); | ||
| while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1); | ||
| x.subTo(this.r2,x); | ||
| while(x.compareTo(this.m) >= 0) x.subTo(this.m,x); | ||
| } | ||
| //r = x^2 mod m; x != r | ||
| // r = x^2 mod m; x != r | ||
| function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); } | ||
| //r = x*y mod m; x,y != r | ||
| // r = x*y mod m; x,y != r | ||
| function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } | ||
@@ -1020,184 +1035,196 @@ | ||
| //(public) this^e % m (HAC 14.85) | ||
| // (public) this^e % m (HAC 14.85) | ||
| function bnModPow(e,m) { | ||
| var i = e.bitLength(), k, r = nbv(1), z; | ||
| if(i <= 0) return r; | ||
| else if(i < 18) k = 1; | ||
| else if(i < 48) k = 3; | ||
| else if(i < 144) k = 4; | ||
| else if(i < 768) k = 5; | ||
| else k = 6; | ||
| if(i < 8) | ||
| z = new Classic(m); | ||
| else if(m.isEven()) | ||
| z = new Barrett(m); | ||
| else | ||
| z = new Montgomery(m); | ||
| var i = e.bitLength(), k, r = nbv(1), z; | ||
| if(i <= 0) return r; | ||
| else if(i < 18) k = 1; | ||
| else if(i < 48) k = 3; | ||
| else if(i < 144) k = 4; | ||
| else if(i < 768) k = 5; | ||
| else k = 6; | ||
| if(i < 8) | ||
| z = new Classic(m); | ||
| else if(m.isEven()) | ||
| z = new Barrett(m); | ||
| else | ||
| z = new Montgomery(m); | ||
| // precomputation | ||
| var g = new Array(), n = 3, k1 = k-1, km = (1<<k)-1; | ||
| g[1] = z.convert(this); | ||
| if(k > 1) { | ||
| var g2 = nbi(); | ||
| z.sqrTo(g[1],g2); | ||
| while(n <= km) { | ||
| g[n] = nbi(); | ||
| z.mulTo(g2,g[n-2],g[n]); | ||
| n += 2; | ||
| } | ||
| } | ||
| // precomputation | ||
| var g = new Array(), n = 3, k1 = k-1, km = (1<<k)-1; | ||
| g[1] = z.convert(this); | ||
| if(k > 1) { | ||
| var g2 = nbi(); | ||
| z.sqrTo(g[1],g2); | ||
| while(n <= km) { | ||
| g[n] = nbi(); | ||
| z.mulTo(g2,g[n-2],g[n]); | ||
| n += 2; | ||
| } | ||
| } | ||
| var j = e.t-1, w, is1 = true, r2 = nbi(), t; | ||
| i = nbits(e.data[j])-1; | ||
| while(j >= 0) { | ||
| if(i >= k1) w = (e.data[j]>>(i-k1))&km; | ||
| else { | ||
| w = (e.data[j]&((1<<(i+1))-1))<<(k1-i); | ||
| if(j > 0) w |= e.data[j-1]>>(this.DB+i-k1); | ||
| } | ||
| var j = e.t-1, w, is1 = true, r2 = nbi(), t; | ||
| i = nbits(e.data[j])-1; | ||
| while(j >= 0) { | ||
| if(i >= k1) w = (e.data[j]>>(i-k1))&km; | ||
| else { | ||
| w = (e.data[j]&((1<<(i+1))-1))<<(k1-i); | ||
| if(j > 0) w |= e.data[j-1]>>(this.DB+i-k1); | ||
| } | ||
| n = k; | ||
| while((w&1) == 0) { w >>= 1; --n; } | ||
| if((i -= n) < 0) { i += this.DB; --j; } | ||
| if(is1) { // ret == 1, don't bother squaring or multiplying it | ||
| g[w].copyTo(r); | ||
| is1 = false; | ||
| } else { | ||
| while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; } | ||
| if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; } | ||
| z.mulTo(r2,g[w],r); | ||
| } | ||
| n = k; | ||
| while((w&1) == 0) { w >>= 1; --n; } | ||
| if((i -= n) < 0) { i += this.DB; --j; } | ||
| if(is1) { // ret == 1, don't bother squaring or multiplying it | ||
| g[w].copyTo(r); | ||
| is1 = false; | ||
| } | ||
| else { | ||
| while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; } | ||
| if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; } | ||
| z.mulTo(r2,g[w],r); | ||
| } | ||
| while(j >= 0 && (e.data[j]&(1<<i)) == 0) { | ||
| z.sqrTo(r,r2); t = r; r = r2; r2 = t; | ||
| if(--i < 0) { i = this.DB-1; --j; } | ||
| } | ||
| while(j >= 0 && (e.data[j]&(1<<i)) == 0) { | ||
| z.sqrTo(r,r2); t = r; r = r2; r2 = t; | ||
| if(--i < 0) { i = this.DB-1; --j; } | ||
| } | ||
| } | ||
| return z.revert(r); | ||
| } | ||
| return z.revert(r); | ||
| } | ||
| //(public) gcd(this,a) (HAC 14.54) | ||
| // (public) gcd(this,a) (HAC 14.54) | ||
| function bnGCD(a) { | ||
| var x = (this.s<0)?this.negate():this.clone(); | ||
| var y = (a.s<0)?a.negate():a.clone(); | ||
| if(x.compareTo(y) < 0) { var t = x; x = y; y = t; } | ||
| var i = x.getLowestSetBit(), g = y.getLowestSetBit(); | ||
| if(g < 0) return x; | ||
| if(i < g) g = i; | ||
| if(g > 0) { | ||
| x.rShiftTo(g,x); | ||
| y.rShiftTo(g,y); | ||
| var x = (this.s<0)?this.negate():this.clone(); | ||
| var y = (a.s<0)?a.negate():a.clone(); | ||
| if(x.compareTo(y) < 0) { var t = x; x = y; y = t; } | ||
| var i = x.getLowestSetBit(), g = y.getLowestSetBit(); | ||
| if(g < 0) return x; | ||
| if(i < g) g = i; | ||
| if(g > 0) { | ||
| x.rShiftTo(g,x); | ||
| y.rShiftTo(g,y); | ||
| } | ||
| while(x.signum() > 0) { | ||
| if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x); | ||
| if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y); | ||
| if(x.compareTo(y) >= 0) { | ||
| x.subTo(y,x); | ||
| x.rShiftTo(1,x); | ||
| } | ||
| else { | ||
| y.subTo(x,y); | ||
| y.rShiftTo(1,y); | ||
| } | ||
| } | ||
| if(g > 0) y.lShiftTo(g,y); | ||
| return y; | ||
| } | ||
| while(x.signum() > 0) { | ||
| if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x); | ||
| if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y); | ||
| if(x.compareTo(y) >= 0) { | ||
| x.subTo(y,x); | ||
| x.rShiftTo(1,x); | ||
| } else { | ||
| y.subTo(x,y); | ||
| y.rShiftTo(1,y); | ||
| } | ||
| } | ||
| if(g > 0) y.lShiftTo(g,y); | ||
| return y; | ||
| } | ||
| //(protected) this % n, n < 2^26 | ||
| // (protected) this % n, n < 2^26 | ||
| function bnpModInt(n) { | ||
| if(n <= 0) return 0; | ||
| var d = this.DV%n, r = (this.s<0)?n-1:0; | ||
| if(this.t > 0) | ||
| if(d == 0) r = this.data[0]%n; | ||
| else for(var i = this.t-1; i >= 0; --i) r = (d*r+this.data[i])%n; | ||
| return r; | ||
| if(n <= 0) return 0; | ||
| var d = this.DV%n, r = (this.s<0)?n-1:0; | ||
| if(this.t > 0) | ||
| if(d == 0) r = this.data[0]%n; | ||
| else for(var i = this.t-1; i >= 0; --i) r = (d*r+this.data[i])%n; | ||
| return r; | ||
| } | ||
| //(public) 1/this % m (HAC 14.61) | ||
| // (public) 1/this % m (HAC 14.61) | ||
| function bnModInverse(m) { | ||
| var ac = m.isEven(); | ||
| if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; | ||
| var u = m.clone(), v = this.clone(); | ||
| var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); | ||
| while(u.signum() != 0) { | ||
| while(u.isEven()) { | ||
| u.rShiftTo(1,u); | ||
| if(ac) { | ||
| if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); } | ||
| a.rShiftTo(1,a); | ||
| } else if(!b.isEven()) b.subTo(m,b); | ||
| b.rShiftTo(1,b); | ||
| } | ||
| while(v.isEven()) { | ||
| v.rShiftTo(1,v); | ||
| if(ac) { | ||
| if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); } | ||
| c.rShiftTo(1,c); | ||
| } else if(!d.isEven()) d.subTo(m,d); | ||
| d.rShiftTo(1,d); | ||
| } | ||
| if(u.compareTo(v) >= 0) { | ||
| u.subTo(v,u); | ||
| if(ac) a.subTo(c,a); | ||
| b.subTo(d,b); | ||
| } else { | ||
| v.subTo(u,v); | ||
| if(ac) c.subTo(a,c); | ||
| d.subTo(b,d); | ||
| } | ||
| // FORGE: jsbn fix | ||
| // avoid infinite loop | ||
| if(this.signum() == 0) { | ||
| // returning zero to align with similar behavior when no multiplicative | ||
| // inverse module m is found. | ||
| return BigInteger.ZERO; | ||
| } | ||
| var ac = m.isEven(); | ||
| if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; | ||
| var u = m.clone(), v = this.clone(); | ||
| var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); | ||
| while(u.signum() != 0) { | ||
| while(u.isEven()) { | ||
| u.rShiftTo(1,u); | ||
| if(ac) { | ||
| if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); } | ||
| a.rShiftTo(1,a); | ||
| } | ||
| else if(!b.isEven()) b.subTo(m,b); | ||
| b.rShiftTo(1,b); | ||
| } | ||
| while(v.isEven()) { | ||
| v.rShiftTo(1,v); | ||
| if(ac) { | ||
| if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); } | ||
| c.rShiftTo(1,c); | ||
| } | ||
| else if(!d.isEven()) d.subTo(m,d); | ||
| d.rShiftTo(1,d); | ||
| } | ||
| if(u.compareTo(v) >= 0) { | ||
| u.subTo(v,u); | ||
| if(ac) a.subTo(c,a); | ||
| b.subTo(d,b); | ||
| } | ||
| else { | ||
| v.subTo(u,v); | ||
| if(ac) c.subTo(a,c); | ||
| d.subTo(b,d); | ||
| } | ||
| } | ||
| if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; | ||
| if(d.compareTo(m) >= 0) return d.subtract(m); | ||
| if(d.signum() < 0) d.addTo(m,d); else return d; | ||
| if(d.signum() < 0) return d.add(m); else return d; | ||
| } | ||
| if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; | ||
| if(d.compareTo(m) >= 0) return d.subtract(m); | ||
| if(d.signum() < 0) d.addTo(m,d); else return d; | ||
| if(d.signum() < 0) return d.add(m); else return d; | ||
| } | ||
| 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]; | ||
| 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]; | ||
| var lplim = (1<<26)/lowprimes[lowprimes.length-1]; | ||
| //(public) test primality with certainty >= 1-.5^t | ||
| // (public) test primality with certainty >= 1-.5^t | ||
| function bnIsProbablePrime(t) { | ||
| var i, x = this.abs(); | ||
| if(x.t == 1 && x.data[0] <= lowprimes[lowprimes.length-1]) { | ||
| for(i = 0; i < lowprimes.length; ++i) | ||
| if(x.data[0] == lowprimes[i]) return true; | ||
| return false; | ||
| var i, x = this.abs(); | ||
| if(x.t == 1 && x.data[0] <= lowprimes[lowprimes.length-1]) { | ||
| for(i = 0; i < lowprimes.length; ++i) | ||
| if(x.data[0] == lowprimes[i]) return true; | ||
| return false; | ||
| } | ||
| if(x.isEven()) return false; | ||
| i = 1; | ||
| while(i < lowprimes.length) { | ||
| var m = lowprimes[i], j = i+1; | ||
| while(j < lowprimes.length && m < lplim) m *= lowprimes[j++]; | ||
| m = x.modInt(m); | ||
| while(i < j) if(m%lowprimes[i++] == 0) return false; | ||
| } | ||
| return x.millerRabin(t); | ||
| } | ||
| if(x.isEven()) return false; | ||
| i = 1; | ||
| while(i < lowprimes.length) { | ||
| var m = lowprimes[i], j = i+1; | ||
| while(j < lowprimes.length && m < lplim) m *= lowprimes[j++]; | ||
| m = x.modInt(m); | ||
| while(i < j) if(m%lowprimes[i++] == 0) return false; | ||
| } | ||
| return x.millerRabin(t); | ||
| } | ||
| //(protected) true if probably prime (HAC 4.24, Miller-Rabin) | ||
| // (protected) true if probably prime (HAC 4.24, Miller-Rabin) | ||
| function bnpMillerRabin(t) { | ||
| var n1 = this.subtract(BigInteger.ONE); | ||
| var k = n1.getLowestSetBit(); | ||
| if(k <= 0) return false; | ||
| var r = n1.shiftRight(k); | ||
| var prng = bnGetPrng(); | ||
| var a; | ||
| for(var i = 0; i < t; ++i) { | ||
| // select witness 'a' at random from between 1 and n1 | ||
| do { | ||
| a = new BigInteger(this.bitLength(), prng); | ||
| } | ||
| while(a.compareTo(BigInteger.ONE) <= 0 || a.compareTo(n1) >= 0); | ||
| var y = a.modPow(r,this); | ||
| if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { | ||
| var j = 1; | ||
| while(j++ < k && y.compareTo(n1) != 0) { | ||
| y = y.modPowInt(2,this); | ||
| if(y.compareTo(BigInteger.ONE) == 0) return false; | ||
| } | ||
| if(y.compareTo(n1) != 0) return false; | ||
| } | ||
| var n1 = this.subtract(BigInteger.ONE); | ||
| var k = n1.getLowestSetBit(); | ||
| if(k <= 0) return false; | ||
| var r = n1.shiftRight(k); | ||
| var prng = bnGetPrng(); | ||
| var a; | ||
| for(var i = 0; i < t; ++i) { | ||
| // select witness 'a' at random from between 1 and n1 | ||
| do { | ||
| a = new BigInteger(this.bitLength(), prng); | ||
| } | ||
| while(a.compareTo(BigInteger.ONE) <= 0 || a.compareTo(n1) >= 0); | ||
| var y = a.modPow(r,this); | ||
| if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { | ||
| var j = 1; | ||
| while(j++ < k && y.compareTo(n1) != 0) { | ||
| y = y.modPowInt(2,this); | ||
| if(y.compareTo(BigInteger.ONE) == 0) return false; | ||
| } | ||
| if(y.compareTo(n1) != 0) return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| return true; | ||
| } | ||
@@ -1217,3 +1244,3 @@ // get pseudo random number generator | ||
| //protected | ||
| // protected | ||
| BigInteger.prototype.chunkSize = bnpChunkSize; | ||
@@ -1233,3 +1260,3 @@ BigInteger.prototype.toRadix = bnpToRadix; | ||
| //public | ||
| // public | ||
| BigInteger.prototype.clone = bnClone; | ||
@@ -1269,9 +1296,12 @@ BigInteger.prototype.intValue = bnIntValue; | ||
| //BigInteger interfaces not implemented in jsbn: | ||
| // JSBN-specific extension | ||
| BigInteger.prototype.square = bnSquare; | ||
| //BigInteger(int signum, byte[] magnitude) | ||
| //double doubleValue() | ||
| //float floatValue() | ||
| //int hashCode() | ||
| //long longValue() | ||
| //static BigInteger valueOf(long val) | ||
| // BigInteger interfaces not implemented in jsbn: | ||
| // BigInteger(int signum, byte[] magnitude) | ||
| // double doubleValue() | ||
| // float floatValue() | ||
| // int hashCode() | ||
| // long longValue() | ||
| // static BigInteger valueOf(long val) |
+1
-0
@@ -126,2 +126,3 @@ /** | ||
| _IN('2.5.4.42', 'givenName'); | ||
| _IN('2.5.4.65', 'pseudonym'); | ||
| _IN('1.3.6.1.4.1.311.60.2.1.2', 'jurisdictionOfIncorporationStateOrProvinceName'); | ||
@@ -128,0 +129,0 @@ _IN('1.3.6.1.4.1.311.60.2.1.3', 'jurisdictionOfIncorporationCountryName'); |
+26
-7
@@ -1136,2 +1136,5 @@ /** | ||
| * (default: true) | ||
| * _skipPaddingChecks testing flag to skip some padding checks to | ||
| * test other checks. Unsupported and not for general usage. | ||
| * (default: false) | ||
| * | ||
@@ -1148,3 +1151,4 @@ * @return true if the signature was verified, false if not. | ||
| options = { | ||
| _parseAllDigestBytes: true | ||
| _parseAllDigestBytes: true, | ||
| _skipPaddingChecks: false | ||
| }; | ||
@@ -1155,2 +1159,5 @@ } | ||
| } | ||
| if(!('_skipPaddingChecks' in options)) { | ||
| options._skipPaddingChecks = false; | ||
| } | ||
@@ -1161,3 +1168,3 @@ if(scheme === 'RSASSA-PKCS1-V1_5') { | ||
| // remove padding | ||
| d = _decodePkcs1_v1_5(d, key, true); | ||
| d = _decodePkcs1_v1_5(d, key, true, undefined, options); | ||
| // d is ASN.1 BER-encoded DigestInfo | ||
@@ -1168,6 +1175,7 @@ var obj = asn1.fromDer(d, { | ||
| // validate DigestInfo | ||
| // validate DigestInfo structure and element count | ||
| var capture = {}; | ||
| var errors = []; | ||
| if(!asn1.validate(obj, digestInfoValidator, capture, errors)) { | ||
| if(!asn1.validate(obj, digestInfoValidator, capture, errors) || | ||
| obj.value.length !== 2) { | ||
| var error = new Error( | ||
@@ -1216,3 +1224,3 @@ 'ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 ' + | ||
| // remove padding | ||
| d = _decodePkcs1_v1_5(d, key, true); | ||
| d = _decodePkcs1_v1_5(d, key, true, undefined, options); | ||
| return digest === d; | ||
@@ -1635,6 +1643,7 @@ } | ||
| * @param ml the message length, if specified. | ||
| * @param options testing options. | ||
| * | ||
| * @return the decoded bytes. | ||
| */ | ||
| function _decodePkcs1_v1_5(em, key, pub, ml) { | ||
| function _decodePkcs1_v1_5(em, key, pub, ml, options) { | ||
| // get the length of the modulus in bytes | ||
@@ -1659,3 +1668,3 @@ var k = Math.ceil(key.n.bitLength() / 8); | ||
| (pub && bt !== 0x00 && bt !== 0x01) || | ||
| (!pub && bt != 0x02) || | ||
| (!pub && bt !== 0x02) || | ||
| (pub && bt === 0x00 && typeof(ml) === 'undefined')) { | ||
@@ -1684,2 +1693,7 @@ throw new Error('Encryption block is invalid.'); | ||
| } | ||
| // RFC 2313 8.1 note 6 | ||
| if(padNum < 8 && !(options ? options._skipPaddingChecks : false)) { | ||
| throw new Error('Encryption block is invalid.'); | ||
| } | ||
| } else if(bt === 0x02) { | ||
@@ -1695,2 +1709,7 @@ // look for 0x00 byte | ||
| } | ||
| // RFC 2313 8.1 note 6 | ||
| if(padNum < 8 && !(options ? options._skipPaddingChecks : false)) { | ||
| throw new Error('Encryption block is invalid.'); | ||
| } | ||
| } | ||
@@ -1697,0 +1716,0 @@ |
+1
-1
| { | ||
| "name": "node-forge", | ||
| "version": "1.3.3", | ||
| "version": "1.4.0", | ||
| "description": "JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilities.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/digitalbazaar/forge", |
+2
-2
| # Forge | ||
| [](https://nodei.co/npm/node-forge/) | ||
| [](https://nodei.co/npm/node-forge/) | ||
| [](https://github.com/digitalbazaar/forge/actions?query=workflow%3A%22Main+Checks%22) | ||
| [](https://github.com/digitalbazaar/forge/actions/workflows/main.yaml) | ||
@@ -7,0 +7,0 @@ A native implementation of [TLS][] (and various other cryptographic tools) in |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1647637
0.34%30836
0.26%