node-forge 0.8.5 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"forge.min.js","sources":["webpack:///forge.min.js"],"mappings":"AAAA","sourceRoot":""}
1
+ {"version":3,"file":"forge.min.js","sources":["webpack://[name]/forge.min.js"],"mappings":"AAAA","sourceRoot":""}
@@ -1,2 +1,2 @@
1
- !function(t){function i(o){if(r[o])return r[o].exports;var s=r[o]={i:o,l:!1,exports:{}};return t[o].call(s.exports,s,s.exports,i),s.l=!0,s.exports}var r={};i.m=t,i.c=r,i.d=function(t,r,o){i.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:o})},i.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(r,"a",r),r},i.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},i.p="",i(i.s=1)}([function(t,i){t.exports={options:{usePureJavaScript:!1}}},function(t,i,r){r(2),t.exports=r(0)},function(t,i,r){function o(t){for(var i=new p(t.hex,16),r=0,o=t.workLoad,a=0;a<o;++a){if(s(i))return{found:!0,prime:i.toString(16)};i.dAddOffset(d[r++%8],0)}return{found:!1}}function s(t){for(var i=1;i<u.length;){for(var r=u[i],o=i+1;o<u.length&&r<f;)r*=u[o++];for(r=t.modInt(r);i<o;)if(r%u[i++]==0)return!1}return a(t)}function a(t){var i=t.subtract(p.ONE),r=i.getLowestSetBit();if(r<=0)return!1;for(var o,s=i.shiftRight(r),a=n(t.bitLength()),h=e(),u=0;u<a;++u){do{o=new p(t.bitLength(),h)}while(o.compareTo(p.ONE)<=0||o.compareTo(i)>=0);var f=o.modPow(s,t);if(0!==f.compareTo(p.ONE)&&0!==f.compareTo(i)){for(var d=r;--d;){if(f=f.modPowInt(2,t),0===f.compareTo(p.ONE))return!1;if(0===f.compareTo(i))break}if(0===d)return!1}}return!0}function e(){return{nextBytes:function(t){for(var i=0;i<t.length;++i)t[i]=Math.floor(255*Math.random())}}}function n(t){return t<=100?27:t<=150?18:t<=200?15:t<=250?12:t<=300?9:t<=350?8:t<=400?7:t<=500?6:t<=600?5:t<=800?4:t<=1250?3:2}var h=r(0);r(3);var u=[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],f=(1<<26)/u[u.length-1],p=h.jsbn.BigInteger;new p(null).fromInt(2),self.addEventListener("message",function(t){var i=o(t.data);self.postMessage(i)}),self.postMessage({found:!1});var d=[6,4,2,4,2,4,6,2]},function(t,i,r){function o(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 s(){return new o(null)}function a(t,i,r,o,s,a){for(;--a>=0;){var e=i*this.data[t++]+r.data[o]+s;s=Math.floor(e/67108864),r.data[o++]=67108863&e}return s}function e(t,i,r,o,s,a){for(var e=32767&i,n=i>>15;--a>=0;){var h=32767&this.data[t],u=this.data[t++]>>15,f=n*h+u*e;h=e*h+((32767&f)<<15)+r.data[o]+(1073741823&s),s=(h>>>30)+(f>>>15)+n*u+(s>>>30),r.data[o++]=1073741823&h}return s}function n(t,i,r,o,s,a){for(var e=16383&i,n=i>>14;--a>=0;){var h=16383&this.data[t],u=this.data[t++]>>14,f=n*h+u*e;h=e*h+((16383&f)<<14)+r.data[o]+s,s=(h>>28)+(f>>14)+n*u,r.data[o++]=268435455&h}return s}function h(t){return ai.charAt(t)}function u(t,i){var r=ei[t.charCodeAt(i)];return null==r?-1:r}function f(t){for(var i=this.t-1;i>=0;--i)t.data[i]=this.data[i];t.t=this.t,t.s=this.s}function p(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}function d(t){var i=s();return i.fromInt(t),i}function c(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 s=t.length,a=!1,e=0;--s>=0;){var n=8==r?255&t[s]:u(t,s);n<0?"-"==t.charAt(s)&&(a=!0):(a=!1,0==e?this.data[this.t++]=n:e+r>this.DB?(this.data[this.t-1]|=(n&(1<<this.DB-e)-1)<<e,this.data[this.t++]=n>>this.DB-e):this.data[this.t-1]|=n<<e,(e+=r)>=this.DB&&(e-=this.DB))}8==r&&0!=(128&t[0])&&(this.s=-1,e>0&&(this.data[this.t-1]|=(1<<this.DB-e)-1<<e)),this.clamp(),a&&o.ZERO.subTo(this,this)}function m(){for(var t=this.s&this.DM;this.t>0&&this.data[this.t-1]==t;)--this.t}function l(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,a="",e=this.t,n=this.DB-e*this.DB%i;if(e-- >0)for(n<this.DB&&(r=this.data[e]>>n)>0&&(s=!0,a=h(r));e>=0;)n<i?(r=(this.data[e]&(1<<n)-1)<<i-n,r|=this.data[--e]>>(n+=this.DB-i)):(r=this.data[e]>>(n-=i)&o,n<=0&&(n+=this.DB,--e)),r>0&&(s=!0),s&&(a+=h(r));return s?a:"0"}function v(){var t=s();return o.ZERO.subTo(this,t),t}function T(){return this.s<0?this.negate():this}function y(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}function b(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 D(){return this.t<=0?0:this.DB*(this.t-1)+b(this.data[this.t-1]^this.s&this.DM)}function g(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}function B(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}function S(t,i){var r,o=t%this.DB,s=this.DB-o,a=(1<<s)-1,e=Math.floor(t/this.DB),n=this.s<<o&this.DM;for(r=this.t-1;r>=0;--r)i.data[r+e+1]=this.data[r]>>s|n,n=(this.data[r]&a)<<o;for(r=e-1;r>=0;--r)i.data[r]=0;i.data[e]=n,i.t=this.t+e+1,i.s=this.s,i.clamp()}function w(t,i){i.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)return void(i.t=0);var o=t%this.DB,s=this.DB-o,a=(1<<o)-1;i.data[0]=this.data[r]>>o;for(var e=r+1;e<this.t;++e)i.data[e-r-1]|=(this.data[e]&a)<<s,i.data[e-r]=this.data[e]>>o;o>0&&(i.data[this.t-r-1]|=(this.s&a)<<s),i.t=this.t-r,i.clamp()}function M(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()}function E(t,i){var r=this.abs(),s=t.abs(),a=r.t;for(i.t=a+s.t;--a>=0;)i.data[a]=0;for(a=0;a<s.t;++a)i.data[a+r.t]=r.am(0,s.data[a],i,a,0,r.t);i.s=0,i.clamp(),this.s!=t.s&&o.ZERO.subTo(i,i)}function O(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()}function R(t,i,r){var a=t.abs();if(!(a.t<=0)){var e=this.abs();if(e.t<a.t)return null!=i&&i.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=s());var n=s(),h=this.s,u=t.s,f=this.DB-b(a.data[a.t-1]);f>0?(a.lShiftTo(f,n),e.lShiftTo(f,r)):(a.copyTo(n),e.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),m=this.FV/c,l=(1<<this.F1)/c,v=1<<this.F2,T=r.t,y=T-p,D=null==i?s():i;for(n.dlShiftTo(y,D),r.compareTo(D)>=0&&(r.data[r.t++]=1,r.subTo(D,r)),o.ONE.dlShiftTo(p,D),D.subTo(n,n);n.t<p;)n.data[n.t++]=0;for(;--y>=0;){var g=r.data[--T]==d?this.DM:Math.floor(r.data[T]*m+(r.data[T-1]+v)*l);if((r.data[T]+=n.am(0,g,r,y,0,p))<g)for(n.dlShiftTo(y,D),r.subTo(D,r);r.data[T]<--g;)r.subTo(D,r)}null!=i&&(r.drShiftTo(p,i),h!=u&&o.ZERO.subTo(i,i)),r.t=p,r.clamp(),f>0&&r.rShiftTo(f,r),h<0&&o.ZERO.subTo(r,r)}}}function x(t){var i=s();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(o.ZERO)>0&&t.subTo(i,i),i}function N(t){this.m=t}function A(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function L(t){return t}function V(t){t.divRemTo(this.m,null,t)}function q(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function I(t,i){t.squareTo(i),this.reduce(i)}function P(){if(this.t<1)return 0;var t=this.data[0];if(0==(1&t))return 0;var i=3&t;return i=i*(2-(15&t)*i)&15,i=i*(2-(255&t)*i)&255,i=i*(2-((65535&t)*i&65535))&65535,i=i*(2-t*i%this.DV)%this.DV,i>0?this.DV-i:-i}function Z(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 F(t){var i=s();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(o.ZERO)>0&&this.m.subTo(i,i),i}function j(t){var i=s();return t.copyTo(i),this.reduce(i),i}function k(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)}function C(t,i){t.squareTo(i),this.reduce(i)}function z(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function U(){return 0==(this.t>0?1&this.data[0]:this.s)}function _(t,i){if(t>4294967295||t<1)return o.ONE;var r=s(),a=s(),e=i.convert(this),n=b(t)-1;for(e.copyTo(r);--n>=0;)if(i.sqrTo(r,a),(t&1<<n)>0)i.mulTo(a,e,r);else{var h=r;r=a,a=h}return i.revert(r)}function J(t,i){var r;return r=t<256||i.isEven()?new N(i):new Z(i),this.exp(t,r)}function G(){var t=s();return this.copyTo(t),t}function H(){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]}function K(){return 0==this.t?this.s:this.data[0]<<24>>24}function Q(){return 0==this.t?this.s:this.data[0]<<16>>16}function W(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function X(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1}function Y(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=d(r),a=s(),e=s(),n="";for(this.divRemTo(o,a,e);a.signum()>0;)n=(r+e.intValue()).toString(t).substr(1)+n,a.divRemTo(o,a,e);return e.intValue().toString(t)+n}function $(t,i){this.fromInt(0),null==i&&(i=10);for(var r=this.chunkSize(i),s=Math.pow(i,r),a=!1,e=0,n=0,h=0;h<t.length;++h){var f=u(t,h);f<0?"-"==t.charAt(h)&&0==this.signum()&&(a=!0):(n=i*n+f,++e>=r&&(this.dMultiply(s),this.dAddOffset(n,0),e=0,n=0))}e>0&&(this.dMultiply(Math.pow(i,e)),this.dAddOffset(n,0)),a&&o.ZERO.subTo(this,this)}function tt(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(o.ONE.shiftLeft(t-1),ht,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(o.ONE.shiftLeft(t-1),this);else{var s=new Array,a=7&t;s.length=1+(t>>3),i.nextBytes(s),a>0?s[0]&=(1<<a)-1:s[0]=0,this.fromString(s,256)}}function it(){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}function rt(t){return 0==this.compareTo(t)}function ot(t){return this.compareTo(t)<0?this:t}function st(t){return this.compareTo(t)>0?this:t}function at(t,i,r){var o,s,a=Math.min(t.t,this.t);for(o=0;o<a;++o)r.data[o]=i(this.data[o],t.data[o]);if(t.t<this.t){for(s=t.s&this.DM,o=a;o<this.t;++o)r.data[o]=i(this.data[o],s);r.t=this.t}else{for(s=this.s&this.DM,o=a;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()}function et(t,i){return t&i}function nt(t){var i=s();return this.bitwiseTo(t,et,i),i}function ht(t,i){return t|i}function ut(t){var i=s();return this.bitwiseTo(t,ht,i),i}function ft(t,i){return t^i}function pt(t){var i=s();return this.bitwiseTo(t,ft,i),i}function dt(t,i){return t&~i}function ct(t){var i=s();return this.bitwiseTo(t,dt,i),i}function mt(){for(var t=s(),i=0;i<this.t;++i)t.data[i]=this.DM&~this.data[i];return t.t=this.t,t.s=~this.s,t}function lt(t){var i=s();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i}function vt(t){var i=s();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i}function Tt(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 yt(){for(var t=0;t<this.t;++t)if(0!=this.data[t])return t*this.DB+Tt(this.data[t]);return this.s<0?this.t*this.DB:-1}function bt(t){for(var i=0;0!=t;)t&=t-1,++i;return i}function Dt(){for(var t=0,i=this.s&this.DM,r=0;r<this.t;++r)t+=bt(this.data[r]^i);return t}function gt(t){var i=Math.floor(t/this.DB);return i>=this.t?0!=this.s:0!=(this.data[i]&1<<t%this.DB)}function Bt(t,i){var r=o.ONE.shiftLeft(t);return this.bitwiseTo(r,i,r),r}function St(t){return this.changeBit(t,ht)}function wt(t){return this.changeBit(t,dt)}function Mt(t){return this.changeBit(t,ft)}function Et(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()}function Ot(t){var i=s();return this.addTo(t,i),i}function Rt(t){var i=s();return this.subTo(t,i),i}function xt(t){var i=s();return this.multiplyTo(t,i),i}function Nt(t){var i=s();return this.divRemTo(t,i,null),i}function At(t){var i=s();return this.divRemTo(t,null,i),i}function Lt(t){var i=s(),r=s();return this.divRemTo(t,i,r),new Array(i,r)}function Vt(t){this.data[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function qt(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]}}function It(){}function Pt(t){return t}function Zt(t,i,r){t.multiplyTo(i,r)}function Ft(t,i){t.squareTo(i)}function jt(t){return this.exp(t,new It)}function kt(t,i,r){var o=Math.min(this.t+t.t,i);for(r.s=0,r.t=o;o>0;)r.data[--o]=0;var s;for(s=r.t-this.t;o<s;++o)r.data[o+this.t]=this.am(0,t.data[o],r,o,0,this.t);for(s=Math.min(t.t,i);o<s;++o)this.am(0,t.data[o],r,o,0,i-o);r.clamp()}function Ct(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)}function zt(t){this.r2=s(),this.q3=s(),o.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function Ut(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=s();return t.copyTo(i),this.reduce(i),i}function _t(t){return t}function Jt(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)}function Gt(t,i){t.squareTo(i),this.reduce(i)}function Ht(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function Kt(t,i){var r,o,a=t.bitLength(),e=d(1);if(a<=0)return e;r=a<18?1:a<48?3:a<144?4:a<768?5:6,o=a<8?new N(i):i.isEven()?new zt(i):new Z(i);var n=new Array,h=3,u=r-1,f=(1<<r)-1;if(n[1]=o.convert(this),r>1){var p=s();for(o.sqrTo(n[1],p);h<=f;)n[h]=s(),o.mulTo(p,n[h-2],n[h]),h+=2}var c,m,l=t.t-1,v=!0,T=s();for(a=b(t.data[l])-1;l>=0;){for(a>=u?c=t.data[l]>>a-u&f:(c=(t.data[l]&(1<<a+1)-1)<<u-a,l>0&&(c|=t.data[l-1]>>this.DB+a-u)),h=r;0==(1&c);)c>>=1,--h;if((a-=h)<0&&(a+=this.DB,--l),v)n[c].copyTo(e),v=!1;else{for(;h>1;)o.sqrTo(e,T),o.sqrTo(T,e),h-=2;h>0?o.sqrTo(e,T):(m=e,e=T,T=m),o.mulTo(T,n[c],e)}for(;l>=0&&0==(t.data[l]&1<<a);)o.sqrTo(e,T),m=e,e=T,T=m,--a<0&&(a=this.DB-1,--l)}return o.revert(e)}function Qt(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(),a=r.getLowestSetBit();if(a<0)return i;for(s<a&&(a=s),a>0&&(i.rShiftTo(a,i),r.rShiftTo(a,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 a>0&&r.lShiftTo(a,r),r}function Wt(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}function Xt(t){var i=t.isEven();if(this.isEven()&&i||0==t.signum())return o.ZERO;for(var r=t.clone(),s=this.clone(),a=d(1),e=d(0),n=d(0),h=d(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),i?(a.isEven()&&e.isEven()||(a.addTo(this,a),e.subTo(t,e)),a.rShiftTo(1,a)):e.isEven()||e.subTo(t,e),e.rShiftTo(1,e);for(;s.isEven();)s.rShiftTo(1,s),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(s)>=0?(r.subTo(s,r),i&&a.subTo(n,a),e.subTo(h,e)):(s.subTo(r,s),i&&n.subTo(a,n),h.subTo(e,h))}return 0!=s.compareTo(o.ONE)?o.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h}function Yt(t){var i,r=this.abs();if(1==r.t&&r.data[0]<=ni[ni.length-1]){for(i=0;i<ni.length;++i)if(r.data[0]==ni[i])return!0;return!1}if(r.isEven())return!1;for(i=1;i<ni.length;){for(var o=ni[i],s=i+1;s<ni.length&&o<hi;)o*=ni[s++];for(o=r.modInt(o);i<s;)if(o%ni[i++]==0)return!1}return r.millerRabin(t)}function $t(t){var i=this.subtract(o.ONE),r=i.getLowestSetBit();if(r<=0)return!1;for(var s,a=i.shiftRight(r),e=ti(),n=0;n<t;++n){do{s=new o(this.bitLength(),e)}while(s.compareTo(o.ONE)<=0||s.compareTo(i)>=0);var h=s.modPow(a,this);if(0!=h.compareTo(o.ONE)&&0!=h.compareTo(i)){for(var u=1;u++<r&&0!=h.compareTo(i);)if(h=h.modPowInt(2,this),0==h.compareTo(o.ONE))return!1;if(0!=h.compareTo(i))return!1}}return!0}function ti(){return{nextBytes:function(t){for(var i=0;i<t.length;++i)t[i]=Math.floor(256*Math.random())}}}var ii=r(0);t.exports=ii.jsbn=ii.jsbn||{};var ri;ii.jsbn.BigInteger=o,"undefined"==typeof navigator?(o.prototype.am=n,ri=28):"Microsoft Internet Explorer"==navigator.appName?(o.prototype.am=e,ri=30):"Netscape"!=navigator.appName?(o.prototype.am=a,ri=26):(o.prototype.am=n,ri=28),o.prototype.DB=ri,o.prototype.DM=(1<<ri)-1,o.prototype.DV=1<<ri;o.prototype.FV=Math.pow(2,52),o.prototype.F1=52-ri,o.prototype.F2=2*ri-52;var oi,si,ai="0123456789abcdefghijklmnopqrstuvwxyz",ei=new Array;for(oi="0".charCodeAt(0),si=0;si<=9;++si)ei[oi++]=si;for(oi="a".charCodeAt(0),si=10;si<36;++si)ei[oi++]=si;for(oi="A".charCodeAt(0),si=10;si<36;++si)ei[oi++]=si;N.prototype.convert=A,N.prototype.revert=L,N.prototype.reduce=V,N.prototype.mulTo=q,N.prototype.sqrTo=I,Z.prototype.convert=F,Z.prototype.revert=j,Z.prototype.reduce=k,Z.prototype.mulTo=z,Z.prototype.sqrTo=C,o.prototype.copyTo=f,o.prototype.fromInt=p,o.prototype.fromString=c,o.prototype.clamp=m,o.prototype.dlShiftTo=g,o.prototype.drShiftTo=B,o.prototype.lShiftTo=S,o.prototype.rShiftTo=w,o.prototype.subTo=M,o.prototype.multiplyTo=E,o.prototype.squareTo=O,o.prototype.divRemTo=R,o.prototype.invDigit=P,o.prototype.isEven=U,o.prototype.exp=_,o.prototype.toString=l,o.prototype.negate=v,o.prototype.abs=T,o.prototype.compareTo=y,o.prototype.bitLength=D,o.prototype.mod=x,o.prototype.modPowInt=J,o.ZERO=d(0),o.ONE=d(1),It.prototype.convert=Pt,It.prototype.revert=Pt,It.prototype.mulTo=Zt,It.prototype.sqrTo=Ft,zt.prototype.convert=Ut,zt.prototype.revert=_t,zt.prototype.reduce=Jt,zt.prototype.mulTo=Ht,zt.prototype.sqrTo=Gt;var ni=[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],hi=(1<<26)/ni[ni.length-1];o.prototype.chunkSize=W,o.prototype.toRadix=Y,o.prototype.fromRadix=$,o.prototype.fromNumber=tt,o.prototype.bitwiseTo=at,o.prototype.changeBit=Bt,o.prototype.addTo=Et,o.prototype.dMultiply=Vt,o.prototype.dAddOffset=qt,o.prototype.multiplyLowerTo=kt,o.prototype.multiplyUpperTo=Ct,o.prototype.modInt=Wt,o.prototype.millerRabin=$t,o.prototype.clone=G,o.prototype.intValue=H,o.prototype.byteValue=K,o.prototype.shortValue=Q,o.prototype.signum=X,o.prototype.toByteArray=it,o.prototype.equals=rt,o.prototype.min=ot,o.prototype.max=st,o.prototype.and=nt,o.prototype.or=ut,o.prototype.xor=pt,o.prototype.andNot=ct,o.prototype.not=mt,o.prototype.shiftLeft=lt,o.prototype.shiftRight=vt,o.prototype.getLowestSetBit=yt,o.prototype.bitCount=Dt,o.prototype.testBit=gt,o.prototype.setBit=St,o.prototype.clearBit=wt,o.prototype.flipBit=Mt,o.prototype.add=Ot,o.prototype.subtract=Rt,o.prototype.multiply=xt,o.prototype.divide=Nt,o.prototype.remainder=At,o.prototype.divideAndRemainder=Lt,o.prototype.modPow=Kt,o.prototype.modInverse=Xt,o.prototype.pow=jt,o.prototype.gcd=Qt,o.prototype.isProbablePrime=Yt}]);
1
+ !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)}}]);
2
2
  //# sourceMappingURL=prime.worker.min.js.map
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Copyright (c) 2019 Digital Bazaar, Inc.
3
+ */
4
+
5
+ var forge = require('./forge');
6
+ require('./asn1');
7
+ var asn1 = forge.asn1;
8
+
9
+ exports.privateKeyValidator = {
10
+ // PrivateKeyInfo
11
+ name: 'PrivateKeyInfo',
12
+ tagClass: asn1.Class.UNIVERSAL,
13
+ type: asn1.Type.SEQUENCE,
14
+ constructed: true,
15
+ value: [{
16
+ // Version (INTEGER)
17
+ name: 'PrivateKeyInfo.version',
18
+ tagClass: asn1.Class.UNIVERSAL,
19
+ type: asn1.Type.INTEGER,
20
+ constructed: false,
21
+ capture: 'privateKeyVersion'
22
+ }, {
23
+ // privateKeyAlgorithm
24
+ name: 'PrivateKeyInfo.privateKeyAlgorithm',
25
+ tagClass: asn1.Class.UNIVERSAL,
26
+ type: asn1.Type.SEQUENCE,
27
+ constructed: true,
28
+ value: [{
29
+ name: 'AlgorithmIdentifier.algorithm',
30
+ tagClass: asn1.Class.UNIVERSAL,
31
+ type: asn1.Type.OID,
32
+ constructed: false,
33
+ capture: 'privateKeyOid'
34
+ }]
35
+ }, {
36
+ // PrivateKey
37
+ name: 'PrivateKeyInfo',
38
+ tagClass: asn1.Class.UNIVERSAL,
39
+ type: asn1.Type.OCTETSTRING,
40
+ constructed: false,
41
+ capture: 'privateKey'
42
+ }]
43
+ };
44
+
45
+ exports.publicKeyValidator = {
46
+ name: 'SubjectPublicKeyInfo',
47
+ tagClass: asn1.Class.UNIVERSAL,
48
+ type: asn1.Type.SEQUENCE,
49
+ constructed: true,
50
+ captureAsn1: 'subjectPublicKeyInfo',
51
+ value: [{
52
+ name: 'SubjectPublicKeyInfo.AlgorithmIdentifier',
53
+ tagClass: asn1.Class.UNIVERSAL,
54
+ type: asn1.Type.SEQUENCE,
55
+ constructed: true,
56
+ value: [{
57
+ name: 'AlgorithmIdentifier.algorithm',
58
+ tagClass: asn1.Class.UNIVERSAL,
59
+ type: asn1.Type.OID,
60
+ constructed: false,
61
+ capture: 'publicKeyOid'
62
+ }]
63
+ },
64
+ // capture group for ed25519PublicKey
65
+ {
66
+ tagClass: asn1.Class.UNIVERSAL,
67
+ type: asn1.Type.BITSTRING,
68
+ constructed: false,
69
+ composed: true,
70
+ captureBitStringValue: 'ed25519PublicKey'
71
+ }
72
+ // FIXME: this is capture group for rsaPublicKey, use it in this API or
73
+ // discard?
74
+ /* {
75
+ // subjectPublicKey
76
+ name: 'SubjectPublicKeyInfo.subjectPublicKey',
77
+ tagClass: asn1.Class.UNIVERSAL,
78
+ type: asn1.Type.BITSTRING,
79
+ constructed: false,
80
+ value: [{
81
+ // RSAPublicKey
82
+ name: 'SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey',
83
+ tagClass: asn1.Class.UNIVERSAL,
84
+ type: asn1.Type.SEQUENCE,
85
+ constructed: true,
86
+ optional: true,
87
+ captureAsn1: 'rsaPublicKey'
88
+ }]
89
+ } */
90
+ ]
91
+ };
@@ -119,7 +119,7 @@ modes.cbc.prototype.start = function(options) {
119
119
  throw new Error('Invalid IV parameter.');
120
120
  } else {
121
121
  // save IV as "previous" block
122
- this._iv = transformIV(options.iv);
122
+ this._iv = transformIV(options.iv, this.blockSize);
123
123
  this._prev = this._iv.slice(0);
124
124
  }
125
125
  };
@@ -215,7 +215,7 @@ modes.cfb.prototype.start = function(options) {
215
215
  throw new Error('Invalid IV parameter.');
216
216
  }
217
217
  // use IV as first input
218
- this._iv = transformIV(options.iv);
218
+ this._iv = transformIV(options.iv, this.blockSize);
219
219
  this._inBlock = this._iv.slice(0);
220
220
  this._partialBytes = 0;
221
221
  };
@@ -359,7 +359,7 @@ modes.ofb.prototype.start = function(options) {
359
359
  throw new Error('Invalid IV parameter.');
360
360
  }
361
361
  // use IV as first input
362
- this._iv = transformIV(options.iv);
362
+ this._iv = transformIV(options.iv, this.blockSize);
363
363
  this._inBlock = this._iv.slice(0);
364
364
  this._partialBytes = 0;
365
365
  };
@@ -444,7 +444,7 @@ modes.ctr.prototype.start = function(options) {
444
444
  throw new Error('Invalid IV parameter.');
445
445
  }
446
446
  // use IV as first input
447
- this._iv = transformIV(options.iv);
447
+ this._iv = transformIV(options.iv, this.blockSize);
448
448
  this._inBlock = this._iv.slice(0);
449
449
  this._partialBytes = 0;
450
450
  };
@@ -954,7 +954,7 @@ modes.gcm.prototype.generateSubHashTable = function(mid, bits) {
954
954
 
955
955
  /** Utility functions */
956
956
 
957
- function transformIV(iv) {
957
+ function transformIV(iv, blockSize) {
958
958
  if(typeof iv === 'string') {
959
959
  // convert iv string into byte buffer
960
960
  iv = forge.util.createBuffer(iv);
@@ -968,9 +968,21 @@ function transformIV(iv) {
968
968
  iv.putByte(tmp[i]);
969
969
  }
970
970
  }
971
+
972
+ if(iv.length() < blockSize) {
973
+ throw new Error(
974
+ 'Invalid IV length; got ' + iv.length() +
975
+ ' bytes and expected ' + blockSize + ' bytes.');
976
+ }
977
+
971
978
  if(!forge.util.isArray(iv)) {
972
979
  // convert iv byte buffer into 32-bit integer array
973
- iv = [iv.getInt32(), iv.getInt32(), iv.getInt32(), iv.getInt32()];
980
+ var ints = [];
981
+ var blocks = blockSize / 4;
982
+ for(var i = 0; i < blocks; ++i) {
983
+ ints.push(iv.getInt32());
984
+ }
985
+ iv = ints;
974
986
  }
975
987
 
976
988
  return iv;
package/lib/ed25519.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * JavaScript implementation of Ed25519.
3
3
  *
4
- * Copyright (c) 2017-2018 Digital Bazaar, Inc.
4
+ * Copyright (c) 2017-2019 Digital Bazaar, Inc.
5
5
  *
6
6
  * This implementation is based on the most excellent TweetNaCl which is
7
7
  * in the public domain. Many thanks to its contributors:
@@ -13,6 +13,9 @@ require('./jsbn');
13
13
  require('./random');
14
14
  require('./sha512');
15
15
  require('./util');
16
+ var asn1Validator = require('./asn1-validator');
17
+ var publicKeyValidator = asn1Validator.publicKeyValidator;
18
+ var privateKeyValidator = asn1Validator.privateKeyValidator;
16
19
 
17
20
  if(typeof BigInteger === 'undefined') {
18
21
  var BigInteger = forge.jsbn.BigInteger;
@@ -64,6 +67,75 @@ ed25519.generateKeyPair = function(options) {
64
67
  return {publicKey: pk, privateKey: sk};
65
68
  };
66
69
 
70
+ /**
71
+ * Converts a private key from a RFC8410 ASN.1 encoding.
72
+ *
73
+ * @param obj - The asn1 representation of a private key.
74
+ *
75
+ * @returns {Object} keyInfo - The key information.
76
+ * @returns {Buffer|Uint8Array} keyInfo.privateKeyBytes - 32 private key bytes.
77
+ */
78
+ ed25519.privateKeyFromAsn1 = function(obj) {
79
+ var capture = {};
80
+ var errors = [];
81
+ var valid = forge.asn1.validate(obj, privateKeyValidator, capture, errors);
82
+ if(!valid) {
83
+ var error = new Error('Invalid Key.');
84
+ error.errors = errors;
85
+ throw error;
86
+ }
87
+ var oid = forge.asn1.derToOid(capture.privateKeyOid);
88
+ var ed25519Oid = forge.oids.EdDSA25519;
89
+ if(oid !== ed25519Oid) {
90
+ throw new Error('Invalid OID "' + oid + '"; OID must be "' +
91
+ ed25519Oid + '".');
92
+ }
93
+ var privateKey = capture.privateKey;
94
+ // manually extract the private key bytes from nested octet string, see FIXME:
95
+ // https://github.com/digitalbazaar/forge/blob/master/lib/asn1.js#L542
96
+ var privateKeyBytes = messageToNativeBuffer({
97
+ message: forge.asn1.fromDer(privateKey).value,
98
+ encoding: 'binary'
99
+ });
100
+ // TODO: RFC8410 specifies a format for encoding the public key bytes along
101
+ // with the private key bytes. `publicKeyBytes` can be returned in the
102
+ // future. https://tools.ietf.org/html/rfc8410#section-10.3
103
+ return {privateKeyBytes: privateKeyBytes};
104
+ };
105
+
106
+ /**
107
+ * Converts a public key from a RFC8410 ASN.1 encoding.
108
+ *
109
+ * @param obj - The asn1 representation of a public key.
110
+ *
111
+ * @return {Buffer|Uint8Array} - 32 public key bytes.
112
+ */
113
+ ed25519.publicKeyFromAsn1 = function(obj) {
114
+ // get SubjectPublicKeyInfo
115
+ var capture = {};
116
+ var errors = [];
117
+ var valid = forge.asn1.validate(obj, publicKeyValidator, capture, errors);
118
+ if(!valid) {
119
+ var error = new Error('Invalid Key.');
120
+ error.errors = errors;
121
+ throw error;
122
+ }
123
+ var oid = forge.asn1.derToOid(capture.publicKeyOid);
124
+ var ed25519Oid = forge.oids.EdDSA25519;
125
+ if(oid !== ed25519Oid) {
126
+ throw new Error('Invalid OID "' + oid + '"; OID must be "' +
127
+ ed25519Oid + '".');
128
+ }
129
+ var publicKeyBytes = capture.ed25519PublicKey;
130
+ if(publicKeyBytes.length !== ed25519.constants.PUBLIC_KEY_BYTE_LENGTH) {
131
+ throw new Error('Key length is invalid.');
132
+ }
133
+ return messageToNativeBuffer({
134
+ message: publicKeyBytes,
135
+ encoding: 'binary'
136
+ });
137
+ };
138
+
67
139
  ed25519.publicKeyFromPrivateKey = function(options) {
68
140
  options = options || {};
69
141
  var privateKey = messageToNativeBuffer({
@@ -89,9 +161,13 @@ ed25519.sign = function(options) {
89
161
  message: options.privateKey,
90
162
  encoding: 'binary'
91
163
  });
92
- if(privateKey.length !== ed25519.constants.PRIVATE_KEY_BYTE_LENGTH) {
164
+ if(privateKey.length === ed25519.constants.SEED_BYTE_LENGTH) {
165
+ var keyPair = ed25519.generateKeyPair({seed: privateKey});
166
+ privateKey = keyPair.privateKey;
167
+ } else if(privateKey.length !== ed25519.constants.PRIVATE_KEY_BYTE_LENGTH) {
93
168
  throw new TypeError(
94
169
  '"options.privateKey" must have a byte length of ' +
170
+ ed25519.constants.SEED_BYTE_LENGTH + ' or ' +
95
171
  ed25519.constants.PRIVATE_KEY_BYTE_LENGTH);
96
172
  }
97
173
 
@@ -147,7 +223,7 @@ ed25519.verify = function(options) {
147
223
 
148
224
  function messageToNativeBuffer(options) {
149
225
  var message = options.message;
150
- if(message instanceof Uint8Array) {
226
+ if(message instanceof Uint8Array || message instanceof NativeBuffer) {
151
227
  return message;
152
228
  }
153
229
 
package/lib/oids.js CHANGED
@@ -34,6 +34,8 @@ _IN('1.2.840.113549.1.1.10', 'RSASSA-PSS');
34
34
  _IN('1.2.840.113549.1.1.11', 'sha256WithRSAEncryption');
35
35
  _IN('1.2.840.113549.1.1.12', 'sha384WithRSAEncryption');
36
36
  _IN('1.2.840.113549.1.1.13', 'sha512WithRSAEncryption');
37
+ // Edwards-curve Digital Signature Algorithm (EdDSA) Ed25519
38
+ _IN('1.3.101.112', 'EdDSA25519');
37
39
 
38
40
  _IN('1.2.840.10040.4.3', 'dsa-with-sha1');
39
41
 
@@ -106,9 +108,14 @@ _IN('2.5.4.5', 'serialName');
106
108
  _IN('2.5.4.6', 'countryName');
107
109
  _IN('2.5.4.7', 'localityName');
108
110
  _IN('2.5.4.8', 'stateOrProvinceName');
111
+ _IN('2.5.4.9', 'streetAddress');
109
112
  _IN('2.5.4.10', 'organizationName');
110
113
  _IN('2.5.4.11', 'organizationalUnitName');
111
114
  _IN('2.5.4.13', 'description');
115
+ _IN('2.5.4.15', 'businessCategory');
116
+ _IN('2.5.4.17', 'postalCode');
117
+ _IN('1.3.6.1.4.1.311.60.2.1.2', 'jurisdictionOfIncorporationStateOrProvinceName');
118
+ _IN('1.3.6.1.4.1.311.60.2.1.3', 'jurisdictionOfIncorporationCountryName');
112
119
 
113
120
  // X.509 extension OIDs
114
121
  _IN('2.16.840.1.113730.1.1', 'nsCertType');
package/lib/util.js CHANGED
@@ -279,7 +279,7 @@ util.ByteStringBuffer.prototype.fillWithByte = function(b, n) {
279
279
  /**
280
280
  * Puts bytes in this buffer.
281
281
  *
282
- * @param bytes the bytes (as a UTF-8 encoded string) to put.
282
+ * @param bytes the bytes (as a binary encoded string) to put.
283
283
  *
284
284
  * @return this buffer.
285
285
  */
@@ -567,11 +567,13 @@ util.ByteStringBuffer.prototype.getSignedInt = function(n) {
567
567
  };
568
568
 
569
569
  /**
570
- * Reads bytes out into a UTF-8 string and clears them from the buffer.
570
+ * Reads bytes out as a binary encoded string and clears them from the
571
+ * buffer. Note that the resulting string is binary encoded (in node.js this
572
+ * encoding is referred to as `binary`, it is *not* `utf8`).
571
573
  *
572
574
  * @param count the number of bytes to read, undefined or null for all.
573
575
  *
574
- * @return a UTF-8 string of bytes.
576
+ * @return a binary encoded string of bytes.
575
577
  */
576
578
  util.ByteStringBuffer.prototype.getBytes = function(count) {
577
579
  var rval;
@@ -591,12 +593,12 @@ util.ByteStringBuffer.prototype.getBytes = function(count) {
591
593
  };
592
594
 
593
595
  /**
594
- * Gets a UTF-8 encoded string of the bytes from this buffer without modifying
595
- * the read pointer.
596
+ * Gets a binary encoded string of the bytes from this buffer without
597
+ * modifying the read pointer.
596
598
  *
597
599
  * @param count the number of bytes to get, omit to get all.
598
600
  *
599
- * @return a string full of UTF-8 encoded characters.
601
+ * @return a string full of binary encoded characters.
600
602
  */
601
603
  util.ByteStringBuffer.prototype.bytes = function(count) {
602
604
  return (typeof(count) === 'undefined' ?
@@ -1228,11 +1230,12 @@ util.DataBuffer.prototype.getSignedInt = function(n) {
1228
1230
  };
1229
1231
 
1230
1232
  /**
1231
- * Reads bytes out into a UTF-8 string and clears them from the buffer.
1233
+ * Reads bytes out as a binary encoded string and clears them from the
1234
+ * buffer.
1232
1235
  *
1233
1236
  * @param count the number of bytes to read, undefined or null for all.
1234
1237
  *
1235
- * @return a UTF-8 string of bytes.
1238
+ * @return a binary encoded string of bytes.
1236
1239
  */
1237
1240
  util.DataBuffer.prototype.getBytes = function(count) {
1238
1241
  // TODO: deprecate this method, it is poorly named and
@@ -1255,12 +1258,12 @@ util.DataBuffer.prototype.getBytes = function(count) {
1255
1258
  };
1256
1259
 
1257
1260
  /**
1258
- * Gets a UTF-8 encoded string of the bytes from this buffer without modifying
1259
- * the read pointer.
1261
+ * Gets a binary encoded string of the bytes from this buffer without
1262
+ * modifying the read pointer.
1260
1263
  *
1261
1264
  * @param count the number of bytes to get, omit to get all.
1262
1265
  *
1263
- * @return a string full of UTF-8 encoded characters.
1266
+ * @return a string full of binary encoded characters.
1264
1267
  */
1265
1268
  util.DataBuffer.prototype.bytes = function(count) {
1266
1269
  // TODO: deprecate this method, it is poorly named, add "getString()"
@@ -1407,12 +1410,13 @@ util.DataBuffer.prototype.toString = function(encoding) {
1407
1410
  /** End Buffer w/UInt8Array backing */
1408
1411
 
1409
1412
  /**
1410
- * Creates a buffer that stores bytes. A value may be given to put into the
1411
- * buffer that is either a string of bytes or a UTF-16 string that will
1412
- * be encoded using UTF-8 (to do the latter, specify 'utf8' as the encoding).
1413
+ * Creates a buffer that stores bytes. A value may be given to populate the
1414
+ * buffer with data. This value can either be string of encoded bytes or a
1415
+ * regular string of characters. When passing a string of binary encoded
1416
+ * bytes, the encoding `raw` should be given. This is also the default. When
1417
+ * passing a string of characters, the encoding `utf8` should be given.
1413
1418
  *
1414
- * @param [input] the bytes to wrap (as a string) or a UTF-16 string to encode
1415
- * as UTF-8.
1419
+ * @param [input] a string with encoded bytes to store in the buffer.
1416
1420
  * @param [encoding] (default: 'raw', other: 'utf8').
1417
1421
  */
1418
1422
  util.createBuffer = function(input, encoding) {
@@ -1641,24 +1645,27 @@ util.decode64 = function(input) {
1641
1645
  };
1642
1646
 
1643
1647
  /**
1644
- * UTF-8 encodes the given UTF-16 encoded string (a standard JavaScript
1645
- * string). Non-ASCII characters will be encoded as multiple bytes according
1646
- * to UTF-8.
1648
+ * Encodes the given string of characters (a standard JavaScript
1649
+ * string) as a binary encoded string where the bytes represent
1650
+ * a UTF-8 encoded string of characters. Non-ASCII characters will be
1651
+ * encoded as multiple bytes according to UTF-8.
1647
1652
  *
1648
- * @param str the string to encode.
1653
+ * @param str a standard string of characters to encode.
1649
1654
  *
1650
- * @return the UTF-8 encoded string.
1655
+ * @return the binary encoded string.
1651
1656
  */
1652
1657
  util.encodeUtf8 = function(str) {
1653
1658
  return unescape(encodeURIComponent(str));
1654
1659
  };
1655
1660
 
1656
1661
  /**
1657
- * Decodes a UTF-8 encoded string into a UTF-16 string.
1662
+ * Decodes a binary encoded string that contains bytes that
1663
+ * represent a UTF-8 encoded string of characters -- into a
1664
+ * string of characters (a standard JavaScript string).
1658
1665
  *
1659
- * @param str the string to decode.
1666
+ * @param str the binary encoded string to decode.
1660
1667
  *
1661
- * @return the UTF-16 encoded string (standard JavaScript string).
1668
+ * @return the resulting standard string of characters.
1662
1669
  */
1663
1670
  util.decodeUtf8 = function(str) {
1664
1671
  return decodeURIComponent(escape(str));
@@ -2506,99 +2513,6 @@ util.makeLink = function(path, query, fragment) {
2506
2513
  ((fragment.length > 0) ? ('#' + fragment) : '');
2507
2514
  };
2508
2515
 
2509
- /**
2510
- * Follows a path of keys deep into an object hierarchy and set a value.
2511
- * If a key does not exist or it's value is not an object, create an
2512
- * object in it's place. This can be destructive to a object tree if
2513
- * leaf nodes are given as non-final path keys.
2514
- * Used to avoid exceptions from missing parts of the path.
2515
- *
2516
- * @param object the starting object.
2517
- * @param keys an array of string keys.
2518
- * @param value the value to set.
2519
- */
2520
- util.setPath = function(object, keys, value) {
2521
- // need to start at an object
2522
- if(typeof(object) === 'object' && object !== null) {
2523
- var i = 0;
2524
- var len = keys.length;
2525
- while(i < len) {
2526
- var next = keys[i++];
2527
- if(i == len) {
2528
- // last
2529
- object[next] = value;
2530
- } else {
2531
- // more
2532
- var hasNext = (next in object);
2533
- if(!hasNext ||
2534
- (hasNext && typeof(object[next]) !== 'object') ||
2535
- (hasNext && object[next] === null)) {
2536
- object[next] = {};
2537
- }
2538
- object = object[next];
2539
- }
2540
- }
2541
- }
2542
- };
2543
-
2544
- /**
2545
- * Follows a path of keys deep into an object hierarchy and return a value.
2546
- * If a key does not exist, create an object in it's place.
2547
- * Used to avoid exceptions from missing parts of the path.
2548
- *
2549
- * @param object the starting object.
2550
- * @param keys an array of string keys.
2551
- * @param _default value to return if path not found.
2552
- *
2553
- * @return the value at the path if found, else default if given, else
2554
- * undefined.
2555
- */
2556
- util.getPath = function(object, keys, _default) {
2557
- var i = 0;
2558
- var len = keys.length;
2559
- var hasNext = true;
2560
- while(hasNext && i < len &&
2561
- typeof(object) === 'object' && object !== null) {
2562
- var next = keys[i++];
2563
- hasNext = next in object;
2564
- if(hasNext) {
2565
- object = object[next];
2566
- }
2567
- }
2568
- return (hasNext ? object : _default);
2569
- };
2570
-
2571
- /**
2572
- * Follow a path of keys deep into an object hierarchy and delete the
2573
- * last one. If a key does not exist, do nothing.
2574
- * Used to avoid exceptions from missing parts of the path.
2575
- *
2576
- * @param object the starting object.
2577
- * @param keys an array of string keys.
2578
- */
2579
- util.deletePath = function(object, keys) {
2580
- // need to start at an object
2581
- if(typeof(object) === 'object' && object !== null) {
2582
- var i = 0;
2583
- var len = keys.length;
2584
- while(i < len) {
2585
- var next = keys[i++];
2586
- if(i == len) {
2587
- // last
2588
- delete object[next];
2589
- } else {
2590
- // more
2591
- if(!(next in object) ||
2592
- (typeof(object[next]) !== 'object') ||
2593
- (object[next] === null)) {
2594
- break;
2595
- }
2596
- object = object[next];
2597
- }
2598
- }
2599
- }
2600
- };
2601
-
2602
2516
  /**
2603
2517
  * Check if an object is empty.
2604
2518
  *