/*
Chen, Yi-Cyuan 2015-2017
@license MIT
*/
(function(){function n(a,c,d){this.blocks=[];this.s=[];this.padding=c;this.outputBits=d;this.reset=!0;this.start=this.block=0;this.blockCount=1600-(a<<1)>>5;this.byteCount=this.blockCount<<2;this.outputBlocks=d>>5;this.extraBytes=(d&31)>>3;for(a=0;50>a;++a)this.s[a]=0}function D(a,c,d){n.call(this,a,c,d)}var u="object"===typeof window?window:{};!u.JS_SHA3_NO_NODE_JS&&"object"===typeof process&&process.versions&&process.versions.node&&(u=global);var na=!u.JS_SHA3_NO_COMMON_JS&&"object"===typeof module&&
module.exports,ea=!u.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!==typeof ArrayBuffer,p="0123456789abcdef".split(""),y=[4,1024,262144,67108864],v=[0,8,16,24],fa=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],
w=[224,256,384,512],r=[128,256],ga=["hex","buffer","arrayBuffer","array"],ha={128:168,256:136};if(u.JS_SHA3_NO_NODE_JS||!Array.isArray)Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)};for(var ia=function(a,c,d){return function(b){return(new n(a,c,a)).update(b)[d]()}},ja=function(a,c,d){return function(b,g){return(new n(a,c,g)).update(b)[d]()}},ka=function(a,c,d){return function(b,c,k,h){return x["cshake"+a].update(b,c,k,h)[d]()}},la=function(a,c,d){return function(b,
c,k,h){return x["kmac"+a].update(b,c,k,h)[d]()}},B=function(a,c,d,b){for(var g=0;g<ga.length;++g){var k=ga[g];a[k]=c(d,b,k)}return a},t=function(a,c){var d=ia(a,c,"hex");d.create=function(){return new n(a,c,a)};d.update=function(a){return d.create().update(a)};return B(d,ia,a,c)},y=[{name:"keccak",padding:[1,256,65536,16777216],bits:w,createMethod:t},{name:"sha3",padding:[6,1536,393216,100663296],bits:w,createMethod:t},{name:"shake",padding:[31,7936,2031616,520093696],bits:r,createMethod:function(a,
c){var d=ja(a,c,"hex");d.create=function(b){return new n(a,c,b)};d.update=function(a,c){return d.create(c).update(a)};return B(d,ja,a,c)}},{name:"cshake",padding:y,bits:r,createMethod:function(a,c){var d=ha[a],b=ka(a,c,"hex");b.create=function(b,k,h){return k||h?(new n(a,c,b)).bytepad([k,h],d):x["shake"+a].create(b)};b.update=function(a,c,d,f){return b.create(c,d,f).update(a)};return B(b,ka,a,c)}},{name:"kmac",padding:y,bits:r,createMethod:function(a,c){var d=ha[a],b=la(a,c,"hex");b.create=function(b,
k,h){return(new D(a,c,k)).bytepad(["KMAC",h],d).bytepad(,d)};b.update=function(a,c,d,f){return b.create(a,d,f).update(c)};return B(b,la,a,c)}}],x={},w=[],r=0;r<y.length;++r)for(var t=y[r],C=t.bits,z=0;z<C.length;++z){var E=t.name+"_"+C[z];w.push(E);x[E]=t.createMethod(C[z],t.padding);if("sha3"!==t.name){var ma=t.name+C[z];w.push(ma);x[ma]=x[E]}}n.prototype.update=function(a){var c="string"!==typeof a;c&&a.constructor===u.ArrayBuffer&&(a=new Uint8Array(a));var d=a.length;if(c&&("number"!==typeof d||
!(Array.isArray(a)||ea&&ArrayBuffer.isView(a))))throw"input is invalid type";for(var b=this.blocks,g=this.byteCount,k=this.blockCount,h=0,f=this.s,e,q;h<d;){if(this.reset)for(this.reset=!1,b[0]=this.block,e=1;e<k+1;++e)b[e]=0;if(c)for(e=this.start;h<d&&e<g;++h)b[e>>2]|=a[h]<<v[e++&3];else for(e=this.start;h<d&&e<g;++h)q=a.charCodeAt(h),128>q?b[e>>2]|=q<<v[e++&3]:(2048>q?b[e>>2]|=(192|q>>6)<<v[e++&3]:(55296>q||57344<=q?b[e>>2]|=(224|q>>12)<<v[e++&3]:(q=65536+((q&1023)<<10|a.charCodeAt(++h)&1023),b[e>>
2]|=(240|q>>18)<<v[e++&3],b[e>>2]|=(128|q>>12&63)<<v[e++&3]),b[e>>2]|=(128|q>>6&63)<<v[e++&3]),b[e>>2]|=(128|q&63)<<v[e++&3]);this.lastByteIndex=e;if(e>=g){this.start=e-g;this.block=b[k];for(e=0;e<k;++e)f[e]^=b[e];A(f);this.reset=!0}else this.start=e}return this};n.prototype.encode=function(a,c){var d,b=1,g=[a&255];a>>=8;for(d=a&255;0<d;)g.unshift(d),a>>=8,d=a&255,++b;c?g.push(b):g.unshift(b);this.update(g);return g.length};n.prototype.encodeString=function(a){a=a||"";var c="string"!==typeof a;c&&
a.constructor===u.ArrayBuffer&&(a=new Uint8Array(a));var d=a.length;if(c&&("number"!==typeof d||!(Array.isArray(a)||ea&&ArrayBuffer.isView(a))))throw"input is invalid type";var b=0;if(c)b=d;else for(c=0;c<a.length;++c)d=a.charCodeAt(c),128>d?b+=1:2048>d?b+=2:55296>d||57344<=d?b+=3:(a.charCodeAt(++c),b+=4);b+=this.encode(8*b);this.update(a);return b};n.prototype.bytepad=function(a,c){for(var d=this.encode(c),b=0;b<a.length;++b)d+=this.encodeString(a);b=[];b.length=c-d%c;this.update(b);return this};
n.prototype.finalize=function(){var a=this.blocks,c=this.lastByteIndex,d=this.blockCount,b=this.s;a[c>>2]|=this.padding[c&3];if(this.lastByteIndex===this.byteCount)for(a[0]=a[d],c=1;c<d+1;++c)a[c]=0;a[d-1]|=2147483648;for(c=0;c<d;++c)b[c]^=a[c];A(b)};n.prototype.toString=n.prototype.hex=function(){this.finalize();for(var a=this.blockCount,c=this.s,d=this.outputBlocks,b=this.extraBytes,g=0,k=0,h="",f;k<d;){for(g=0;g<a&&k<d;++g,++k)f=c[g],h+=p[f>>4&15]+p[f&15]+p[f>>12&15]+p[f>>8&15]+p[f>>20&15]+p[f>>
16&15]+p[f>>28&15]+p[f>>24&15];0===k%a&&(A(c),g=0)}b&&(f=c[g],0<b&&(h+=p[f>>4&15]+p[f&15]),1<b&&(h+=p[f>>12&15]+p[f>>8&15]),2<b&&(h+=p[f>>20&15]+p[f>>16&15]));return h};n.prototype.arrayBuffer=function(){this.finalize();var a=this.blockCount,c=this.s,d=this.outputBlocks,b=this.extraBytes,g=0,k=0,h=this.outputBits>>3;var f=b?new ArrayBuffer(d+1<<2):new ArrayBuffer(h);for(var e=new Uint32Array(f);k<d;){for(g=0;g<a&&k<d;++g,++k)e[k]=c[g];0===k%a&&A(c)}b&&(e[g]=c[g],f=f.slice(0,h));return f};n.prototype.buffer=
n.prototype.arrayBuffer;n.prototype.digest=n.prototype.array=function(){this.finalize();for(var a=this.blockCount,c=this.s,d=this.outputBlocks,b=this.extraBytes,g=0,k=0,h=[],f,e;k<d;){for(g=0;g<a&&k<d;++g,++k)f=k<<2,e=c[g],h[f]=e&255,h[f+1]=e>>8&255,h[f+2]=e>>16&255,h[f+3]=e>>24&255;0===k%a&&A(c)}b&&(f=k<<2,e=c[g],0<b&&(h[f]=e&255),1<b&&(h[f+1]=e>>8&255),2<b&&(h[f+2]=e>>16&255));return h};D.prototype=new n;D.prototype.finalize=function(){this.encode(this.outputBits,!0);return n.prototype.finalize.call(this)};
var A=function(a){var c;for(c=0;48>c;c+=2){var d=a[0]^a[10]^a[20]^a[30]^a[40];var b=a[1]^a[11]^a[21]^a[31]^a[41];var g=a[2]^a[12]^a[22]^a[32]^a[42];var k=a[3]^a[13]^a[23]^a[33]^a[43];var h=a[4]^a[14]^a[24]^a[34]^a[44];var f=a[5]^a[15]^a[25]^a[35]^a[45];var e=a[6]^a[16]^a[26]^a[36]^a[46];var q=a[7]^a[17]^a[27]^a[37]^a[47];var n=a[8]^a[18]^a[28]^a[38]^a[48];var p=a[9]^a[19]^a[29]^a[39]^a[49];var l=n^(g<<1|k>>>31);var m=p^(k<<1|g>>>31);a[0]^=l;a[1]^=m;a[10]^=l;a[11]^=m;a[20]^=l;a[21]^=m;a[30]^=l;a[31]^=
m;a[40]^=l;a[41]^=m;l=d^(h<<1|f>>>31);m=b^(f<<1|h>>>31);a[2]^=l;a[3]^=m;a[12]^=l;a[13]^=m;a[22]^=l;a[23]^=m;a[32]^=l;a[33]^=m;a[42]^=l;a[43]^=m;l=g^(e<<1|q>>>31);m=k^(q<<1|e>>>31);a[4]^=l;a[5]^=m;a[14]^=l;a[15]^=m;a[24]^=l;a[25]^=m;a[34]^=l;a[35]^=m;a[44]^=l;a[45]^=m;l=h^(n<<1|p>>>31);m=f^(p<<1|n>>>31);a[6]^=l;a[7]^=m;a[16]^=l;a[17]^=m;a[26]^=l;a[27]^=m;a[36]^=l;a[37]^=m;a[46]^=l;a[47]^=m;l=e^(d<<1|b>>>31);m=q^(b<<1|d>>>31);a[8]^=l;a[9]^=m;a[18]^=l;a[19]^=m;a[28]^=l;a[29]^=m;a[38]^=l;a[39]^=m;a[48]^=
l;a[49]^=m;l=a[0];m=a[1];var r=a[11]<<4|a[10]>>>28;var t=a[10]<<4|a[11]>>>28;var u=a[20]<<3|a[21]>>>29;var v=a[21]<<3|a[20]>>>29;var w=a[31]<<9|a[30]>>>23;var x=a[30]<<9|a[31]>>>23;var y=a[40]<<18|a[41]>>>14;var z=a[41]<<18|a[40]>>>14;var A=a[2]<<1|a[3]>>>31;var B=a[3]<<1|a[2]>>>31;d=a[13]<<12|a[12]>>>20;b=a[12]<<12|a[13]>>>20;var C=a[22]<<10|a[23]>>>22;var D=a[23]<<10|a[22]>>>22;var E=a[33]<<13|a[32]>>>19;var F=a[32]<<13|a[33]>>>19;var G=a[42]<<2|a[43]>>>30;var H=a[43]<<2|a[42]>>>30;var I=a[5]<<
30|a[4]>>>2;var J=a[4]<<30|a[5]>>>2;var K=a[14]<<6|a[15]>>>26;var L=a[15]<<6|a[14]>>>26;g=a[25]<<11|a[24]>>>21;k=a[24]<<11|a[25]>>>21;var M=a[34]<<15|a[35]>>>17;var N=a[35]<<15|a[34]>>>17;var O=a[45]<<29|a[44]>>>3;var P=a[44]<<29|a[45]>>>3;n=a[6]<<28|a[7]>>>4;p=a[7]<<28|a[6]>>>4;var Q=a[17]<<23|a[16]>>>9;var R=a[16]<<23|a[17]>>>9;var S=a[26]<<25|a[27]>>>7;var T=a[27]<<25|a[26]>>>7;h=a[36]<<21|a[37]>>>11;f=a[37]<<21|a[36]>>>11;var U=a[47]<<24|a[46]>>>8;var V=a[46]<<24|a[47]>>>8;var W=a[8]<<27|a[9]>>>
5;var X=a[9]<<27|a[8]>>>5;var Y=a[18]<<20|a[19]>>>12;var Z=a[19]<<20|a[18]>>>12;var aa=a[29]<<7|a[28]>>>25;var ba=a[28]<<7|a[29]>>>25;var ca=a[38]<<8|a[39]>>>24;var da=a[39]<<8|a[38]>>>24;e=a[48]<<14|a[49]>>>18;q=a[49]<<14|a[48]>>>18;a[0]=l^~d&g;a[1]=m^~b&k;a[10]=n^~Y&u;a[11]=p^~Z&v;a[20]=A^~K&S;a[21]=B^~L&T;a[30]=W^~r&C;a[31]=X^~t&D;a[40]=I^~Q&aa;a[41]=J^~R&ba;a[2]=d^~g&h;a[3]=b^~k&f;a[12]=Y^~u&E;a[13]=Z^~v&F;a[22]=K^~S&ca;a[23]=L^~T&da;a[32]=r^~C&M;a[33]=t^~D&N;a[42]=Q^~aa&w;a[43]=R^~ba&x;a[4]=
g^~h&e;a[5]=k^~f&q;a[14]=u^~E&O;a[15]=v^~F&P;a[24]=S^~ca&y;a[25]=T^~da&z;a[34]=C^~M&U;a[35]=D^~N&V;a[44]=aa^~w&G;a[45]=ba^~x&H;a[6]=h^~e&l;a[7]=f^~q&m;a[16]=E^~O&n;a[17]=F^~P&p;a[26]=ca^~y&A;a[27]=da^~z&B;a[36]=M^~U&W;a[37]=N^~V&X;a[46]=w^~G&I;a[47]=x^~H&J;a[8]=e^~l&d;a[9]=q^~m&b;a[18]=O^~n&Y;a[19]=P^~p&Z;a[28]=y^~A&K;a[29]=z^~B&L;a[38]=U^~W&r;a[39]=V^~X&t;a[48]=G^~I&Q;a[49]=H^~J&R;a[0]^=fa[c];a[1]^=fa[c+1]}};if(na)module.exports=x;else for(r=0;r<w.length;++r)u[w[r]]=x[w[r]]})();