Comparing version 0.3.9 to 0.3.10
@@ -0,2 +1,6 @@ | ||
## 0.3.10 | ||
* 支持 sm3 hmac 模式 | ||
## 0.3.9 | ||
@@ -3,0 +7,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.sm2=i():t.sm2=i()}("undefined"!=typeof self?self:this,function(){return function(t){function i(e){if(r[e])return r[e].exports;var n=r[e]={i:e,l:!1,exports:{}};return t[e].call(n.exports,n,n.exports,i),n.l=!0,n.exports}var r={};return i.m=t,i.c=r,i.d=function(t,r,e){i.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:e})},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=2)}([function(t,i,r){(function(){function r(t,i,r){null!=t&&("number"==typeof t?this.fromNumber(t,i,r):null==i&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,i))}function e(){return new r(null)}function n(t,i,r,e,n,o){for(;--o>=0;){var s=i*this[t++]+r[e]+n;n=Math.floor(s/67108864),r[e++]=67108863&s}return n}function o(t,i,r,e,n,o){for(var s=32767&i,u=i>>15;--o>=0;){var h=32767&this[t],a=this[t++]>>15,f=u*h+a*s;h=s*h+((32767&f)<<15)+r[e]+(1073741823&n),n=(h>>>30)+(f>>>15)+u*a+(n>>>30),r[e++]=1073741823&h}return n}function s(t,i,r,e,n,o){for(var s=16383&i,u=i>>14;--o>=0;){var h=16383&this[t],a=this[t++]>>14,f=u*h+a*s;h=s*h+((16383&f)<<14)+r[e]+n,n=(h>>28)+(f>>14)+u*a,r[e++]=268435455&h}return n}function u(t){return pi.charAt(t)}function h(t,i){var r=vi[t.charCodeAt(i)];return null==r?-1:r}function a(t){for(var i=this.t-1;i>=0;--i)t[i]=this[i];t.t=this.t,t.s=this.s}function f(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}function l(t){var i=e();return i.fromInt(t),i}function c(t,i){var e;if(16==i)e=4;else if(8==i)e=3;else if(256==i)e=8;else if(2==i)e=1;else if(32==i)e=5;else{if(4!=i)return void this.fromRadix(t,i);e=2}this.t=0,this.s=0;for(var n=t.length,o=!1,s=0;--n>=0;){var u=8==e?255&t[n]:h(t,n);u<0?"-"==t.charAt(n)&&(o=!0):(o=!1,0==s?this[this.t++]=u:s+e>this.DB?(this[this.t-1]|=(u&(1<<this.DB-s)-1)<<s,this[this.t++]=u>>this.DB-s):this[this.t-1]|=u<<s,(s+=e)>=this.DB&&(s-=this.DB))}8==e&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),o&&r.ZERO.subTo(this,this)}function p(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function v(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,e=(1<<i)-1,n=!1,o="",s=this.t,h=this.DB-s*this.DB%i;if(s-- >0)for(h<this.DB&&(r=this[s]>>h)>0&&(n=!0,o=u(r));s>=0;)h<i?(r=(this[s]&(1<<h)-1)<<i-h,r|=this[--s]>>(h+=this.DB-i)):(r=this[s]>>(h-=i)&e,h<=0&&(h+=this.DB,--s)),r>0&&(n=!0),n&&(o+=u(r));return n?o:"0"}function y(){var t=e();return r.ZERO.subTo(this,t),t}function m(){return this.s<0?this.negate():this}function g(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[r]-t[r]))return i;return 0}function d(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 T(){return this.t<=0?0:this.DB*(this.t-1)+d(this[this.t-1]^this.s&this.DM)}function F(t,i){var r;for(r=this.t-1;r>=0;--r)i[r+t]=this[r];for(r=t-1;r>=0;--r)i[r]=0;i.t=this.t+t,i.s=this.s}function b(t,i){for(var r=t;r<this.t;++r)i[r-t]=this[r];i.t=Math.max(this.t-t,0),i.s=this.s}function B(t,i){var r,e=t%this.DB,n=this.DB-e,o=(1<<n)-1,s=Math.floor(t/this.DB),u=this.s<<e&this.DM;for(r=this.t-1;r>=0;--r)i[r+s+1]=this[r]>>n|u,u=(this[r]&o)<<e;for(r=s-1;r>=0;--r)i[r]=0;i[s]=u,i.t=this.t+s+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 e=t%this.DB,n=this.DB-e,o=(1<<e)-1;i[0]=this[r]>>e;for(var s=r+1;s<this.t;++s)i[s-r-1]|=(this[s]&o)<<n,i[s-r]=this[s]>>e;e>0&&(i[this.t-r-1]|=(this.s&o)<<n),i.t=this.t-r,i.clamp()}function x(t,i){for(var r=0,e=0,n=Math.min(t.t,this.t);r<n;)e+=this[r]-t[r],i[r++]=e&this.DM,e>>=this.DB;if(t.t<this.t){for(e-=t.s;r<this.t;)e+=this[r],i[r++]=e&this.DM,e>>=this.DB;e+=this.s}else{for(e+=this.s;r<t.t;)e-=t[r],i[r++]=e&this.DM,e>>=this.DB;e-=t.s}i.s=e<0?-1:0,e<-1?i[r++]=this.DV+e:e>0&&(i[r++]=e),i.t=r,i.clamp()}function D(t,i){var e=this.abs(),n=t.abs(),o=e.t;for(i.t=o+n.t;--o>=0;)i[o]=0;for(o=0;o<n.t;++o)i[o+e.t]=e.am(0,n[o],i,o,0,e.t);i.s=0,i.clamp(),this.s!=t.s&&r.ZERO.subTo(i,i)}function S(t){for(var i=this.abs(),r=t.t=2*i.t;--r>=0;)t[r]=0;for(r=0;r<i.t-1;++r){var e=i.am(r,i[r],t,2*r,0,1);(t[r+i.t]+=i.am(r+1,2*i[r],t,2*r+1,e,i.t-r-1))>=i.DV&&(t[r+i.t]-=i.DV,t[r+i.t+1]=1)}t.t>0&&(t[t.t-1]+=i.am(r,i[r],t,2*r,0,1)),t.s=0,t.clamp()}function I(t,i,n){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!=n&&this.copyTo(n));null==n&&(n=e());var u=e(),h=this.s,a=t.s,f=this.DB-d(o[o.t-1]);f>0?(o.lShiftTo(f,u),s.lShiftTo(f,n)):(o.copyTo(u),s.copyTo(n));var l=u.t,c=u[l-1];if(0!=c){var p=c*(1<<this.F1)+(l>1?u[l-2]>>this.F2:0),v=this.FV/p,y=(1<<this.F1)/p,m=1<<this.F2,g=n.t,T=g-l,F=null==i?e():i;for(u.dlShiftTo(T,F),n.compareTo(F)>=0&&(n[n.t++]=1,n.subTo(F,n)),r.ONE.dlShiftTo(l,F),F.subTo(u,u);u.t<l;)u[u.t++]=0;for(;--T>=0;){var b=n[--g]==c?this.DM:Math.floor(n[g]*v+(n[g-1]+m)*y);if((n[g]+=u.am(0,b,n,T,0,l))<b)for(u.dlShiftTo(T,F),n.subTo(F,n);n[g]<--b;)n.subTo(F,n)}null!=i&&(n.drShiftTo(l,i),h!=a&&r.ZERO.subTo(i,i)),n.t=l,n.clamp(),f>0&&n.rShiftTo(f,n),h<0&&r.ZERO.subTo(n,n)}}}function q(t){var i=e();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(r.ZERO)>0&&t.subTo(i,i),i}function E(t){this.m=t}function O(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function A(t){return t}function R(t){t.divRemTo(this.m,null,t)}function P(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function M(t,i){t.squareTo(i),this.reduce(i)}function C(){if(this.t<1)return 0;var t=this[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 k(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 V(t){var i=e();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(r.ZERO)>0&&this.m.subTo(i,i),i}function H(t){var i=e();return t.copyTo(i),this.reduce(i),i}function N(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var i=0;i<this.m.t;++i){var r=32767&t[i],e=r*this.mpl+((r*this.mph+(t[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(r=i+this.m.t,t[r]+=this.m.am(0,e,t,i,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function j(t,i){t.squareTo(i),this.reduce(i)}function L(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function z(){return 0==(this.t>0?1&this[0]:this.s)}function Z(t,i){if(t>4294967295||t<1)return r.ONE;var n=e(),o=e(),s=i.convert(this),u=d(t)-1;for(s.copyTo(n);--u>=0;)if(i.sqrTo(n,o),(t&1<<u)>0)i.mulTo(o,s,n);else{var h=n;n=o,o=h}return i.revert(n)}function K(t,i){var r;return r=t<256||i.isEven()?new E(i):new k(i),this.exp(t,r)}function _(){var t=e();return this.copyTo(t),t}function X(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function U(){return 0==this.t?this.s:this[0]<<24>>24}function Y(){return 0==this.t?this.s:this[0]<<16>>16}function G(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function J(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function Q(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),n=l(r),o=e(),s=e(),u="";for(this.divRemTo(n,o,s);o.signum()>0;)u=(r+s.intValue()).toString(t).substr(1)+u,o.divRemTo(n,o,s);return s.intValue().toString(t)+u}function W(t,i){this.fromInt(0),null==i&&(i=10);for(var e=this.chunkSize(i),n=Math.pow(i,e),o=!1,s=0,u=0,a=0;a<t.length;++a){var f=h(t,a);f<0?"-"==t.charAt(a)&&0==this.signum()&&(o=!0):(u=i*u+f,++s>=e&&(this.dMultiply(n),this.dAddOffset(u,0),s=0,u=0))}s>0&&(this.dMultiply(Math.pow(i,s)),this.dAddOffset(u,0)),o&&r.ZERO.subTo(this,this)}function $(t,i,e){if("number"==typeof i)if(t<2)this.fromInt(1);else for(this.fromNumber(t,e),this.testBit(t-1)||this.bitwiseTo(r.ONE.shiftLeft(t-1),ut,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(r.ONE.shiftLeft(t-1),this);else{var n=new Array,o=7&t;n.length=1+(t>>3),i.nextBytes(n),o>0?n[0]&=(1<<o)-1:n[0]=0,this.fromString(n,256)}}function tt(){var t=this.t,i=new Array;i[0]=this.s;var r,e=this.DB-t*this.DB%8,n=0;if(t-- >0)for(e<this.DB&&(r=this[t]>>e)!=(this.s&this.DM)>>e&&(i[n++]=r|this.s<<this.DB-e);t>=0;)e<8?(r=(this[t]&(1<<e)-1)<<8-e,r|=this[--t]>>(e+=this.DB-8)):(r=this[t]>>(e-=8)&255,e<=0&&(e+=this.DB,--t)),0!=(128&r)&&(r|=-256),0==n&&(128&this.s)!=(128&r)&&++n,(n>0||r!=this.s)&&(i[n++]=r);return i}function it(t){return 0==this.compareTo(t)}function rt(t){return this.compareTo(t)<0?this:t}function et(t){return this.compareTo(t)>0?this:t}function nt(t,i,r){var e,n,o=Math.min(t.t,this.t);for(e=0;e<o;++e)r[e]=i(this[e],t[e]);if(t.t<this.t){for(n=t.s&this.DM,e=o;e<this.t;++e)r[e]=i(this[e],n);r.t=this.t}else{for(n=this.s&this.DM,e=o;e<t.t;++e)r[e]=i(n,t[e]);r.t=t.t}r.s=i(this.s,t.s),r.clamp()}function ot(t,i){return t&i}function st(t){var i=e();return this.bitwiseTo(t,ot,i),i}function ut(t,i){return t|i}function ht(t){var i=e();return this.bitwiseTo(t,ut,i),i}function at(t,i){return t^i}function ft(t){var i=e();return this.bitwiseTo(t,at,i),i}function lt(t,i){return t&~i}function ct(t){var i=e();return this.bitwiseTo(t,lt,i),i}function pt(){for(var t=e(),i=0;i<this.t;++i)t[i]=this.DM&~this[i];return t.t=this.t,t.s=~this.s,t}function vt(t){var i=e();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i}function yt(t){var i=e();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i}function mt(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 gt(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+mt(this[t]);return this.s<0?this.t*this.DB:-1}function dt(t){for(var i=0;0!=t;)t&=t-1,++i;return i}function Tt(){for(var t=0,i=this.s&this.DM,r=0;r<this.t;++r)t+=dt(this[r]^i);return t}function Ft(t){var i=Math.floor(t/this.DB);return i>=this.t?0!=this.s:0!=(this[i]&1<<t%this.DB)}function bt(t,i){var e=r.ONE.shiftLeft(t);return this.bitwiseTo(e,i,e),e}function Bt(t){return this.changeBit(t,ut)}function wt(t){return this.changeBit(t,lt)}function xt(t){return this.changeBit(t,at)}function Dt(t,i){for(var r=0,e=0,n=Math.min(t.t,this.t);r<n;)e+=this[r]+t[r],i[r++]=e&this.DM,e>>=this.DB;if(t.t<this.t){for(e+=t.s;r<this.t;)e+=this[r],i[r++]=e&this.DM,e>>=this.DB;e+=this.s}else{for(e+=this.s;r<t.t;)e+=t[r],i[r++]=e&this.DM,e>>=this.DB;e+=t.s}i.s=e<0?-1:0,e>0?i[r++]=e:e<-1&&(i[r++]=this.DV+e),i.t=r,i.clamp()}function St(t){var i=e();return this.addTo(t,i),i}function It(t){var i=e();return this.subTo(t,i),i}function qt(t){var i=e();return this.multiplyTo(t,i),i}function Et(){var t=e();return this.squareTo(t),t}function Ot(t){var i=e();return this.divRemTo(t,i,null),i}function At(t){var i=e();return this.divRemTo(t,null,i),i}function Rt(t){var i=e(),r=e();return this.divRemTo(t,i,r),new Array(i,r)}function Pt(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function Mt(t,i){if(0!=t){for(;this.t<=i;)this[this.t++]=0;for(this[i]+=t;this[i]>=this.DV;)this[i]-=this.DV,++i>=this.t&&(this[this.t++]=0),++this[i]}}function Ct(){}function kt(t){return t}function Vt(t,i,r){t.multiplyTo(i,r)}function Ht(t,i){t.squareTo(i)}function Nt(t){return this.exp(t,new Ct)}function jt(t,i,r){var e=Math.min(this.t+t.t,i);for(r.s=0,r.t=e;e>0;)r[--e]=0;var n;for(n=r.t-this.t;e<n;++e)r[e+this.t]=this.am(0,t[e],r,e,0,this.t);for(n=Math.min(t.t,i);e<n;++e)this.am(0,t[e],r,e,0,i-e);r.clamp()}function Lt(t,i,r){--i;var e=r.t=this.t+t.t-i;for(r.s=0;--e>=0;)r[e]=0;for(e=Math.max(i-this.t,0);e<t.t;++e)r[this.t+e-i]=this.am(i-e,t[e],r,0,0,this.t+e-i);r.clamp(),r.drShiftTo(1,r)}function zt(t){this.r2=e(),this.q3=e(),r.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function Zt(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=e();return t.copyTo(i),this.reduce(i),i}function Kt(t){return t}function _t(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 Xt(t,i){t.squareTo(i),this.reduce(i)}function Ut(t,i,r){t.multiplyTo(i,r),this.reduce(r)}function Yt(t,i){var r,n,o=t.bitLength(),s=l(1);if(o<=0)return s;r=o<18?1:o<48?3:o<144?4:o<768?5:6,n=o<8?new E(i):i.isEven()?new zt(i):new k(i);var u=new Array,h=3,a=r-1,f=(1<<r)-1;if(u[1]=n.convert(this),r>1){var c=e();for(n.sqrTo(u[1],c);h<=f;)u[h]=e(),n.mulTo(c,u[h-2],u[h]),h+=2}var p,v,y=t.t-1,m=!0,g=e();for(o=d(t[y])-1;y>=0;){for(o>=a?p=t[y]>>o-a&f:(p=(t[y]&(1<<o+1)-1)<<a-o,y>0&&(p|=t[y-1]>>this.DB+o-a)),h=r;0==(1&p);)p>>=1,--h;if((o-=h)<0&&(o+=this.DB,--y),m)u[p].copyTo(s),m=!1;else{for(;h>1;)n.sqrTo(s,g),n.sqrTo(g,s),h-=2;h>0?n.sqrTo(s,g):(v=s,s=g,g=v),n.mulTo(g,u[p],s)}for(;y>=0&&0==(t[y]&1<<o);)n.sqrTo(s,g),v=s,s=g,g=v,--o<0&&(o=this.DB-1,--y)}return n.revert(s)}function Gt(t){var i=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(i.compareTo(r)<0){var e=i;i=r,r=e}var n=i.getLowestSetBit(),o=r.getLowestSetBit();if(o<0)return i;for(n<o&&(o=n),o>0&&(i.rShiftTo(o,i),r.rShiftTo(o,r));i.signum()>0;)(n=i.getLowestSetBit())>0&&i.rShiftTo(n,i),(n=r.getLowestSetBit())>0&&r.rShiftTo(n,r),i.compareTo(r)>=0?(i.subTo(r,i),i.rShiftTo(1,i)):(r.subTo(i,r),r.rShiftTo(1,r));return o>0&&r.lShiftTo(o,r),r}function Jt(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[0]%t;else for(var e=this.t-1;e>=0;--e)r=(i*r+this[e])%t;return r}function Qt(t){var i=t.isEven();if(this.isEven()&&i||0==t.signum())return r.ZERO;for(var e=t.clone(),n=this.clone(),o=l(1),s=l(0),u=l(0),h=l(1);0!=e.signum();){for(;e.isEven();)e.rShiftTo(1,e),i?(o.isEven()&&s.isEven()||(o.addTo(this,o),s.subTo(t,s)),o.rShiftTo(1,o)):s.isEven()||s.subTo(t,s),s.rShiftTo(1,s);for(;n.isEven();)n.rShiftTo(1,n),i?(u.isEven()&&h.isEven()||(u.addTo(this,u),h.subTo(t,h)),u.rShiftTo(1,u)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);e.compareTo(n)>=0?(e.subTo(n,e),i&&o.subTo(u,o),s.subTo(h,s)):(n.subTo(e,n),i&&u.subTo(o,u),h.subTo(s,h))}return 0!=n.compareTo(r.ONE)?r.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h}function Wt(t){var i,r=this.abs();if(1==r.t&&r[0]<=yi[yi.length-1]){for(i=0;i<yi.length;++i)if(r[0]==yi[i])return!0;return!1}if(r.isEven())return!1;for(i=1;i<yi.length;){for(var e=yi[i],n=i+1;n<yi.length&&e<mi;)e*=yi[n++];for(e=r.modInt(e);i<n;)if(e%yi[i++]==0)return!1}return r.millerRabin(t)}function $t(t){var i=this.subtract(r.ONE),n=i.getLowestSetBit();if(n<=0)return!1;var o=i.shiftRight(n);(t=t+1>>1)>yi.length&&(t=yi.length);for(var s=e(),u=0;u<t;++u){s.fromInt(yi[Math.floor(Math.random()*yi.length)]);var h=s.modPow(o,this);if(0!=h.compareTo(r.ONE)&&0!=h.compareTo(i)){for(var a=1;a++<n&&0!=h.compareTo(i);)if(h=h.modPowInt(2,this),0==h.compareTo(r.ONE))return!1;if(0!=h.compareTo(i))return!1}}return!0}function ti(t){di[Ti++]^=255&t,di[Ti++]^=t>>8&255,di[Ti++]^=t>>16&255,di[Ti++]^=t>>24&255,Ti>=wi&&(Ti-=wi)}function ii(){ti((new Date).getTime())}function ri(){if(null==gi){for(ii(),gi=hi(),gi.init(di),Ti=0;Ti<di.length;++Ti)di[Ti]=0;Ti=0}return gi.next()}function ei(t){var i;for(i=0;i<t.length;++i)t[i]=ri()}function ni(){}function oi(){this.i=0,this.j=0,this.S=new Array}function si(t){var i,r,e;for(i=0;i<256;++i)this.S[i]=i;for(r=0,i=0;i<256;++i)r=r+this.S[i]+t[i%t.length]&255,e=this.S[i],this.S[i]=this.S[r],this.S[r]=e;this.i=0,this.j=0}function ui(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}function hi(){return new oi}var ai,fi="undefined"!=typeof navigator;fi&&"Microsoft Internet Explorer"==navigator.appName?(r.prototype.am=o,ai=30):fi&&"Netscape"!=navigator.appName?(r.prototype.am=n,ai=26):(r.prototype.am=s,ai=28),r.prototype.DB=ai,r.prototype.DM=(1<<ai)-1,r.prototype.DV=1<<ai;r.prototype.FV=Math.pow(2,52),r.prototype.F1=52-ai,r.prototype.F2=2*ai-52;var li,ci,pi="0123456789abcdefghijklmnopqrstuvwxyz",vi=new Array;for(li="0".charCodeAt(0),ci=0;ci<=9;++ci)vi[li++]=ci;for(li="a".charCodeAt(0),ci=10;ci<36;++ci)vi[li++]=ci;for(li="A".charCodeAt(0),ci=10;ci<36;++ci)vi[li++]=ci;E.prototype.convert=O,E.prototype.revert=A,E.prototype.reduce=R,E.prototype.mulTo=P,E.prototype.sqrTo=M,k.prototype.convert=V,k.prototype.revert=H,k.prototype.reduce=N,k.prototype.mulTo=L,k.prototype.sqrTo=j,r.prototype.copyTo=a,r.prototype.fromInt=f,r.prototype.fromString=c,r.prototype.clamp=p,r.prototype.dlShiftTo=F,r.prototype.drShiftTo=b,r.prototype.lShiftTo=B,r.prototype.rShiftTo=w,r.prototype.subTo=x,r.prototype.multiplyTo=D,r.prototype.squareTo=S,r.prototype.divRemTo=I,r.prototype.invDigit=C,r.prototype.isEven=z,r.prototype.exp=Z,r.prototype.toString=v,r.prototype.negate=y,r.prototype.abs=m,r.prototype.compareTo=g,r.prototype.bitLength=T,r.prototype.mod=q,r.prototype.modPowInt=K,r.ZERO=l(0),r.ONE=l(1),Ct.prototype.convert=kt,Ct.prototype.revert=kt,Ct.prototype.mulTo=Vt,Ct.prototype.sqrTo=Ht,zt.prototype.convert=Zt,zt.prototype.revert=Kt,zt.prototype.reduce=_t,zt.prototype.mulTo=Ut,zt.prototype.sqrTo=Xt;var yi=[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],mi=(1<<26)/yi[yi.length-1];r.prototype.chunkSize=G,r.prototype.toRadix=Q,r.prototype.fromRadix=W,r.prototype.fromNumber=$,r.prototype.bitwiseTo=nt,r.prototype.changeBit=bt,r.prototype.addTo=Dt,r.prototype.dMultiply=Pt,r.prototype.dAddOffset=Mt,r.prototype.multiplyLowerTo=jt,r.prototype.multiplyUpperTo=Lt,r.prototype.modInt=Jt,r.prototype.millerRabin=$t,r.prototype.clone=_,r.prototype.intValue=X,r.prototype.byteValue=U,r.prototype.shortValue=Y,r.prototype.signum=J,r.prototype.toByteArray=tt,r.prototype.equals=it,r.prototype.min=rt,r.prototype.max=et,r.prototype.and=st,r.prototype.or=ht,r.prototype.xor=ft,r.prototype.andNot=ct,r.prototype.not=pt,r.prototype.shiftLeft=vt,r.prototype.shiftRight=yt,r.prototype.getLowestSetBit=gt,r.prototype.bitCount=Tt,r.prototype.testBit=Ft,r.prototype.setBit=Bt,r.prototype.clearBit=wt,r.prototype.flipBit=xt,r.prototype.add=St,r.prototype.subtract=It,r.prototype.multiply=qt,r.prototype.divide=Ot,r.prototype.remainder=At,r.prototype.divideAndRemainder=Rt,r.prototype.modPow=Yt,r.prototype.modInverse=Qt,r.prototype.pow=Nt,r.prototype.gcd=Gt,r.prototype.isProbablePrime=Wt,r.prototype.square=Et,r.prototype.Barrett=zt;var gi,di,Ti;if(null==di){di=new Array,Ti=0;var Fi;if("undefined"!=typeof window&&window.crypto)if(window.crypto.getRandomValues){var bi=new Uint8Array(32);for(window.crypto.getRandomValues(bi),Fi=0;Fi<32;++Fi)di[Ti++]=bi[Fi]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var Bi=window.crypto.random(32);for(Fi=0;Fi<Bi.length;++Fi)di[Ti++]=255&Bi.charCodeAt(Fi)}for(;Ti<wi;)Fi=Math.floor(65536*Math.random()),di[Ti++]=Fi>>>8,di[Ti++]=255&Fi;Ti=0,ii()}ni.prototype.nextBytes=ei,oi.prototype.init=si,oi.prototype.next=ui;var wi=256;i=t.exports={default:r,BigInteger:r,SecureRandom:ni}}).call(this)},function(t,i,r){"use strict";function e(t,i){for(var r=[],e=~~(i/8),n=i%8,o=0,s=t.length;o<s;o++)r[o]=(t[(o+e)%s]<<n&255)+(t[(o+e+1)%s]>>>8-n&255);return r}function n(t,i){for(var r=[],e=t.length-1;e>=0;e--)r[e]=255&(t[e]^i[e]);return r}function o(t,i){for(var r=[],e=t.length-1;e>=0;e--)r[e]=t[e]&i[e]&255;return r}function s(t,i){for(var r=[],e=t.length-1;e>=0;e--)r[e]=255&(t[e]|i[e]);return r}function u(t,i){for(var r=[],e=0,n=t.length-1;n>=0;n--){var o=t[n]+i[n]+e;o>255?(e=1,r[n]=255&o):(e=0,r[n]=255&o)}return r}function h(t){for(var i=[],r=t.length-1;r>=0;r--)i[r]=255&~t[r];return i}function a(t){return n(n(t,e(t,9)),e(t,17))}function f(t){return n(n(t,e(t,15)),e(t,23))}function l(t,i,r,e){return e>=0&&e<=15?n(n(t,i),r):s(s(o(t,i),o(t,r)),o(i,r))}function c(t,i,r,e){return e>=0&&e<=15?n(n(t,i),r):s(o(t,i),o(h(t),r))}function p(t,i){for(var r=[],o=[],s=0;s<16;s++){var h=4*s;r.push(i.slice(h,h+4))}for(var p=16;p<68;p++)r.push(n(n(f(n(n(r[p-16],r[p-9]),e(r[p-3],15))),e(r[p-13],7)),r[p-6]));for(var v=0;v<64;v++)o.push(n(r[v],r[v+4]));for(var y=[121,204,69,25],m=[122,135,157,138],g=t.slice(0,4),d=t.slice(4,8),T=t.slice(8,12),F=t.slice(12,16),b=t.slice(16,20),B=t.slice(20,24),w=t.slice(24,28),x=t.slice(28,32),D=void 0,S=void 0,I=void 0,q=void 0,E=0;E<64;E++){var O=E>=0&&E<=15?y:m;D=e(u(u(e(g,12),b),e(O,E)),7),S=n(D,e(g,12)),I=u(u(u(l(g,d,T,E),F),S),o[E]),q=u(u(u(c(b,B,w,E),x),D),r[E]),F=T,T=e(d,9),d=g,g=I,x=w,w=e(B,19),B=b,b=a(q)}return n([].concat(g,d,T,F,b,B,w,x),t)}t.exports=function(t){var i=8*t.length,r=i%512;r=r>=448?512-r%448-1:448-r-1;for(var e=new Array((r-7)/8),n=0,o=e.length;n<o;n++)e[n]=0;var s=[];i=i.toString(2);for(var u=7;u>=0;u--)if(i.length>8){var h=i.length-8;s[u]=parseInt(i.substr(h),2),i=i.substr(0,h)}else i.length>0?(s[u]=parseInt(i,2),i=""):s[u]=0;for(var a=[].concat(t,[128],e,s),f=a.length/64,l=[115,128,22,111,73,20,178,185,23,36,66,215,218,138,6,0,169,111,48,188,22,49,56,170,227,141,238,77,176,251,14,78],c=0;c<f;c++){var v=64*c;l=p(l,a.slice(v,v+64))}return l}},function(t,i,r){"use strict";function e(t){if(Array.isArray(t)){for(var i=0,r=Array(t.length);i<t.length;i++)r[i]=t[i];return r}return Array.from(t)}function n(t,i){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;t="string"==typeof t?m.hexToArray(m.utf8ToHex(t)):Array.prototype.slice.call(t),i=m.getGlobalCurve().decodePointHex(i);var n=m.generateKeyPairHex(),o=new c(n.privateKey,16),s=n.publicKey;s.length>128&&(s=s.substr(s.length-128));var u=i.multiply(o),h=m.hexToArray(m.leftPad(u.getX().toBigInteger().toRadix(16),64)),a=m.hexToArray(m.leftPad(u.getY().toBigInteger().toRadix(16),64)),f=m.arrayToHex(g([].concat(h,t,a))),l=1,p=0,v=[],y=[].concat(h,a),d=function(){v=g([].concat(e(y),[l>>24&255,l>>16&255,l>>8&255,255&l])),l++,p=0};d();for(var T=0,F=t.length;T<F;T++)p===v.length&&d(),t[T]^=255&v[p++];var b=m.arrayToHex(t);return r===B?s+b+f:s+f+b}function o(t,i){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=n.output,s=void 0===o?"string":o;i=new c(i,16);var u=t.substr(128,64),h=t.substr(192);r===B&&(u=t.substr(t.length-64),h=t.substr(128,t.length-128-64));var a=m.hexToArray(h),f=m.getGlobalCurve().decodePointHex("04"+t.substr(0,128)),l=f.multiply(i),p=m.hexToArray(m.leftPad(l.getX().toBigInteger().toRadix(16),64)),v=m.hexToArray(m.leftPad(l.getY().toBigInteger().toRadix(16),64)),y=1,d=0,T=[],F=[].concat(p,v),b=function(){T=g([].concat(e(F),[y>>24&255,y>>16&255,y>>8&255,255&y])),y++,d=0};b();for(var w=0,x=a.length;w<x;w++)d===T.length&&b(),a[w]^=255&T[d++];return m.arrayToHex(g([].concat(p,a,v)))===u.toLowerCase()?"array"===s?a:m.arrayToUtf8(a):"array"===s?[]:""}function s(t,i){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},e=r.pointPool,n=r.der,o=r.hash,s=r.publicKey,u=r.userId,l="string"==typeof t?m.utf8ToHex(t):m.arrayToHex(t);o&&(s=s||a(i),l=h(l,s,u));var p=new c(i,16),y=new c(l,16),g=null,d=null,T=null;do{do{var F=void 0;F=e&&e.length?e.pop():f(),g=F.k,d=y.add(F.x1).mod(b)}while(d.equals(c.ZERO)||d.add(g).equals(b));T=p.add(c.ONE).modInverse(b).multiply(g.subtract(d.multiply(p))).mod(b)}while(T.equals(c.ZERO));return n?v(d,T):m.leftPad(d.toString(16),64)+m.leftPad(T.toString(16),64)}function u(t,i,r){var e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=e.der,o=e.hash,s=e.userId,u="string"==typeof t?m.utf8ToHex(t):m.arrayToHex(t);o&&(u=h(u,r,s));var a=void 0,f=void 0;if(n){var l=y(i);a=l.r,f=l.s}else a=new c(i.substring(0,64),16),f=new c(i.substring(64),16);var p=F.decodePointHex(r),v=new c(u,16),g=a.add(f).mod(b);if(g.equals(c.ZERO))return!1;var d=T.multiply(f).add(p.multiply(g)),B=v.add(d.getX().toBigInteger()).mod(b);return a.equals(B)}function h(t,i){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"1234567812345678";r=m.utf8ToHex(r);var e=m.leftPad(T.curve.a.toBigInteger().toRadix(16),64),n=m.leftPad(T.curve.b.toBigInteger().toRadix(16),64),o=m.leftPad(T.getX().toBigInteger().toRadix(16),64),s=m.leftPad(T.getY().toBigInteger().toRadix(16),64);i.length>128&&(i=i.substr(2,128));var u=i.substr(0,64),h=i.substr(64,64),a=m.hexToArray(r+e+n+o+s+u+h),f=4*r.length;a.unshift(255&f),a.unshift(f>>8&255);var l=g(a);return m.arrayToHex(g(l.concat(m.hexToArray(t))))}function a(t){var i=T.multiply(new c(t,16));return"04"+m.leftPad(i.getX().toBigInteger().toString(16),64)+m.leftPad(i.getY().toBigInteger().toString(16),64)}function f(){var t=m.generateKeyPairHex(),i=F.decodePointHex(t.publicKey);return t.k=new c(t.privateKey,16),t.x1=i.getX().toBigInteger(),t}var l=r(0),c=l.BigInteger,p=r(3),v=p.encodeDer,y=p.decodeDer,m=r(4),g=r(1),d=m.generateEcparam(),T=d.G,F=d.curve,b=d.n,B=0;t.exports={generateKeyPairHex:m.generateKeyPairHex,doEncrypt:n,doDecrypt:o,doSignature:s,doVerifySignature:u,getPoint:f,verifyPublicKey:m.verifyPublicKey}},function(t,i,r){"use strict";function e(t,i){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!i||"object"!=typeof i&&"function"!=typeof i?t:i}function n(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Super expression must either be null or a function, not "+typeof i);t.prototype=Object.create(i&&i.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),i&&(Object.setPrototypeOf?Object.setPrototypeOf(t,i):t.__proto__=i)}function o(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}function s(t){var i=t.toString(16);if("-"!==i[0])i.length%2==1?i="0"+i:i.match(/^[0-7]/)||(i="00"+i);else{i=i.substr(1);var r=i.length;r%2==1?r+=1:i.match(/^[0-7]/)||(r+=2);for(var e="",n=0;n<r;n++)e+="f";e=new c(e,16),i=e.xor(t).add(c.ONE),i=i.toString(16).replace(/^-/,"")}return i}function u(t,i){return+t[i+2]<8?1:128&+t.substr(i+2,2)}function h(t,i){var r=u(t,i),e=t.substr(i+2,2*r);return e?(+e[0]<8?new c(e,16):new c(e.substr(2),16)).intValue():-1}function a(t,i){return i+2*(u(t,i)+1)}var f=function(){function t(t,i){for(var r=0;r<i.length;r++){var e=i[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}return function(i,r,e){return r&&t(i.prototype,r),e&&t(i,e),i}}(),l=r(0),c=l.BigInteger,p=function(){function t(){o(this,t),this.tlv=null,this.t="00",this.l="00",this.v=""}return f(t,[{key:"getEncodedHex",value:function(){return this.tlv||(this.v=this.getValue(),this.l=this.getLength(),this.tlv=this.t+this.l+this.v),this.tlv}},{key:"getLength",value:function(){var t=this.v.length/2,i=t.toString(16);return i.length%2==1&&(i="0"+i),t<128?i:(128+i.length/2).toString(16)+i}},{key:"getValue",value:function(){return""}}]),t}(),v=function(t){function i(t){o(this,i);var r=e(this,(i.__proto__||Object.getPrototypeOf(i)).call(this));return r.t="02",t&&(r.v=s(t)),r}return n(i,t),f(i,[{key:"getValue",value:function(){return this.v}}]),i}(p),y=function(t){function i(t){o(this,i);var r=e(this,(i.__proto__||Object.getPrototypeOf(i)).call(this));return r.t="30",r.asn1Array=t,r}return n(i,t),f(i,[{key:"getValue",value:function(){return this.v=this.asn1Array.map(function(t){return t.getEncodedHex()}).join(""),this.v}}]),i}(p);t.exports={encodeDer:function(t,i){var r=new v(t),e=new v(i);return new y([r,e]).getEncodedHex()},decodeDer:function(t){var i=a(t,0),r=a(t,i),e=h(t,i),n=t.substr(r,2*e),o=r+n.length,s=a(t,o),u=h(t,o),f=t.substr(s,2*u);return{r:new c(n,16),s:new c(f,16)}}}},function(t,i,r){"use strict";function e(){return T}function n(){var t=new p("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",16),i=new p("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",16),r=new p("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",16),e=new m(t,i,r);return{curve:e,G:e.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0"),n:new p("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",16)}}function o(t,i,r){var e=t?new p(t,i,r):new p(b.bitLength(),g),n=e.mod(b.subtract(p.ONE)).add(p.ONE),o=u(n.toString(16),64),s=F.multiply(n);return{privateKey:o,publicKey:"04"+u(s.getX().toBigInteger().toString(16),64)+u(s.getY().toBigInteger().toString(16),64)}}function s(t){t=unescape(encodeURIComponent(t));for(var i=t.length,r=[],e=0;e<i;e++)r[e>>>2]|=(255&t.charCodeAt(e))<<24-e%4*8;for(var n=[],o=0;o<i;o++){var s=r[o>>>2]>>>24-o%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")}function u(t,i){return t.length>=i?t:new Array(i-t.length+1).join("0")+t}function h(t){return t.map(function(t){return t=t.toString(16),1===t.length?"0"+t:t}).join("")}function a(t){for(var i=[],r=0,e=0;e<2*t.length;e+=2)i[e>>>3]|=parseInt(t[r],10)<<24-e%8*4,r++;try{for(var n=[],o=0;o<t.length;o++){var s=i[o>>>2]>>>24-o%4*8&255;n.push(String.fromCharCode(s))}return decodeURIComponent(escape(n.join("")))}catch(t){throw new Error("Malformed UTF-8 data")}}function f(t){var i=[],r=t.length;r%2!=0&&(t=u(t,r+1)),r=t.length;for(var e=0;e<r;e+=2)i.push(parseInt(t.substr(e,2),16));return i}function l(t){var i=T.decodePointHex(t);if(!i)return!1;var r=i.getX();return i.getY().square().equals(r.multiply(r.square()).add(r.multiply(T.a)).add(T.b))}var c=r(0),p=c.BigInteger,v=c.SecureRandom,y=r(5),m=y.ECCurveFp,g=new v,d=n(),T=d.curve,F=d.G,b=d.n;t.exports={getGlobalCurve:e,generateEcparam:n,generateKeyPairHex:o,utf8ToHex:s,leftPad:u,arrayToHex:h,arrayToUtf8:a,hexToArray:f,verifyPublicKey:l}},function(t,i,r){"use strict";function e(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}var n=function(){function t(t,i){for(var r=0;r<i.length;r++){var e=i[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}return function(i,r,e){return r&&t(i.prototype,r),e&&t(i,e),i}}(),o=r(0),s=o.BigInteger,u=new s("3"),h=function(){function t(i,r){e(this,t),this.x=r,this.q=i}return n(t,[{key:"equals",value:function(t){return t===this||this.q.equals(t.q)&&this.x.equals(t.x)}},{key:"toBigInteger",value:function(){return this.x}},{key:"negate",value:function(){return new t(this.q,this.x.negate().mod(this.q))}},{key:"add",value:function(i){return new t(this.q,this.x.add(i.toBigInteger()).mod(this.q))}},{key:"subtract",value:function(i){return new t(this.q,this.x.subtract(i.toBigInteger()).mod(this.q))}},{key:"multiply",value:function(i){return new t(this.q,this.x.multiply(i.toBigInteger()).mod(this.q))}},{key:"divide",value:function(i){return new t(this.q,this.x.multiply(i.toBigInteger().modInverse(this.q)).mod(this.q))}},{key:"square",value:function(){return new t(this.q,this.x.square().mod(this.q))}}]),t}(),a=function(){function t(i,r,n,o){e(this,t),this.curve=i,this.x=r,this.y=n,this.z=null==o?s.ONE:o,this.zinv=null}return n(t,[{key:"getX",value:function(){return null===this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}},{key:"getY",value:function(){return null===this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}},{key:"equals",value:function(t){return t===this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():!!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(s.ZERO)&&t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(s.ZERO))}},{key:"isInfinity",value:function(){return null===this.x&&null===this.y||this.z.equals(s.ZERO)&&!this.y.toBigInteger().equals(s.ZERO)}},{key:"negate",value:function(){return new t(this.curve,this.x,this.y.negate(),this.z)}},{key:"add",value:function(i){if(this.isInfinity())return i;if(i.isInfinity())return this;var r=this.x.toBigInteger(),e=this.y.toBigInteger(),n=this.z,o=i.x.toBigInteger(),u=i.y.toBigInteger(),h=i.z,a=this.curve.q,f=r.multiply(h).mod(a),l=o.multiply(n).mod(a),c=f.subtract(l),p=e.multiply(h).mod(a),v=u.multiply(n).mod(a),y=p.subtract(v);if(s.ZERO.equals(c))return s.ZERO.equals(y)?this.twice():this.curve.infinity;var m=f.add(l),g=n.multiply(h).mod(a),d=c.square().mod(a),T=c.multiply(d).mod(a),F=g.multiply(y.square()).subtract(m.multiply(d)).mod(a),b=c.multiply(F).mod(a),B=y.multiply(d.multiply(f).subtract(F)).subtract(p.multiply(T)).mod(a),w=T.multiply(g).mod(a);return new t(this.curve,this.curve.fromBigInteger(b),this.curve.fromBigInteger(B),w)}},{key:"twice",value:function(){if(this.isInfinity())return this;if(!this.y.toBigInteger().signum())return this.curve.infinity;var i=this.x.toBigInteger(),r=this.y.toBigInteger(),e=this.z,n=this.curve.q,o=this.curve.a.toBigInteger(),s=i.square().multiply(u).add(o.multiply(e.square())).mod(n),h=r.shiftLeft(1).multiply(e).mod(n),a=r.square().mod(n),f=a.multiply(i).multiply(e).mod(n),l=h.square().mod(n),c=s.square().subtract(f.shiftLeft(3)).mod(n),p=h.multiply(c).mod(n),v=s.multiply(f.shiftLeft(2).subtract(c)).subtract(l.shiftLeft(1).multiply(a)).mod(n),y=h.multiply(l).mod(n);return new t(this.curve,this.curve.fromBigInteger(p),this.curve.fromBigInteger(v),y)}},{key:"multiply",value:function(t){if(this.isInfinity())return this;if(!t.signum())return this.curve.infinity;for(var i=t.multiply(u),r=this.negate(),e=this,n=i.bitLength()-2;n>0;n--){e=e.twice();var o=i.testBit(n);o!==t.testBit(n)&&(e=e.add(o?this:r))}return e}}]),t}(),f=function(){function t(i,r,n){e(this,t),this.q=i,this.a=this.fromBigInteger(r),this.b=this.fromBigInteger(n),this.infinity=new a(this,null,null)}return n(t,[{key:"equals",value:function(t){return t===this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}},{key:"fromBigInteger",value:function(t){return new h(this.q,t)}},{key:"decodePointHex",value:function(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var i=(t.length-2)/2,r=t.substr(2,i),e=t.substr(i+2,i);return new a(this,this.fromBigInteger(new s(r,16)),this.fromBigInteger(new s(e,16)));default:return null}}}]),t}();t.exports={ECPointFp:a,ECCurveFp:f}}])}); | ||
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.sm2=r():t.sm2=r()}("undefined"!=typeof self?self:this,function(){return function(t){function r(e){if(i[e])return i[e].exports;var n=i[e]={i:e,l:!1,exports:{}};return t[e].call(n.exports,n,n.exports,r),n.l=!0,n.exports}var i={};return r.m=t,r.c=i,r.d=function(t,i,e){r.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:e})},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,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=2)}([function(t,r,i){(function(){function i(t,r,i){null!=t&&("number"==typeof t?this.fromNumber(t,r,i):null==r&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,r))}function e(){return new i(null)}function n(t,r,i,e,n,o){for(;--o>=0;){var s=r*this[t++]+i[e]+n;n=Math.floor(s/67108864),i[e++]=67108863&s}return n}function o(t,r,i,e,n,o){for(var s=32767&r,u=r>>15;--o>=0;){var h=32767&this[t],a=this[t++]>>15,f=u*h+a*s;h=s*h+((32767&f)<<15)+i[e]+(1073741823&n),n=(h>>>30)+(f>>>15)+u*a+(n>>>30),i[e++]=1073741823&h}return n}function s(t,r,i,e,n,o){for(var s=16383&r,u=r>>14;--o>=0;){var h=16383&this[t],a=this[t++]>>14,f=u*h+a*s;h=s*h+((16383&f)<<14)+i[e]+n,n=(h>>28)+(f>>14)+u*a,i[e++]=268435455&h}return n}function u(t){return pr.charAt(t)}function h(t,r){var i=vr[t.charCodeAt(r)];return null==i?-1:i}function a(t){for(var r=this.t-1;r>=0;--r)t[r]=this[r];t.t=this.t,t.s=this.s}function f(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}function l(t){var r=e();return r.fromInt(t),r}function c(t,r){var e;if(16==r)e=4;else if(8==r)e=3;else if(256==r)e=8;else if(2==r)e=1;else if(32==r)e=5;else{if(4!=r)return void this.fromRadix(t,r);e=2}this.t=0,this.s=0;for(var n=t.length,o=!1,s=0;--n>=0;){var u=8==e?255&t[n]:h(t,n);u<0?"-"==t.charAt(n)&&(o=!0):(o=!1,0==s?this[this.t++]=u:s+e>this.DB?(this[this.t-1]|=(u&(1<<this.DB-s)-1)<<s,this[this.t++]=u>>this.DB-s):this[this.t-1]|=u<<s,(s+=e)>=this.DB&&(s-=this.DB))}8==e&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),o&&i.ZERO.subTo(this,this)}function p(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function v(t){if(this.s<0)return"-"+this.negate().toString(t);var r;if(16==t)r=4;else if(8==t)r=3;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)return this.toRadix(t);r=2}var i,e=(1<<r)-1,n=!1,o="",s=this.t,h=this.DB-s*this.DB%r;if(s-- >0)for(h<this.DB&&(i=this[s]>>h)>0&&(n=!0,o=u(i));s>=0;)h<r?(i=(this[s]&(1<<h)-1)<<r-h,i|=this[--s]>>(h+=this.DB-r)):(i=this[s]>>(h-=r)&e,h<=0&&(h+=this.DB,--s)),i>0&&(n=!0),n&&(o+=u(i));return n?o:"0"}function y(){var t=e();return i.ZERO.subTo(this,t),t}function m(){return this.s<0?this.negate():this}function g(t){var r=this.s-t.s;if(0!=r)return r;var i=this.t;if(0!=(r=i-t.t))return this.s<0?-r:r;for(;--i>=0;)if(0!=(r=this[i]-t[i]))return r;return 0}function d(t){var r,i=1;return 0!=(r=t>>>16)&&(t=r,i+=16),0!=(r=t>>8)&&(t=r,i+=8),0!=(r=t>>4)&&(t=r,i+=4),0!=(r=t>>2)&&(t=r,i+=2),0!=(r=t>>1)&&(t=r,i+=1),i}function T(){return this.t<=0?0:this.DB*(this.t-1)+d(this[this.t-1]^this.s&this.DM)}function F(t,r){var i;for(i=this.t-1;i>=0;--i)r[i+t]=this[i];for(i=t-1;i>=0;--i)r[i]=0;r.t=this.t+t,r.s=this.s}function b(t,r){for(var i=t;i<this.t;++i)r[i-t]=this[i];r.t=Math.max(this.t-t,0),r.s=this.s}function B(t,r){var i,e=t%this.DB,n=this.DB-e,o=(1<<n)-1,s=Math.floor(t/this.DB),u=this.s<<e&this.DM;for(i=this.t-1;i>=0;--i)r[i+s+1]=this[i]>>n|u,u=(this[i]&o)<<e;for(i=s-1;i>=0;--i)r[i]=0;r[s]=u,r.t=this.t+s+1,r.s=this.s,r.clamp()}function w(t,r){r.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t)return void(r.t=0);var e=t%this.DB,n=this.DB-e,o=(1<<e)-1;r[0]=this[i]>>e;for(var s=i+1;s<this.t;++s)r[s-i-1]|=(this[s]&o)<<n,r[s-i]=this[s]>>e;e>0&&(r[this.t-i-1]|=(this.s&o)<<n),r.t=this.t-i,r.clamp()}function x(t,r){for(var i=0,e=0,n=Math.min(t.t,this.t);i<n;)e+=this[i]-t[i],r[i++]=e&this.DM,e>>=this.DB;if(t.t<this.t){for(e-=t.s;i<this.t;)e+=this[i],r[i++]=e&this.DM,e>>=this.DB;e+=this.s}else{for(e+=this.s;i<t.t;)e-=t[i],r[i++]=e&this.DM,e>>=this.DB;e-=t.s}r.s=e<0?-1:0,e<-1?r[i++]=this.DV+e:e>0&&(r[i++]=e),r.t=i,r.clamp()}function D(t,r){var e=this.abs(),n=t.abs(),o=e.t;for(r.t=o+n.t;--o>=0;)r[o]=0;for(o=0;o<n.t;++o)r[o+e.t]=e.am(0,n[o],r,o,0,e.t);r.s=0,r.clamp(),this.s!=t.s&&i.ZERO.subTo(r,r)}function S(t){for(var r=this.abs(),i=t.t=2*r.t;--i>=0;)t[i]=0;for(i=0;i<r.t-1;++i){var e=r.am(i,r[i],t,2*i,0,1);(t[i+r.t]+=r.am(i+1,2*r[i],t,2*i+1,e,r.t-i-1))>=r.DV&&(t[i+r.t]-=r.DV,t[i+r.t+1]=1)}t.t>0&&(t[t.t-1]+=r.am(i,r[i],t,2*i,0,1)),t.s=0,t.clamp()}function I(t,r,n){var o=t.abs();if(!(o.t<=0)){var s=this.abs();if(s.t<o.t)return null!=r&&r.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=e());var u=e(),h=this.s,a=t.s,f=this.DB-d(o[o.t-1]);f>0?(o.lShiftTo(f,u),s.lShiftTo(f,n)):(o.copyTo(u),s.copyTo(n));var l=u.t,c=u[l-1];if(0!=c){var p=c*(1<<this.F1)+(l>1?u[l-2]>>this.F2:0),v=this.FV/p,y=(1<<this.F1)/p,m=1<<this.F2,g=n.t,T=g-l,F=null==r?e():r;for(u.dlShiftTo(T,F),n.compareTo(F)>=0&&(n[n.t++]=1,n.subTo(F,n)),i.ONE.dlShiftTo(l,F),F.subTo(u,u);u.t<l;)u[u.t++]=0;for(;--T>=0;){var b=n[--g]==c?this.DM:Math.floor(n[g]*v+(n[g-1]+m)*y);if((n[g]+=u.am(0,b,n,T,0,l))<b)for(u.dlShiftTo(T,F),n.subTo(F,n);n[g]<--b;)n.subTo(F,n)}null!=r&&(n.drShiftTo(l,r),h!=a&&i.ZERO.subTo(r,r)),n.t=l,n.clamp(),f>0&&n.rShiftTo(f,n),h<0&&i.ZERO.subTo(n,n)}}}function q(t){var r=e();return this.abs().divRemTo(t,null,r),this.s<0&&r.compareTo(i.ZERO)>0&&t.subTo(r,r),r}function E(t){this.m=t}function A(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function O(t){return t}function R(t){t.divRemTo(this.m,null,t)}function P(t,r,i){t.multiplyTo(r,i),this.reduce(i)}function M(t,r){t.squareTo(r),this.reduce(r)}function C(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var r=3&t;return r=r*(2-(15&t)*r)&15,r=r*(2-(255&t)*r)&255,r=r*(2-((65535&t)*r&65535))&65535,r=r*(2-t*r%this.DV)%this.DV,r>0?this.DV-r:-r}function k(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 V(t){var r=e();return t.abs().dlShiftTo(this.m.t,r),r.divRemTo(this.m,null,r),t.s<0&&r.compareTo(i.ZERO)>0&&this.m.subTo(r,r),r}function H(t){var r=e();return t.copyTo(r),this.reduce(r),r}function N(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var r=0;r<this.m.t;++r){var i=32767&t[r],e=i*this.mpl+((i*this.mph+(t[r]>>15)*this.mpl&this.um)<<15)&t.DM;for(i=r+this.m.t,t[i]+=this.m.am(0,e,t,r,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function j(t,r){t.squareTo(r),this.reduce(r)}function L(t,r,i){t.multiplyTo(r,i),this.reduce(i)}function z(){return 0==(this.t>0?1&this[0]:this.s)}function Z(t,r){if(t>4294967295||t<1)return i.ONE;var n=e(),o=e(),s=r.convert(this),u=d(t)-1;for(s.copyTo(n);--u>=0;)if(r.sqrTo(n,o),(t&1<<u)>0)r.mulTo(o,s,n);else{var h=n;n=o,o=h}return r.revert(n)}function K(t,r){var i;return i=t<256||r.isEven()?new E(r):new k(r),this.exp(t,i)}function _(){var t=e();return this.copyTo(t),t}function X(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function U(){return 0==this.t?this.s:this[0]<<24>>24}function Y(){return 0==this.t?this.s:this[0]<<16>>16}function G(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function J(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function Q(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var r=this.chunkSize(t),i=Math.pow(t,r),n=l(i),o=e(),s=e(),u="";for(this.divRemTo(n,o,s);o.signum()>0;)u=(i+s.intValue()).toString(t).substr(1)+u,o.divRemTo(n,o,s);return s.intValue().toString(t)+u}function W(t,r){this.fromInt(0),null==r&&(r=10);for(var e=this.chunkSize(r),n=Math.pow(r,e),o=!1,s=0,u=0,a=0;a<t.length;++a){var f=h(t,a);f<0?"-"==t.charAt(a)&&0==this.signum()&&(o=!0):(u=r*u+f,++s>=e&&(this.dMultiply(n),this.dAddOffset(u,0),s=0,u=0))}s>0&&(this.dMultiply(Math.pow(r,s)),this.dAddOffset(u,0)),o&&i.ZERO.subTo(this,this)}function $(t,r,e){if("number"==typeof r)if(t<2)this.fromInt(1);else for(this.fromNumber(t,e),this.testBit(t-1)||this.bitwiseTo(i.ONE.shiftLeft(t-1),ut,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(r);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(i.ONE.shiftLeft(t-1),this);else{var n=new Array,o=7&t;n.length=1+(t>>3),r.nextBytes(n),o>0?n[0]&=(1<<o)-1:n[0]=0,this.fromString(n,256)}}function tt(){var t=this.t,r=new Array;r[0]=this.s;var i,e=this.DB-t*this.DB%8,n=0;if(t-- >0)for(e<this.DB&&(i=this[t]>>e)!=(this.s&this.DM)>>e&&(r[n++]=i|this.s<<this.DB-e);t>=0;)e<8?(i=(this[t]&(1<<e)-1)<<8-e,i|=this[--t]>>(e+=this.DB-8)):(i=this[t]>>(e-=8)&255,e<=0&&(e+=this.DB,--t)),0!=(128&i)&&(i|=-256),0==n&&(128&this.s)!=(128&i)&&++n,(n>0||i!=this.s)&&(r[n++]=i);return r}function rt(t){return 0==this.compareTo(t)}function it(t){return this.compareTo(t)<0?this:t}function et(t){return this.compareTo(t)>0?this:t}function nt(t,r,i){var e,n,o=Math.min(t.t,this.t);for(e=0;e<o;++e)i[e]=r(this[e],t[e]);if(t.t<this.t){for(n=t.s&this.DM,e=o;e<this.t;++e)i[e]=r(this[e],n);i.t=this.t}else{for(n=this.s&this.DM,e=o;e<t.t;++e)i[e]=r(n,t[e]);i.t=t.t}i.s=r(this.s,t.s),i.clamp()}function ot(t,r){return t&r}function st(t){var r=e();return this.bitwiseTo(t,ot,r),r}function ut(t,r){return t|r}function ht(t){var r=e();return this.bitwiseTo(t,ut,r),r}function at(t,r){return t^r}function ft(t){var r=e();return this.bitwiseTo(t,at,r),r}function lt(t,r){return t&~r}function ct(t){var r=e();return this.bitwiseTo(t,lt,r),r}function pt(){for(var t=e(),r=0;r<this.t;++r)t[r]=this.DM&~this[r];return t.t=this.t,t.s=~this.s,t}function vt(t){var r=e();return t<0?this.rShiftTo(-t,r):this.lShiftTo(t,r),r}function yt(t){var r=e();return t<0?this.lShiftTo(-t,r):this.rShiftTo(t,r),r}function mt(t){if(0==t)return-1;var r=0;return 0==(65535&t)&&(t>>=16,r+=16),0==(255&t)&&(t>>=8,r+=8),0==(15&t)&&(t>>=4,r+=4),0==(3&t)&&(t>>=2,r+=2),0==(1&t)&&++r,r}function gt(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+mt(this[t]);return this.s<0?this.t*this.DB:-1}function dt(t){for(var r=0;0!=t;)t&=t-1,++r;return r}function Tt(){for(var t=0,r=this.s&this.DM,i=0;i<this.t;++i)t+=dt(this[i]^r);return t}function Ft(t){var r=Math.floor(t/this.DB);return r>=this.t?0!=this.s:0!=(this[r]&1<<t%this.DB)}function bt(t,r){var e=i.ONE.shiftLeft(t);return this.bitwiseTo(e,r,e),e}function Bt(t){return this.changeBit(t,ut)}function wt(t){return this.changeBit(t,lt)}function xt(t){return this.changeBit(t,at)}function Dt(t,r){for(var i=0,e=0,n=Math.min(t.t,this.t);i<n;)e+=this[i]+t[i],r[i++]=e&this.DM,e>>=this.DB;if(t.t<this.t){for(e+=t.s;i<this.t;)e+=this[i],r[i++]=e&this.DM,e>>=this.DB;e+=this.s}else{for(e+=this.s;i<t.t;)e+=t[i],r[i++]=e&this.DM,e>>=this.DB;e+=t.s}r.s=e<0?-1:0,e>0?r[i++]=e:e<-1&&(r[i++]=this.DV+e),r.t=i,r.clamp()}function St(t){var r=e();return this.addTo(t,r),r}function It(t){var r=e();return this.subTo(t,r),r}function qt(t){var r=e();return this.multiplyTo(t,r),r}function Et(){var t=e();return this.squareTo(t),t}function At(t){var r=e();return this.divRemTo(t,r,null),r}function Ot(t){var r=e();return this.divRemTo(t,null,r),r}function Rt(t){var r=e(),i=e();return this.divRemTo(t,r,i),new Array(r,i)}function Pt(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function Mt(t,r){if(0!=t){for(;this.t<=r;)this[this.t++]=0;for(this[r]+=t;this[r]>=this.DV;)this[r]-=this.DV,++r>=this.t&&(this[this.t++]=0),++this[r]}}function Ct(){}function kt(t){return t}function Vt(t,r,i){t.multiplyTo(r,i)}function Ht(t,r){t.squareTo(r)}function Nt(t){return this.exp(t,new Ct)}function jt(t,r,i){var e=Math.min(this.t+t.t,r);for(i.s=0,i.t=e;e>0;)i[--e]=0;var n;for(n=i.t-this.t;e<n;++e)i[e+this.t]=this.am(0,t[e],i,e,0,this.t);for(n=Math.min(t.t,r);e<n;++e)this.am(0,t[e],i,e,0,r-e);i.clamp()}function Lt(t,r,i){--r;var e=i.t=this.t+t.t-r;for(i.s=0;--e>=0;)i[e]=0;for(e=Math.max(r-this.t,0);e<t.t;++e)i[this.t+e-r]=this.am(r-e,t[e],i,0,0,this.t+e-r);i.clamp(),i.drShiftTo(1,i)}function zt(t){this.r2=e(),this.q3=e(),i.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function Zt(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 r=e();return t.copyTo(r),this.reduce(r),r}function Kt(t){return t}function _t(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 Xt(t,r){t.squareTo(r),this.reduce(r)}function Ut(t,r,i){t.multiplyTo(r,i),this.reduce(i)}function Yt(t,r){var i,n,o=t.bitLength(),s=l(1);if(o<=0)return s;i=o<18?1:o<48?3:o<144?4:o<768?5:6,n=o<8?new E(r):r.isEven()?new zt(r):new k(r);var u=new Array,h=3,a=i-1,f=(1<<i)-1;if(u[1]=n.convert(this),i>1){var c=e();for(n.sqrTo(u[1],c);h<=f;)u[h]=e(),n.mulTo(c,u[h-2],u[h]),h+=2}var p,v,y=t.t-1,m=!0,g=e();for(o=d(t[y])-1;y>=0;){for(o>=a?p=t[y]>>o-a&f:(p=(t[y]&(1<<o+1)-1)<<a-o,y>0&&(p|=t[y-1]>>this.DB+o-a)),h=i;0==(1&p);)p>>=1,--h;if((o-=h)<0&&(o+=this.DB,--y),m)u[p].copyTo(s),m=!1;else{for(;h>1;)n.sqrTo(s,g),n.sqrTo(g,s),h-=2;h>0?n.sqrTo(s,g):(v=s,s=g,g=v),n.mulTo(g,u[p],s)}for(;y>=0&&0==(t[y]&1<<o);)n.sqrTo(s,g),v=s,s=g,g=v,--o<0&&(o=this.DB-1,--y)}return n.revert(s)}function Gt(t){var r=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(r.compareTo(i)<0){var e=r;r=i,i=e}var n=r.getLowestSetBit(),o=i.getLowestSetBit();if(o<0)return r;for(n<o&&(o=n),o>0&&(r.rShiftTo(o,r),i.rShiftTo(o,i));r.signum()>0;)(n=r.getLowestSetBit())>0&&r.rShiftTo(n,r),(n=i.getLowestSetBit())>0&&i.rShiftTo(n,i),r.compareTo(i)>=0?(r.subTo(i,r),r.rShiftTo(1,r)):(i.subTo(r,i),i.rShiftTo(1,i));return o>0&&i.lShiftTo(o,i),i}function Jt(t){if(t<=0)return 0;var r=this.DV%t,i=this.s<0?t-1:0;if(this.t>0)if(0==r)i=this[0]%t;else for(var e=this.t-1;e>=0;--e)i=(r*i+this[e])%t;return i}function Qt(t){var r=t.isEven();if(this.isEven()&&r||0==t.signum())return i.ZERO;for(var e=t.clone(),n=this.clone(),o=l(1),s=l(0),u=l(0),h=l(1);0!=e.signum();){for(;e.isEven();)e.rShiftTo(1,e),r?(o.isEven()&&s.isEven()||(o.addTo(this,o),s.subTo(t,s)),o.rShiftTo(1,o)):s.isEven()||s.subTo(t,s),s.rShiftTo(1,s);for(;n.isEven();)n.rShiftTo(1,n),r?(u.isEven()&&h.isEven()||(u.addTo(this,u),h.subTo(t,h)),u.rShiftTo(1,u)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);e.compareTo(n)>=0?(e.subTo(n,e),r&&o.subTo(u,o),s.subTo(h,s)):(n.subTo(e,n),r&&u.subTo(o,u),h.subTo(s,h))}return 0!=n.compareTo(i.ONE)?i.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h}function Wt(t){var r,i=this.abs();if(1==i.t&&i[0]<=yr[yr.length-1]){for(r=0;r<yr.length;++r)if(i[0]==yr[r])return!0;return!1}if(i.isEven())return!1;for(r=1;r<yr.length;){for(var e=yr[r],n=r+1;n<yr.length&&e<mr;)e*=yr[n++];for(e=i.modInt(e);r<n;)if(e%yr[r++]==0)return!1}return i.millerRabin(t)}function $t(t){var r=this.subtract(i.ONE),n=r.getLowestSetBit();if(n<=0)return!1;var o=r.shiftRight(n);(t=t+1>>1)>yr.length&&(t=yr.length);for(var s=e(),u=0;u<t;++u){s.fromInt(yr[Math.floor(Math.random()*yr.length)]);var h=s.modPow(o,this);if(0!=h.compareTo(i.ONE)&&0!=h.compareTo(r)){for(var a=1;a++<n&&0!=h.compareTo(r);)if(h=h.modPowInt(2,this),0==h.compareTo(i.ONE))return!1;if(0!=h.compareTo(r))return!1}}return!0}function tr(t){dr[Tr++]^=255&t,dr[Tr++]^=t>>8&255,dr[Tr++]^=t>>16&255,dr[Tr++]^=t>>24&255,Tr>=wr&&(Tr-=wr)}function rr(){tr((new Date).getTime())}function ir(){if(null==gr){for(rr(),gr=hr(),gr.init(dr),Tr=0;Tr<dr.length;++Tr)dr[Tr]=0;Tr=0}return gr.next()}function er(t){var r;for(r=0;r<t.length;++r)t[r]=ir()}function nr(){}function or(){this.i=0,this.j=0,this.S=new Array}function sr(t){var r,i,e;for(r=0;r<256;++r)this.S[r]=r;for(i=0,r=0;r<256;++r)i=i+this.S[r]+t[r%t.length]&255,e=this.S[r],this.S[r]=this.S[i],this.S[i]=e;this.i=0,this.j=0}function ur(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}function hr(){return new or}var ar,fr="undefined"!=typeof navigator;fr&&"Microsoft Internet Explorer"==navigator.appName?(i.prototype.am=o,ar=30):fr&&"Netscape"!=navigator.appName?(i.prototype.am=n,ar=26):(i.prototype.am=s,ar=28),i.prototype.DB=ar,i.prototype.DM=(1<<ar)-1,i.prototype.DV=1<<ar;i.prototype.FV=Math.pow(2,52),i.prototype.F1=52-ar,i.prototype.F2=2*ar-52;var lr,cr,pr="0123456789abcdefghijklmnopqrstuvwxyz",vr=new Array;for(lr="0".charCodeAt(0),cr=0;cr<=9;++cr)vr[lr++]=cr;for(lr="a".charCodeAt(0),cr=10;cr<36;++cr)vr[lr++]=cr;for(lr="A".charCodeAt(0),cr=10;cr<36;++cr)vr[lr++]=cr;E.prototype.convert=A,E.prototype.revert=O,E.prototype.reduce=R,E.prototype.mulTo=P,E.prototype.sqrTo=M,k.prototype.convert=V,k.prototype.revert=H,k.prototype.reduce=N,k.prototype.mulTo=L,k.prototype.sqrTo=j,i.prototype.copyTo=a,i.prototype.fromInt=f,i.prototype.fromString=c,i.prototype.clamp=p,i.prototype.dlShiftTo=F,i.prototype.drShiftTo=b,i.prototype.lShiftTo=B,i.prototype.rShiftTo=w,i.prototype.subTo=x,i.prototype.multiplyTo=D,i.prototype.squareTo=S,i.prototype.divRemTo=I,i.prototype.invDigit=C,i.prototype.isEven=z,i.prototype.exp=Z,i.prototype.toString=v,i.prototype.negate=y,i.prototype.abs=m,i.prototype.compareTo=g,i.prototype.bitLength=T,i.prototype.mod=q,i.prototype.modPowInt=K,i.ZERO=l(0),i.ONE=l(1),Ct.prototype.convert=kt,Ct.prototype.revert=kt,Ct.prototype.mulTo=Vt,Ct.prototype.sqrTo=Ht,zt.prototype.convert=Zt,zt.prototype.revert=Kt,zt.prototype.reduce=_t,zt.prototype.mulTo=Ut,zt.prototype.sqrTo=Xt;var yr=[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],mr=(1<<26)/yr[yr.length-1];i.prototype.chunkSize=G,i.prototype.toRadix=Q,i.prototype.fromRadix=W,i.prototype.fromNumber=$,i.prototype.bitwiseTo=nt,i.prototype.changeBit=bt,i.prototype.addTo=Dt,i.prototype.dMultiply=Pt,i.prototype.dAddOffset=Mt,i.prototype.multiplyLowerTo=jt,i.prototype.multiplyUpperTo=Lt,i.prototype.modInt=Jt,i.prototype.millerRabin=$t,i.prototype.clone=_,i.prototype.intValue=X,i.prototype.byteValue=U,i.prototype.shortValue=Y,i.prototype.signum=J,i.prototype.toByteArray=tt,i.prototype.equals=rt,i.prototype.min=it,i.prototype.max=et,i.prototype.and=st,i.prototype.or=ht,i.prototype.xor=ft,i.prototype.andNot=ct,i.prototype.not=pt,i.prototype.shiftLeft=vt,i.prototype.shiftRight=yt,i.prototype.getLowestSetBit=gt,i.prototype.bitCount=Tt,i.prototype.testBit=Ft,i.prototype.setBit=Bt,i.prototype.clearBit=wt,i.prototype.flipBit=xt,i.prototype.add=St,i.prototype.subtract=It,i.prototype.multiply=qt,i.prototype.divide=At,i.prototype.remainder=Ot,i.prototype.divideAndRemainder=Rt,i.prototype.modPow=Yt,i.prototype.modInverse=Qt,i.prototype.pow=Nt,i.prototype.gcd=Gt,i.prototype.isProbablePrime=Wt,i.prototype.square=Et,i.prototype.Barrett=zt;var gr,dr,Tr;if(null==dr){dr=new Array,Tr=0;var Fr;if("undefined"!=typeof window&&window.crypto)if(window.crypto.getRandomValues){var br=new Uint8Array(32);for(window.crypto.getRandomValues(br),Fr=0;Fr<32;++Fr)dr[Tr++]=br[Fr]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var Br=window.crypto.random(32);for(Fr=0;Fr<Br.length;++Fr)dr[Tr++]=255&Br.charCodeAt(Fr)}for(;Tr<wr;)Fr=Math.floor(65536*Math.random()),dr[Tr++]=Fr>>>8,dr[Tr++]=255&Fr;Tr=0,rr()}nr.prototype.nextBytes=er,or.prototype.init=sr,or.prototype.next=ur;var wr=256;r=t.exports={default:i,BigInteger:i,SecureRandom:nr}}).call(this)},function(t,r,i){"use strict";function e(t,r){for(var i=[],e=~~(r/8),n=r%8,o=0,s=t.length;o<s;o++)i[o]=(t[(o+e)%s]<<n&255)+(t[(o+e+1)%s]>>>8-n&255);return i}function n(t,r){for(var i=[],e=t.length-1;e>=0;e--)i[e]=255&(t[e]^r[e]);return i}function o(t,r){for(var i=[],e=t.length-1;e>=0;e--)i[e]=t[e]&r[e]&255;return i}function s(t,r){for(var i=[],e=t.length-1;e>=0;e--)i[e]=255&(t[e]|r[e]);return i}function u(t,r){for(var i=[],e=0,n=t.length-1;n>=0;n--){var o=t[n]+r[n]+e;o>255?(e=1,i[n]=255&o):(e=0,i[n]=255&o)}return i}function h(t){for(var r=[],i=t.length-1;i>=0;i--)r[i]=255&~t[i];return r}function a(t){return n(n(t,e(t,9)),e(t,17))}function f(t){return n(n(t,e(t,15)),e(t,23))}function l(t,r,i,e){return e>=0&&e<=15?n(n(t,r),i):s(s(o(t,r),o(t,i)),o(r,i))}function c(t,r,i,e){return e>=0&&e<=15?n(n(t,r),i):s(o(t,r),o(h(t),i))}function p(t,r){for(var i=[],o=[],s=0;s<16;s++){var h=4*s;i.push(r.slice(h,h+4))}for(var p=16;p<68;p++)i.push(n(n(f(n(n(i[p-16],i[p-9]),e(i[p-3],15))),e(i[p-13],7)),i[p-6]));for(var v=0;v<64;v++)o.push(n(i[v],i[v+4]));for(var y=[121,204,69,25],m=[122,135,157,138],g=t.slice(0,4),d=t.slice(4,8),T=t.slice(8,12),F=t.slice(12,16),b=t.slice(16,20),B=t.slice(20,24),w=t.slice(24,28),x=t.slice(28,32),D=void 0,S=void 0,I=void 0,q=void 0,E=0;E<64;E++){var A=E>=0&&E<=15?y:m;D=e(u(u(e(g,12),b),e(A,E)),7),S=n(D,e(g,12)),I=u(u(u(l(g,d,T,E),F),S),o[E]),q=u(u(u(c(b,B,w,E),x),D),i[E]),F=T,T=e(d,9),d=g,g=I,x=w,w=e(B,19),B=b,b=a(q)}return n([].concat(g,d,T,F,b,B,w,x),t)}function v(t){var r=8*t.length,i=r%512;i=i>=448?512-i%448-1:448-i-1;for(var e=new Array((i-7)/8),n=0,o=e.length;n<o;n++)e[n]=0;var s=[];r=r.toString(2);for(var u=7;u>=0;u--)if(r.length>8){var h=r.length-8;s[u]=parseInt(r.substr(h),2),r=r.substr(0,h)}else r.length>0?(s[u]=parseInt(r,2),r=""):s[u]=0;for(var a=[].concat(t,[128],e,s),f=a.length/64,l=[115,128,22,111,73,20,178,185,23,36,66,215,218,138,6,0,169,111,48,188,22,49,56,170,227,141,238,77,176,251,14,78],c=0;c<f;c++){var v=64*c;l=p(l,a.slice(v,v+64))}return l}function y(t,r){for(r.length>m&&(r=v(r));r.length<m;)r.push(0);var i=n(r,g),e=i.concat(t);return e=v(e),e=n(r,d).concat(e),e=v(e)}for(var m=64,g=new Array(m),d=new Array(m),T=0;T<m;T++)g[T]=54,d[T]=92;t.exports={sm3:v,hmac:y}},function(t,r,i){"use strict";function e(t){if(Array.isArray(t)){for(var r=0,i=Array(t.length);r<t.length;r++)i[r]=t[r];return i}return Array.from(t)}function n(t,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;t="string"==typeof t?m.hexToArray(m.utf8ToHex(t)):Array.prototype.slice.call(t),r=m.getGlobalCurve().decodePointHex(r);var n=m.generateKeyPairHex(),o=new c(n.privateKey,16),s=n.publicKey;s.length>128&&(s=s.substr(s.length-128));var u=r.multiply(o),h=m.hexToArray(m.leftPad(u.getX().toBigInteger().toRadix(16),64)),a=m.hexToArray(m.leftPad(u.getY().toBigInteger().toRadix(16),64)),f=m.arrayToHex(g([].concat(h,t,a))),l=1,p=0,v=[],y=[].concat(h,a),d=function(){v=g([].concat(e(y),[l>>24&255,l>>16&255,l>>8&255,255&l])),l++,p=0};d();for(var T=0,F=t.length;T<F;T++)p===v.length&&d(),t[T]^=255&v[p++];var b=m.arrayToHex(t);return i===B?s+b+f:s+f+b}function o(t,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=n.output,s=void 0===o?"string":o;r=new c(r,16);var u=t.substr(128,64),h=t.substr(192);i===B&&(u=t.substr(t.length-64),h=t.substr(128,t.length-128-64));var a=m.hexToArray(h),f=m.getGlobalCurve().decodePointHex("04"+t.substr(0,128)),l=f.multiply(r),p=m.hexToArray(m.leftPad(l.getX().toBigInteger().toRadix(16),64)),v=m.hexToArray(m.leftPad(l.getY().toBigInteger().toRadix(16),64)),y=1,d=0,T=[],F=[].concat(p,v),b=function(){T=g([].concat(e(F),[y>>24&255,y>>16&255,y>>8&255,255&y])),y++,d=0};b();for(var w=0,x=a.length;w<x;w++)d===T.length&&b(),a[w]^=255&T[d++];return m.arrayToHex(g([].concat(p,a,v)))===u.toLowerCase()?"array"===s?a:m.arrayToUtf8(a):"array"===s?[]:""}function s(t,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},e=i.pointPool,n=i.der,o=i.hash,s=i.publicKey,u=i.userId,l="string"==typeof t?m.utf8ToHex(t):m.arrayToHex(t);o&&(s=s||a(r),l=h(l,s,u));var p=new c(r,16),y=new c(l,16),g=null,d=null,T=null;do{do{var F=void 0;F=e&&e.length?e.pop():f(),g=F.k,d=y.add(F.x1).mod(b)}while(d.equals(c.ZERO)||d.add(g).equals(b));T=p.add(c.ONE).modInverse(b).multiply(g.subtract(d.multiply(p))).mod(b)}while(T.equals(c.ZERO));return n?v(d,T):m.leftPad(d.toString(16),64)+m.leftPad(T.toString(16),64)}function u(t,r,i){var e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=e.der,o=e.hash,s=e.userId,u="string"==typeof t?m.utf8ToHex(t):m.arrayToHex(t);o&&(u=h(u,i,s));var a=void 0,f=void 0;if(n){var l=y(r);a=l.r,f=l.s}else a=new c(r.substring(0,64),16),f=new c(r.substring(64),16);var p=F.decodePointHex(i),v=new c(u,16),g=a.add(f).mod(b);if(g.equals(c.ZERO))return!1;var d=T.multiply(f).add(p.multiply(g)),B=v.add(d.getX().toBigInteger()).mod(b);return a.equals(B)}function h(t,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"1234567812345678";i=m.utf8ToHex(i);var e=m.leftPad(T.curve.a.toBigInteger().toRadix(16),64),n=m.leftPad(T.curve.b.toBigInteger().toRadix(16),64),o=m.leftPad(T.getX().toBigInteger().toRadix(16),64),s=m.leftPad(T.getY().toBigInteger().toRadix(16),64);r.length>128&&(r=r.substr(2,128));var u=r.substr(0,64),h=r.substr(64,64),a=m.hexToArray(i+e+n+o+s+u+h),f=4*i.length;a.unshift(255&f),a.unshift(f>>8&255);var l=g(a);return m.arrayToHex(g(l.concat(m.hexToArray(t))))}function a(t){var r=T.multiply(new c(t,16));return"04"+m.leftPad(r.getX().toBigInteger().toString(16),64)+m.leftPad(r.getY().toBigInteger().toString(16),64)}function f(){var t=m.generateKeyPairHex(),r=F.decodePointHex(t.publicKey);return t.k=new c(t.privateKey,16),t.x1=r.getX().toBigInteger(),t}var l=i(0),c=l.BigInteger,p=i(3),v=p.encodeDer,y=p.decodeDer,m=i(4),g=i(1).sm3,d=m.generateEcparam(),T=d.G,F=d.curve,b=d.n,B=0;t.exports={generateKeyPairHex:m.generateKeyPairHex,doEncrypt:n,doDecrypt:o,doSignature:s,doVerifySignature:u,getPoint:f,verifyPublicKey:m.verifyPublicKey}},function(t,r,i){"use strict";function e(t,r){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?t:r}function n(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}function o(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function s(t){var r=t.toString(16);if("-"!==r[0])r.length%2==1?r="0"+r:r.match(/^[0-7]/)||(r="00"+r);else{r=r.substr(1);var i=r.length;i%2==1?i+=1:r.match(/^[0-7]/)||(i+=2);for(var e="",n=0;n<i;n++)e+="f";e=new c(e,16),r=e.xor(t).add(c.ONE),r=r.toString(16).replace(/^-/,"")}return r}function u(t,r){return+t[r+2]<8?1:128&+t.substr(r+2,2)}function h(t,r){var i=u(t,r),e=t.substr(r+2,2*i);return e?(+e[0]<8?new c(e,16):new c(e.substr(2),16)).intValue():-1}function a(t,r){return r+2*(u(t,r)+1)}var f=function(){function t(t,r){for(var i=0;i<r.length;i++){var e=r[i];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}return function(r,i,e){return i&&t(r.prototype,i),e&&t(r,e),r}}(),l=i(0),c=l.BigInteger,p=function(){function t(){o(this,t),this.tlv=null,this.t="00",this.l="00",this.v=""}return f(t,[{key:"getEncodedHex",value:function(){return this.tlv||(this.v=this.getValue(),this.l=this.getLength(),this.tlv=this.t+this.l+this.v),this.tlv}},{key:"getLength",value:function(){var t=this.v.length/2,r=t.toString(16);return r.length%2==1&&(r="0"+r),t<128?r:(128+r.length/2).toString(16)+r}},{key:"getValue",value:function(){return""}}]),t}(),v=function(t){function r(t){o(this,r);var i=e(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return i.t="02",t&&(i.v=s(t)),i}return n(r,t),f(r,[{key:"getValue",value:function(){return this.v}}]),r}(p),y=function(t){function r(t){o(this,r);var i=e(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return i.t="30",i.asn1Array=t,i}return n(r,t),f(r,[{key:"getValue",value:function(){return this.v=this.asn1Array.map(function(t){return t.getEncodedHex()}).join(""),this.v}}]),r}(p);t.exports={encodeDer:function(t,r){var i=new v(t),e=new v(r);return new y([i,e]).getEncodedHex()},decodeDer:function(t){var r=a(t,0),i=a(t,r),e=h(t,r),n=t.substr(i,2*e),o=i+n.length,s=a(t,o),u=h(t,o),f=t.substr(s,2*u);return{r:new c(n,16),s:new c(f,16)}}}},function(t,r,i){"use strict";function e(){return T}function n(){var t=new p("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",16),r=new p("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",16),i=new p("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",16),e=new m(t,r,i);return{curve:e,G:e.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0"),n:new p("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",16)}}function o(t,r,i){var e=t?new p(t,r,i):new p(b.bitLength(),g),n=e.mod(b.subtract(p.ONE)).add(p.ONE),o=u(n.toString(16),64),s=F.multiply(n);return{privateKey:o,publicKey:"04"+u(s.getX().toBigInteger().toString(16),64)+u(s.getY().toBigInteger().toString(16),64)}}function s(t){t=unescape(encodeURIComponent(t));for(var r=t.length,i=[],e=0;e<r;e++)i[e>>>2]|=(255&t.charCodeAt(e))<<24-e%4*8;for(var n=[],o=0;o<r;o++){var s=i[o>>>2]>>>24-o%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")}function u(t,r){return t.length>=r?t:new Array(r-t.length+1).join("0")+t}function h(t){return t.map(function(t){return t=t.toString(16),1===t.length?"0"+t:t}).join("")}function a(t){for(var r=[],i=0,e=0;e<2*t.length;e+=2)r[e>>>3]|=parseInt(t[i],10)<<24-e%8*4,i++;try{for(var n=[],o=0;o<t.length;o++){var s=r[o>>>2]>>>24-o%4*8&255;n.push(String.fromCharCode(s))}return decodeURIComponent(escape(n.join("")))}catch(t){throw new Error("Malformed UTF-8 data")}}function f(t){var r=[],i=t.length;i%2!=0&&(t=u(t,i+1)),i=t.length;for(var e=0;e<i;e+=2)r.push(parseInt(t.substr(e,2),16));return r}function l(t){var r=T.decodePointHex(t);if(!r)return!1;var i=r.getX();return r.getY().square().equals(i.multiply(i.square()).add(i.multiply(T.a)).add(T.b))}var c=i(0),p=c.BigInteger,v=c.SecureRandom,y=i(5),m=y.ECCurveFp,g=new v,d=n(),T=d.curve,F=d.G,b=d.n;t.exports={getGlobalCurve:e,generateEcparam:n,generateKeyPairHex:o,utf8ToHex:s,leftPad:u,arrayToHex:h,arrayToUtf8:a,hexToArray:f,verifyPublicKey:l}},function(t,r,i){"use strict";function e(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}var n=function(){function t(t,r){for(var i=0;i<r.length;i++){var e=r[i];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}return function(r,i,e){return i&&t(r.prototype,i),e&&t(r,e),r}}(),o=i(0),s=o.BigInteger,u=new s("3"),h=function(){function t(r,i){e(this,t),this.x=i,this.q=r}return n(t,[{key:"equals",value:function(t){return t===this||this.q.equals(t.q)&&this.x.equals(t.x)}},{key:"toBigInteger",value:function(){return this.x}},{key:"negate",value:function(){return new t(this.q,this.x.negate().mod(this.q))}},{key:"add",value:function(r){return new t(this.q,this.x.add(r.toBigInteger()).mod(this.q))}},{key:"subtract",value:function(r){return new t(this.q,this.x.subtract(r.toBigInteger()).mod(this.q))}},{key:"multiply",value:function(r){return new t(this.q,this.x.multiply(r.toBigInteger()).mod(this.q))}},{key:"divide",value:function(r){return new t(this.q,this.x.multiply(r.toBigInteger().modInverse(this.q)).mod(this.q))}},{key:"square",value:function(){return new t(this.q,this.x.square().mod(this.q))}}]),t}(),a=function(){function t(r,i,n,o){e(this,t),this.curve=r,this.x=i,this.y=n,this.z=null==o?s.ONE:o,this.zinv=null}return n(t,[{key:"getX",value:function(){return null===this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}},{key:"getY",value:function(){return null===this.zinv&&(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}},{key:"equals",value:function(t){return t===this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():!!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(s.ZERO)&&t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(s.ZERO))}},{key:"isInfinity",value:function(){return null===this.x&&null===this.y||this.z.equals(s.ZERO)&&!this.y.toBigInteger().equals(s.ZERO)}},{key:"negate",value:function(){return new t(this.curve,this.x,this.y.negate(),this.z)}},{key:"add",value:function(r){if(this.isInfinity())return r;if(r.isInfinity())return this;var i=this.x.toBigInteger(),e=this.y.toBigInteger(),n=this.z,o=r.x.toBigInteger(),u=r.y.toBigInteger(),h=r.z,a=this.curve.q,f=i.multiply(h).mod(a),l=o.multiply(n).mod(a),c=f.subtract(l),p=e.multiply(h).mod(a),v=u.multiply(n).mod(a),y=p.subtract(v);if(s.ZERO.equals(c))return s.ZERO.equals(y)?this.twice():this.curve.infinity;var m=f.add(l),g=n.multiply(h).mod(a),d=c.square().mod(a),T=c.multiply(d).mod(a),F=g.multiply(y.square()).subtract(m.multiply(d)).mod(a),b=c.multiply(F).mod(a),B=y.multiply(d.multiply(f).subtract(F)).subtract(p.multiply(T)).mod(a),w=T.multiply(g).mod(a);return new t(this.curve,this.curve.fromBigInteger(b),this.curve.fromBigInteger(B),w)}},{key:"twice",value:function(){if(this.isInfinity())return this;if(!this.y.toBigInteger().signum())return this.curve.infinity;var r=this.x.toBigInteger(),i=this.y.toBigInteger(),e=this.z,n=this.curve.q,o=this.curve.a.toBigInteger(),s=r.square().multiply(u).add(o.multiply(e.square())).mod(n),h=i.shiftLeft(1).multiply(e).mod(n),a=i.square().mod(n),f=a.multiply(r).multiply(e).mod(n),l=h.square().mod(n),c=s.square().subtract(f.shiftLeft(3)).mod(n),p=h.multiply(c).mod(n),v=s.multiply(f.shiftLeft(2).subtract(c)).subtract(l.shiftLeft(1).multiply(a)).mod(n),y=h.multiply(l).mod(n);return new t(this.curve,this.curve.fromBigInteger(p),this.curve.fromBigInteger(v),y)}},{key:"multiply",value:function(t){if(this.isInfinity())return this;if(!t.signum())return this.curve.infinity;for(var r=t.multiply(u),i=this.negate(),e=this,n=r.bitLength()-2;n>0;n--){e=e.twice();var o=r.testBit(n);o!==t.testBit(n)&&(e=e.add(o?this:i))}return e}}]),t}(),f=function(){function t(r,i,n){e(this,t),this.q=r,this.a=this.fromBigInteger(i),this.b=this.fromBigInteger(n),this.infinity=new a(this,null,null)}return n(t,[{key:"equals",value:function(t){return t===this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}},{key:"fromBigInteger",value:function(t){return new h(this.q,t)}},{key:"decodePointHex",value:function(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var r=(t.length-2)/2,i=t.substr(2,r),e=t.substr(r+2,r);return new a(this,this.fromBigInteger(new s(i,16)),this.fromBigInteger(new s(e,16)));default:return null}}}]),t}();t.exports={ECPointFp:a,ECCurveFp:f}}])}); |
@@ -1,1 +0,1 @@ | ||
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.sm3=t():r.sm3=t()}("undefined"!=typeof self?self:this,function(){return function(r){function t(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=r,t.c=n,t.d=function(r,n,e){t.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:e})},t.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,"a",n),n},t.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},t.p="",t(t.s=6)}({1:function(r,t,n){"use strict";function e(r,t){for(var n=[],e=~~(t/8),o=t%8,u=0,i=r.length;u<i;u++)n[u]=(r[(u+e)%i]<<o&255)+(r[(u+e+1)%i]>>>8-o&255);return n}function o(r,t){for(var n=[],e=r.length-1;e>=0;e--)n[e]=255&(r[e]^t[e]);return n}function u(r,t){for(var n=[],e=r.length-1;e>=0;e--)n[e]=r[e]&t[e]&255;return n}function i(r,t){for(var n=[],e=r.length-1;e>=0;e--)n[e]=255&(r[e]|t[e]);return n}function f(r,t){for(var n=[],e=0,o=r.length-1;o>=0;o--){var u=r[o]+t[o]+e;u>255?(e=1,n[o]=255&u):(e=0,n[o]=255&u)}return n}function s(r){for(var t=[],n=r.length-1;n>=0;n--)t[n]=255&~r[n];return t}function c(r){return o(o(r,e(r,9)),e(r,17))}function l(r){return o(o(r,e(r,15)),e(r,23))}function p(r,t,n,e){return e>=0&&e<=15?o(o(r,t),n):i(i(u(r,t),u(r,n)),u(t,n))}function a(r,t,n,e){return e>=0&&e<=15?o(o(r,t),n):i(u(r,t),u(s(r),n))}function h(r,t){for(var n=[],u=[],i=0;i<16;i++){var s=4*i;n.push(t.slice(s,s+4))}for(var h=16;h<68;h++)n.push(o(o(l(o(o(n[h-16],n[h-9]),e(n[h-3],15))),e(n[h-13],7)),n[h-6]));for(var v=0;v<64;v++)u.push(o(n[v],n[v+4]));for(var d=[121,204,69,25],g=[122,135,157,138],y=r.slice(0,4),x=r.slice(4,8),b=r.slice(8,12),m=r.slice(12,16),j=r.slice(16,20),w=r.slice(20,24),A=r.slice(24,28),O=r.slice(28,32),P=void 0,I=void 0,S=void 0,_=void 0,E=0;E<64;E++){var M=E>=0&&E<=15?d:g;P=e(f(f(e(y,12),j),e(M,E)),7),I=o(P,e(y,12)),S=f(f(f(p(y,x,b,E),m),I),u[E]),_=f(f(f(a(j,w,A,E),O),P),n[E]),m=b,b=e(x,9),x=y,y=S,O=A,A=e(w,19),w=j,j=c(_)}return o([].concat(y,x,b,m,j,w,A,O),r)}r.exports=function(r){var t=8*r.length,n=t%512;n=n>=448?512-n%448-1:448-n-1;for(var e=new Array((n-7)/8),o=0,u=e.length;o<u;o++)e[o]=0;var i=[];t=t.toString(2);for(var f=7;f>=0;f--)if(t.length>8){var s=t.length-8;i[f]=parseInt(t.substr(s),2),t=t.substr(0,s)}else t.length>0?(i[f]=parseInt(t,2),t=""):i[f]=0;for(var c=[].concat(r,[128],e,i),l=c.length/64,p=[115,128,22,111,73,20,178,185,23,36,66,215,218,138,6,0,169,111,48,188,22,49,56,170,227,141,238,77,176,251,14,78],a=0;a<l;a++){var v=64*a;p=h(p,c.slice(v,v+64))}return p}},6:function(r,t,n){"use strict";function e(r){return r.map(function(r){return r=r.toString(16),1===r.length?"0"+r:r}).join("")}function o(r){for(var t=[],n=0,e=r.length;n<e;n++){var o=r.codePointAt(n);if(o<=127)t.push(o);else if(o<=2047)t.push(192|o>>>6),t.push(128|63&o);else if(o<=55295||o>=57344&&o<=65535)t.push(224|o>>>12),t.push(128|o>>>6&63),t.push(128|63&o);else{if(!(o>=65536&&o<=1114111))throw t.push(o),new Error("input is not supported");n++,t.push(240|o>>>18&28),t.push(128|o>>>12&63),t.push(128|o>>>6&63),t.push(128|63&o)}}return t}var u=n(1);r.exports=function(r){return r="string"==typeof r?o(r):Array.prototype.slice.call(r),e(u(r))}}})}); | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.sm3=n():r.sm3=n()}("undefined"!=typeof self?self:this,function(){return function(r){function n(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var t={};return n.m=r,n.c=t,n.d=function(r,t,e){n.o(r,t)||Object.defineProperty(r,t,{configurable:!1,enumerable:!0,get:e})},n.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(t,"a",t),t},n.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},n.p="",n(n.s=6)}({1:function(r,n,t){"use strict";function e(r,n){for(var t=[],e=~~(n/8),o=n%8,u=0,i=r.length;u<i;u++)t[u]=(r[(u+e)%i]<<o&255)+(r[(u+e+1)%i]>>>8-o&255);return t}function o(r,n){for(var t=[],e=r.length-1;e>=0;e--)t[e]=255&(r[e]^n[e]);return t}function u(r,n){for(var t=[],e=r.length-1;e>=0;e--)t[e]=r[e]&n[e]&255;return t}function i(r,n){for(var t=[],e=r.length-1;e>=0;e--)t[e]=255&(r[e]|n[e]);return t}function f(r,n){for(var t=[],e=0,o=r.length-1;o>=0;o--){var u=r[o]+n[o]+e;u>255?(e=1,t[o]=255&u):(e=0,t[o]=255&u)}return t}function s(r){for(var n=[],t=r.length-1;t>=0;t--)n[t]=255&~r[t];return n}function c(r){return o(o(r,e(r,9)),e(r,17))}function a(r){return o(o(r,e(r,15)),e(r,23))}function l(r,n,t,e){return e>=0&&e<=15?o(o(r,n),t):i(i(u(r,n),u(r,t)),u(n,t))}function p(r,n,t,e){return e>=0&&e<=15?o(o(r,n),t):i(u(r,n),u(s(r),t))}function h(r,n){for(var t=[],u=[],i=0;i<16;i++){var s=4*i;t.push(n.slice(s,s+4))}for(var h=16;h<68;h++)t.push(o(o(a(o(o(t[h-16],t[h-9]),e(t[h-3],15))),e(t[h-13],7)),t[h-6]));for(var v=0;v<64;v++)u.push(o(t[v],t[v+4]));for(var g=[121,204,69,25],d=[122,135,157,138],y=r.slice(0,4),m=r.slice(4,8),w=r.slice(8,12),x=r.slice(12,16),b=r.slice(16,20),j=r.slice(20,24),A=r.slice(24,28),E=r.slice(28,32),I=void 0,O=void 0,P=void 0,k=void 0,S=0;S<64;S++){var _=S>=0&&S<=15?g:d;I=e(f(f(e(y,12),b),e(_,S)),7),O=o(I,e(y,12)),P=f(f(f(l(y,m,w,S),x),O),u[S]),k=f(f(f(p(b,j,A,S),E),I),t[S]),x=w,w=e(m,9),m=y,y=P,E=A,A=e(j,19),j=b,b=c(k)}return o([].concat(y,m,w,x,b,j,A,E),r)}function v(r){var n=8*r.length,t=n%512;t=t>=448?512-t%448-1:448-t-1;for(var e=new Array((t-7)/8),o=0,u=e.length;o<u;o++)e[o]=0;var i=[];n=n.toString(2);for(var f=7;f>=0;f--)if(n.length>8){var s=n.length-8;i[f]=parseInt(n.substr(s),2),n=n.substr(0,s)}else n.length>0?(i[f]=parseInt(n,2),n=""):i[f]=0;for(var c=[].concat(r,[128],e,i),a=c.length/64,l=[115,128,22,111,73,20,178,185,23,36,66,215,218,138,6,0,169,111,48,188,22,49,56,170,227,141,238,77,176,251,14,78],p=0;p<a;p++){var v=64*p;l=h(l,c.slice(v,v+64))}return l}function g(r,n){for(n.length>d&&(n=v(n));n.length<d;)n.push(0);var t=o(n,y),e=t.concat(r);return e=v(e),e=o(n,m).concat(e),e=v(e)}for(var d=64,y=new Array(d),m=new Array(d),w=0;w<d;w++)y[w]=54,m[w]=92;r.exports={sm3:v,hmac:g}},6:function(r,n,t){"use strict";function e(r,n){return r.length>=n?r:new Array(n-r.length+1).join("0")+r}function o(r){return r.map(function(r){return r=r.toString(16),1===r.length?"0"+r:r}).join("")}function u(r){var n=[],t=r.length;t%2!=0&&(r=e(r,t+1)),t=r.length;for(var o=0;o<t;o+=2)n.push(parseInt(r.substr(o,2),16));return n}function i(r){for(var n=[],t=0,e=r.length;t<e;t++){var o=r.codePointAt(t);if(o<=127)n.push(o);else if(o<=2047)n.push(192|o>>>6),n.push(128|63&o);else if(o<=55295||o>=57344&&o<=65535)n.push(224|o>>>12),n.push(128|o>>>6&63),n.push(128|63&o);else{if(!(o>=65536&&o<=1114111))throw n.push(o),new Error("input is not supported");t++,n.push(240|o>>>18&28),n.push(128|o>>>12&63),n.push(128|o>>>6&63),n.push(128|63&o)}}return n}var f=t(1),s=f.sm3,c=f.hmac;r.exports=function(r,n){if(r="string"==typeof r?i(r):Array.prototype.slice.call(r),n){if("hmac"!==(n.mode||"hmac"))throw new Error("invalid mode");var t=n.key;if(!t)throw new Error("invalid key");return t="string"==typeof t?u(t):Array.prototype.slice.call(t),o(c(r,t))}return o(s(r))}}})}); |
@@ -1,1 +0,1 @@ | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.sm4=n():r.sm4=n()}("undefined"!=typeof self?self:this,function(){return function(r){function n(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var t={};return n.m=r,n.c=t,n.d=function(r,t,e){n.o(r,t)||Object.defineProperty(r,t,{configurable:!1,enumerable:!0,get:e})},n.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(t,"a",t),t},n.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},n.p="",n(n.s=7)}({7:function(r,n,t){"use strict";function e(r){if(Array.isArray(r)){for(var n=0,t=Array(r.length);n<r.length;n++)t[n]=r[n];return t}return Array.from(r)}function o(r){for(var n=[],t=0,e=r.length;t<e;t+=2)n.push(parseInt(r.substr(t,2),16));return n}function i(r){return r.map(function(r){return r=r.toString(16),1===r.length?"0"+r:r}).join("")}function u(r){for(var n=[],t=0,e=r.length;t<e;t++){var o=r.codePointAt(t);if(o<=127)n.push(o);else if(o<=2047)n.push(192|o>>>6),n.push(128|63&o);else if(o<=55295||o>=57344&&o<=65535)n.push(224|o>>>12),n.push(128|o>>>6&63),n.push(128|63&o);else{if(!(o>=65536&&o<=1114111))throw n.push(o),new Error("input is not supported");t++,n.push(240|o>>>18&28),n.push(128|o>>>12&63),n.push(128|o>>>6&63),n.push(128|63&o)}}return n}function f(r){for(var n=[],t=0,e=r.length;t<e;t++)r[t]>=240&&r[t]<=247?(n.push(String.fromCodePoint(((7&r[t])<<18)+((63&r[t+1])<<12)+((63&r[t+2])<<6)+(63&r[t+3]))),t+=3):r[t]>=224&&r[t]<=239?(n.push(String.fromCodePoint(((15&r[t])<<12)+((63&r[t+1])<<6)+(63&r[t+2]))),t+=2):r[t]>=192&&r[t]<=223?(n.push(String.fromCodePoint(((31&r[t])<<6)+(63&r[t+1]))),t++):n.push(String.fromCodePoint(r[t]));return n.join("")}function s(r,n){return r<<n|r>>>32-n}function c(r){return(255&m[r>>>24&255])<<24|(255&m[r>>>16&255])<<16|(255&m[r>>>8&255])<<8|255&m[255&r]}function p(r){return r^s(r,2)^s(r,10)^s(r,18)^s(r,24)}function a(r){return r^s(r,13)^s(r,23)}function h(r,n,t){for(var e=new Array(4),o=new Array(4),i=0;i<4;i++)o[0]=255&r[4*i],o[1]=255&r[4*i+1],o[2]=255&r[4*i+2],o[3]=255&r[4*i+3],e[i]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];for(var u,f=0;f<32;f+=4)u=e[1]^e[2]^e[3]^t[f+0],e[0]^=p(c(u)),u=e[2]^e[3]^e[0]^t[f+1],e[1]^=p(c(u)),u=e[3]^e[0]^e[1]^t[f+2],e[2]^=p(c(u)),u=e[0]^e[1]^e[2]^t[f+3],e[3]^=p(c(u));for(var s=0;s<16;s+=4)n[s]=e[3-s/4]>>>24&255,n[s+1]=e[3-s/4]>>>16&255,n[s+2]=e[3-s/4]>>>8&255,n[s+3]=255&e[3-s/4]}function l(r,n,t){for(var e=new Array(4),o=new Array(4),i=0;i<4;i++)o[0]=255&r[0+4*i],o[1]=255&r[1+4*i],o[2]=255&r[2+4*i],o[3]=255&r[3+4*i],e[i]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];e[0]^=2746333894,e[1]^=1453994832,e[2]^=1736282519,e[3]^=2993693404;for(var u,f=0;f<32;f+=4)u=e[1]^e[2]^e[3]^w[f+0],n[f+0]=e[0]^=a(c(u)),u=e[2]^e[3]^e[0]^w[f+1],n[f+1]=e[1]^=a(c(u)),u=e[3]^e[0]^e[1]^w[f+2],n[f+2]=e[2]^=a(c(u)),u=e[0]^e[1]^e[2]^w[f+3],n[f+3]=e[3]^=a(c(u));if(t===d)for(var s,p=0;p<16;p++)s=n[p],n[p]=n[31-p],n[31-p]=s}function v(r,n,t){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},c=s.padding,p=void 0===c?"pkcs#7":c,a=s.mode,v=s.iv,m=void 0===v?[]:v,w=s.output,b=void 0===w?"string":w;if("cbc"===a&&("string"==typeof m&&(m=o(m)),16!==m.length))throw new Error("iv is invalid");if("string"==typeof n&&(n=o(n)),16!==n.length)throw new Error("key is invalid");if(r="string"==typeof r?t!==d?u(r):o(r):[].concat(e(r)),("pkcs#5"===p||"pkcs#7"===p)&&t!==d)for(var A=y-r.length%y,x=0;x<A;x++)r.push(A);var j=new Array(g);l(n,j,t);for(var P=[],k=m,S=r.length,C=0;S>=y;){var E=r.slice(C,C+16),O=new Array(16);if("cbc"===a)for(var _=0;_<y;_++)t!==d&&(E[_]^=k[_]);h(E,O,j);for(var I=0;I<y;I++)"cbc"===a&&t===d&&(O[I]^=k[I]),P[C+I]=O[I];"cbc"===a&&(k=t!==d?O:E),S-=y,C+=y}if(("pkcs#5"===p||"pkcs#7"===p)&&t===d){var M=P[P.length-1];P.splice(P.length-M,M)}return"array"!==b?t!==d?i(P):f(P):P}var d=0,g=32,y=16,m=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],w=[462357,472066609,943670861,1415275113,1886879365,2358483617,2830087869,3301692121,3773296373,4228057617,404694573,876298825,1347903077,1819507329,2291111581,2762715833,3234320085,3705924337,4177462797,337322537,808926789,1280531041,1752135293,2223739545,2695343797,3166948049,3638552301,4110090761,269950501,741554753,1213159005,1684763257];r.exports={encrypt:function(r,n,t){return v(r,n,1,t)},decrypt:function(r,n,t){return v(r,n,0,t)}}}})}); | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.sm4=n():r.sm4=n()}("undefined"!=typeof self?self:this,function(){return function(r){function n(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var t={};return n.m=r,n.c=t,n.d=function(r,t,e){n.o(r,t)||Object.defineProperty(r,t,{configurable:!1,enumerable:!0,get:e})},n.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(t,"a",t),t},n.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},n.p="",n(n.s=7)}({7:function(r,n,t){"use strict";function e(r){if(Array.isArray(r)){for(var n=0,t=Array(r.length);n<r.length;n++)t[n]=r[n];return t}return Array.from(r)}function o(r){for(var n=[],t=0,e=r.length;t<e;t+=2)n.push(parseInt(r.substr(t,2),16));return n}function i(r){return r.map(function(r){return r=r.toString(16),1===r.length?"0"+r:r}).join("")}function u(r){for(var n=[],t=0,e=r.length;t<e;t++){var o=r.codePointAt(t);if(o<=127)n.push(o);else if(o<=2047)n.push(192|o>>>6),n.push(128|63&o);else if(o<=55295||o>=57344&&o<=65535)n.push(224|o>>>12),n.push(128|o>>>6&63),n.push(128|63&o);else{if(!(o>=65536&&o<=1114111))throw n.push(o),new Error("input is not supported");t++,n.push(240|o>>>18&28),n.push(128|o>>>12&63),n.push(128|o>>>6&63),n.push(128|63&o)}}return n}function f(r){for(var n=[],t=0,e=r.length;t<e;t++)r[t]>=240&&r[t]<=247?(n.push(String.fromCodePoint(((7&r[t])<<18)+((63&r[t+1])<<12)+((63&r[t+2])<<6)+(63&r[t+3]))),t+=3):r[t]>=224&&r[t]<=239?(n.push(String.fromCodePoint(((15&r[t])<<12)+((63&r[t+1])<<6)+(63&r[t+2]))),t+=2):r[t]>=192&&r[t]<=223?(n.push(String.fromCodePoint(((31&r[t])<<6)+(63&r[t+1]))),t++):n.push(String.fromCodePoint(r[t]));return n.join("")}function s(r,n){return r<<n|r>>>32-n}function c(r){return(255&w[r>>>24&255])<<24|(255&w[r>>>16&255])<<16|(255&w[r>>>8&255])<<8|255&w[255&r]}function p(r){return r^s(r,2)^s(r,10)^s(r,18)^s(r,24)}function a(r){return r^s(r,13)^s(r,23)}function h(r,n,t){for(var e=new Array(4),o=new Array(4),i=0;i<4;i++)o[0]=255&r[4*i],o[1]=255&r[4*i+1],o[2]=255&r[4*i+2],o[3]=255&r[4*i+3],e[i]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];for(var u,f=0;f<32;f+=4)u=e[1]^e[2]^e[3]^t[f+0],e[0]^=p(c(u)),u=e[2]^e[3]^e[0]^t[f+1],e[1]^=p(c(u)),u=e[3]^e[0]^e[1]^t[f+2],e[2]^=p(c(u)),u=e[0]^e[1]^e[2]^t[f+3],e[3]^=p(c(u));for(var s=0;s<16;s+=4)n[s]=e[3-s/4]>>>24&255,n[s+1]=e[3-s/4]>>>16&255,n[s+2]=e[3-s/4]>>>8&255,n[s+3]=255&e[3-s/4]}function l(r,n,t){for(var e=new Array(4),o=new Array(4),i=0;i<4;i++)o[0]=255&r[0+4*i],o[1]=255&r[1+4*i],o[2]=255&r[2+4*i],o[3]=255&r[3+4*i],e[i]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];e[0]^=2746333894,e[1]^=1453994832,e[2]^=1736282519,e[3]^=2993693404;for(var u,f=0;f<32;f+=4)u=e[1]^e[2]^e[3]^m[f+0],n[f+0]=e[0]^=a(c(u)),u=e[2]^e[3]^e[0]^m[f+1],n[f+1]=e[1]^=a(c(u)),u=e[3]^e[0]^e[1]^m[f+2],n[f+2]=e[2]^=a(c(u)),u=e[0]^e[1]^e[2]^m[f+3],n[f+3]=e[3]^=a(c(u));if(t===v)for(var s,p=0;p<16;p++)s=n[p],n[p]=n[31-p],n[31-p]=s}function d(r,n,t){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},c=s.padding,p=void 0===c?"pkcs#7":c,a=s.mode,d=s.iv,w=void 0===d?[]:d,m=s.output,b=void 0===m?"string":m;if("cbc"===a&&("string"==typeof w&&(w=o(w)),16!==w.length))throw new Error("iv is invalid");if("string"==typeof n&&(n=o(n)),16!==n.length)throw new Error("key is invalid");if(r="string"==typeof r?t!==v?u(r):o(r):[].concat(e(r)),("pkcs#5"===p||"pkcs#7"===p)&&t!==v)for(var A=y-r.length%y,x=0;x<A;x++)r.push(A);var j=new Array(g);l(n,j,t);for(var P=[],k=w,S=r.length,C=0;S>=y;){var E=r.slice(C,C+16),O=new Array(16);if("cbc"===a)for(var _=0;_<y;_++)t!==v&&(E[_]^=k[_]);h(E,O,j);for(var I=0;I<y;I++)"cbc"===a&&t===v&&(O[I]^=k[I]),P[C+I]=O[I];"cbc"===a&&(k=t!==v?O:E),S-=y,C+=y}if(("pkcs#5"===p||"pkcs#7"===p)&&t===v){for(var M=P.length,q=P[M-1],z=1;z<=q;z++)if(P[M-z]!==q)throw new Error("padding is invalid");P.splice(M-q,q)}return"array"!==b?t!==v?i(P):f(P):P}var v=0,g=32,y=16,w=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],m=[462357,472066609,943670861,1415275113,1886879365,2358483617,2830087869,3301692121,3773296373,4228057617,404694573,876298825,1347903077,1819507329,2291111581,2762715833,3234320085,3705924337,4177462797,337322537,808926789,1280531041,1752135293,2223739545,2695343797,3166948049,3638552301,4110090761,269950501,741554753,1213159005,1684763257];r.exports={encrypt:function(r,n,t){return d(r,n,1,t)},decrypt:function(r,n,t){return d(r,n,0,t)}}}})}); |
{ | ||
"name": "sm-crypto", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"description": "sm-crypto", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -118,2 +118,7 @@ # sm-crypto | ||
let hashData = sm3('abc') // 杂凑 | ||
// hmac | ||
hashData = sm3('abc', { | ||
key: 'daac25c1512fe50f79b0e4526b93f5c0e1460cef40b6dd44af13caec62e8c60e0d885f3c6d6fb51e530889e6fd4ac743a6d332e68a0f2a3923f42585dceb93e9', // 要求为 16 进制串或字节数组 | ||
}) | ||
``` | ||
@@ -120,0 +125,0 @@ |
@@ -5,3 +5,3 @@ /* eslint-disable no-use-before-define */ | ||
const _ = require('./utils') | ||
const sm3 = require('./sm3') | ||
const sm3 = require('./sm3').sm3 | ||
@@ -8,0 +8,0 @@ const {G, curve, n} = _.generateEcparam() |
@@ -174,3 +174,6 @@ /** | ||
module.exports = function (array) { | ||
/** | ||
* sm3 本体 | ||
*/ | ||
function sm3(array) { | ||
// 填充 | ||
@@ -213,1 +216,32 @@ let len = array.length * 8 | ||
} | ||
/** | ||
* hmac 实现 | ||
*/ | ||
const blockLen = 64 | ||
const iPad = new Array(blockLen) | ||
const oPad = new Array(blockLen) | ||
for (let i = 0; i < blockLen; i++) { | ||
iPad[i] = 0x36 | ||
oPad[i] = 0x5c | ||
} | ||
function hmac(input, key) { | ||
// 密钥填充 | ||
if (key.length > blockLen) key = sm3(key) | ||
while (key.length < blockLen) key.push(0) | ||
const iPadKey = xor(key, iPad) | ||
let hash = iPadKey.concat(input) | ||
hash = sm3(hash) | ||
const oPadKey = xor(key, oPad) | ||
hash = oPadKey.concat(hash) | ||
hash = sm3(hash) | ||
return hash | ||
} | ||
module.exports = { | ||
sm3, | ||
hmac, | ||
} |
@@ -1,4 +0,13 @@ | ||
const sm3 = require('../sm2/sm3') | ||
const {sm3, hmac} = require('../sm2/sm3') | ||
/** | ||
* 补全16进制字符串 | ||
*/ | ||
function leftPad(input, num) { | ||
if (input.length >= num) return input | ||
return (new Array(num - input.length + 1)).join('0') + input | ||
} | ||
/** | ||
* 字节数组转 16 进制串 | ||
@@ -14,2 +23,21 @@ */ | ||
/** | ||
* 转成字节数组 | ||
*/ | ||
function hexToArray(hexStr) { | ||
const words = [] | ||
let hexStrLength = hexStr.length | ||
if (hexStrLength % 2 !== 0) { | ||
hexStr = leftPad(hexStr, hexStrLength + 1) | ||
} | ||
hexStrLength = hexStr.length | ||
for (let i = 0; i < hexStrLength; i += 2) { | ||
words.push(parseInt(hexStr.substr(i, 2), 16)) | ||
} | ||
return words | ||
} | ||
/** | ||
* utf8 串转字节数组 | ||
@@ -52,5 +80,17 @@ */ | ||
module.exports = function (input) { | ||
module.exports = function (input, options) { | ||
input = typeof input === 'string' ? utf8ToArray(input) : Array.prototype.slice.call(input) | ||
if (options) { | ||
const mode = options.mode || 'hmac' | ||
if (mode !== 'hmac') throw new Error('invalid mode') | ||
let key = options.key | ||
if (!key) throw new Error('invalid key') | ||
key = typeof key === 'string' ? hexToArray(key) : Array.prototype.slice.call(key) | ||
return ArrayToHex(hmac(input, key)) | ||
} | ||
return ArrayToHex(sm3(input)) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97573
1482
156