Files
js-sha3/build/sha3.min.mjs
T
Yi-Cyuan Chen a67f74cf2c ### Added
- ParallelHash128, ParallelHash256, ParallelHashXOF128, and ParallelHashXOF256 (NIST SP 800-185)
2026-08-07 08:18:38 +08:00

10 lines
15 KiB
JavaScript

var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var r,n={exports:{}};
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.13.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2026
* @license MIT
*/r=n,function(){var e="input is invalid type",n="finalize already called",i="tuple input is incomplete",a="object"==typeof window,o=a?window:{};o.JS_SHA3_NO_WINDOW&&(a=!1);var s=!a&&"object"==typeof self;!o.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?o=t:s&&(o=self);for(var u=!o.JS_SHA3_NO_COMMON_JS&&r.exports,h=!o.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),c=[31,7936,2031616,520093696],p=[4,1024,262144,67108864],l=[0,8,16,24],d=[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],y=[224,256,384,512],k=[128,256],b=["hex","buffer","arrayBuffer","array","digest"],v={128:168,256:136},_=o.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,g=!h||!o.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},w=function(t){var r=typeof t;if("string"===r)return[t,!0];if("object"!==r||null===t)throw new Error(e);if(h&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!_(t)&&!g(t))throw new Error(e);return[t,!1]},x=function(t){return 0===w(t)[0].length},B=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},A=function(t,e,r){return function(n){return new W(t,e,t).update(n)[r]()}},m=function(t,e,r){return function(n,i){return new W(t,e,i).update(n)[r]()}},C=function(t,e,r){return function(e,n,i,a){return j["cshake"+t].update(e,n,i,a)[r]()}},S=function(t,e,r,n){return function(e,i,a,o){return j[(r?"kmacxof":"kmac")+t].update(e,i,a,o)[n]()}},z=function(t,e,r,n){return function(e,i,a){return j[(r?"tuplehashxof":"tuplehash")+t].update(e,i,a)[n]()}},M=function(t,e,r,n){return function(e,i,a,o){return j[(r?"parallelhashxof":"parallelhash")+t].update(e,i,a,o)[n]()}},E=function(t,e,r,n){for(var i=0;i<b.length;++i){var a=b[i];t[a]=e(r,n,a)}return t},O=function(t,e){var r=A(t,e,"hex");return r.create=function(){return new W(t,e,t)},r.update=function(t){return r.create().update(t)},E(r,A,t,e)},N=function(t,e,r){var n=v[t],i=S(t,0,r,"hex");return i.create=function(i,a,o){return new P(t,e,a,r).bytepad(["KMAC",o],n).bytepad([i],n)},i.update=function(t,e,r,n){return i.create(t,r,n).update(e)},E(i,function(t,e,n){return S(t,0,r,n)},t,e)},I=function(t,r,n){var i=v[t],a=z(t,0,n,"hex");return a.create=function(e,a){return new Y(t,r,e,n).bytepad(["TupleHash",a],i)},a.update=function(t,r,n){if(!_(t))throw new Error(e);for(var i=a.create(r,n),o=0;o<t.length;++o)i.update(t[o]);return i},E(a,function(t,e,r){return z(t,0,n,r)},t,r)},R=function(t,e,r){var n=v[t],i=M(t,0,r,"hex");return i.create=function(i,a,o){if("number"!=typeof i||!isFinite(i)||i<1||Math.floor(i)!==i||i>268435455)throw new Error("block size is invalid");var s=new K(t,e,a,r,i).bytepad(["ParallelHash",o],n);return s.encode(i,!1),s},i.update=function(t,e,r,n){return i.create(e,r,n).update(t)},E(i,function(t,e,n){return M(t,0,r,n)},t,e)},J=[{name:"keccak",padding:[1,256,65536,16777216],bits:y,createMethod:O},{name:"sha3",padding:[6,1536,393216,100663296],bits:y,createMethod:O},{name:"shake",padding:c,bits:k,createMethod:function(t,e){var r=m(t,e,"hex");return r.create=function(r){return new W(t,e,r)},r.update=function(t,e){return r.create(e).update(t)},E(r,m,t,e)}},{name:"cshake",padding:p,bits:k,createMethod:function(t,e){var r=v[t],n=C(t,0,"hex");return n.create=function(n,i,a){return x(i)&&x(a)?j["shake"+t].create(n):new W(t,e,n).bytepad([i,a],r)},n.update=function(t,e,r,i){return n.create(e,r,i).update(t)},E(n,C,t,e)}},{name:"kmac",padding:p,bits:k,createMethod:function(t,e){return N(t,e,!1)}},{name:"kmacxof",padding:p,bits:k,createMethod:function(t,e){return N(t,e,!0)}},{name:"tuplehash",padding:p,bits:k,createMethod:function(t,e){return I(t,e,!1)}},{name:"tuplehashxof",padding:p,bits:k,createMethod:function(t,e){return I(t,e,!0)}},{name:"parallelhash",padding:p,bits:k,createMethod:function(t,e){return R(t,e,!1)}},{name:"parallelhashxof",padding:p,bits:k,createMethod:function(t,e){return R(t,e,!0)}}],j={},H=[],F=0;F<J.length;++F)for(var U=J[F],D=U.bits,L=0;L<D.length;++L){var T=U.name+"_"+D[L];if(H.push(T),j[T]=U.createMethod(D[L],U.padding),"sha3"!==U.name){var V=U.name+D[L];H.push(V),j[V]=j[T]}}function W(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function P(t,e,r,n){W.call(this,t,e,r),this.xof=n}function Y(t,e,r,n){P.call(this,t,e,r,n),this.inputActive=!1,this.inputBytesRemaining=0}function K(t,e,r,n,i){P.call(this,t,e,r,n),this.bits=t,this.blockSize=i,this.inner=null,this.innerBytes=0,this.blockNumber=0}W.prototype.update=function(t){if(this.finalized)throw new Error(n);var e=w(t);t=e[0];for(var r,i,a=e[1],o=this.blocks,s=this.byteCount,u=t.length,h=this.blockCount,f=0,c=this.s;f<u;){if(this.reset)for(this.reset=!1,o[0]=this.block,r=1;r<h+1;++r)o[r]=0;if(a)for(r=this.start;f<u&&r<s;++f)(i=t.charCodeAt(f))<128?o[r>>2]|=i<<l[3&r++]:i<2048?(o[r>>2]|=(192|i>>6)<<l[3&r++],o[r>>2]|=(128|63&i)<<l[3&r++]):i<55296||i>=57344?(o[r>>2]|=(224|i>>12)<<l[3&r++],o[r>>2]|=(128|i>>6&63)<<l[3&r++],o[r>>2]|=(128|63&i)<<l[3&r++]):(i=65536+((1023&i)<<10|1023&t.charCodeAt(++f)),o[r>>2]|=(240|i>>18)<<l[3&r++],o[r>>2]|=(128|i>>12&63)<<l[3&r++],o[r>>2]|=(128|i>>6&63)<<l[3&r++],o[r>>2]|=(128|63&i)<<l[3&r++]);else for(r=this.start;f<u&&r<s;++f)o[r>>2]|=t[f]<<l[3&r++];if(this.lastByteIndex=r,r>=s){for(this.start=r-s,this.block=o[h],r=0;r<h;++r)c[r]^=o[r];q(c),this.reset=!0}else this.start=r}return this},W.prototype.encode=function(t,e){var r=255&t,n=1,i=[r];for(r=255&(t>>=8);r>0;)i.unshift(r),r=255&(t>>=8),++n;return e?i.push(n):i.unshift(n),W.prototype.update.call(this,i),i.length},W.prototype.encodeString=function(t){var e=w(t);t=e[0];var r=e[1],n=0,i=t.length;if(r)for(var a=0;a<t.length;++a){var o=t.charCodeAt(a);o<128?n+=1:o<2048?n+=2:o<55296||o>=57344?n+=3:(o=65536+((1023&o)<<10|1023&t.charCodeAt(++a)),n+=4)}else n=i;return n+=this.encode(8*n),W.prototype.update.call(this,t),n},W.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var i=(e-r%e)%e,a=[];return a.length=i,W.prototype.update.call(this,a),this},W.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];q(n)}},W.prototype.toString=W.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,a=0,o=0,s="";o<n;){for(a=0;a<e&&o<n;++a,++o)t=r[a],s+=f[t>>4&15]+f[15&t]+f[t>>12&15]+f[t>>8&15]+f[t>>20&15]+f[t>>16&15]+f[t>>28&15]+f[t>>24&15];o%e===0&&(r=B(r),q(r),a=0)}return i&&(t=r[a],s+=f[t>>4&15]+f[15&t],i>1&&(s+=f[t>>12&15]+f[t>>8&15]),i>2&&(s+=f[t>>20&15]+f[t>>16&15])),s},W.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,a=0,o=0,s=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(s);for(var u=new Uint32Array(t);o<n;){for(a=0;a<e&&o<n;++a,++o)u[o]=r[a];o%e===0&&(r=B(r),q(r))}return i&&(u[o]=r[a],t=t.slice(0,s)),t},W.prototype.buffer=W.prototype.arrayBuffer,W.prototype.digest=W.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,i=this.outputBlocks,a=this.extraBytes,o=0,s=0,u=[];s<i;){for(o=0;o<r&&s<i;++o,++s)t=s<<2,e=n[o],u[t]=255&e,u[t+1]=e>>8&255,u[t+2]=e>>16&255,u[t+3]=e>>24&255;s%r===0&&(n=B(n),q(n))}return a&&(t=s<<2,e=n[o],u[t]=255&e,a>1&&(u[t+1]=e>>8&255),a>2&&(u[t+2]=e>>16&255)),u},P.prototype=new W,P.prototype.finalize=function(){return this.finalized||this.encode(this.xof?0:this.outputBits,!0),W.prototype.finalize.call(this)},Y.prototype=new P,Y.prototype.getMessageByteLength=function(t){var e=w(t);if(t=e[0],!e[1])return t.length;for(var r=0,n=0;n<t.length;++n){var i=t.charCodeAt(n);i<128?r+=1:i<2048?r+=2:i<55296||i>=57344?r+=3:(++n,r+=4)}return r},Y.prototype.beginInput=function(t){if(this.inputActive)throw new Error(i);if("number"!=typeof t||!isFinite(t)||t<0||Math.floor(t)!==t||t>268435455)throw new Error("tuple input byte length is invalid");return this.encode(8*t,!1),0!==t&&(this.inputActive=!0,this.inputBytesRemaining=t),this},Y.prototype._updateChunk=function(t,e){return P.prototype.update.call(this,t),this.inputBytesRemaining-=e,0===this.inputBytesRemaining&&(this.inputActive=!1),this},Y.prototype.updateChunk=function(t){if(!this.inputActive)throw new Error("no active tuple input");var e=this.getMessageByteLength(t);if(e>this.inputBytesRemaining)throw new Error("tuple input exceeds declared length");return this._updateChunk(t,e)},Y.prototype.update=function(t){var e=this.getMessageByteLength(t);return this.beginInput(e),this._updateChunk(t,e)},Y.prototype.finalize=function(){if(this.inputActive)throw new Error(i);return P.prototype.finalize.call(this)},K.prototype=new P,K.prototype._finishInner=function(){P.prototype.update.call(this,this.inner.array()),this.inner=null,this.innerBytes=0,++this.blockNumber},K.prototype._updateBytes=function(t){var e=t.length;if(e)for(var r=t.subarray||t.slice,n=this.blockSize,i=0;i<e;){this.inner||(this.inner=new W(this.bits,c,this.bits<<1));var a=n-this.innerBytes;e-i<a&&(a=e-i),this.inner.update(r.call(t,i,i+a)),this.innerBytes+=a,i+=a,this.innerBytes===n&&this._finishInner()}},K.prototype.update=function(t){if(this.finalized)throw new Error(n);var e=w(t);if(t=e[0],e[1]){var r,i,a=[],o=t.length,s=0;for(i=0;i<o;++i)(r=t.charCodeAt(i))<128?a[s++]=r:r<2048?(a[s++]=192|r>>>6,a[s++]=128|63&r):r<55296||r>=57344?(a[s++]=224|r>>>12,a[s++]=128|r>>>6&63,a[s++]=128|63&r):(r=65536+((1023&r)<<10|1023&t.charCodeAt(++i)),a[s++]=240|r>>>18,a[s++]=128|r>>>12&63,a[s++]=128|r>>>6&63,a[s++]=128|63&r);t=a}return this._updateBytes(t),this},K.prototype.finalize=function(){return this.finalized||(this.inner&&this._finishInner(),this.encode(this.blockNumber,!0)),P.prototype.finalize.call(this)};var q=function(t){var e,r,n,i,a,o,s,u,h,f,c,p,l,y,k,b,v,_,g,w,x,B,A,m,C,S,z,M,E,O,N,I,R,J,j,H,F,U,D,L,T,V,W,P,Y,K,q,G,Q,X,Z,$,tt,et,rt,nt,it,at,ot,st,ut,ht,ft;for(n=0;n<48;n+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],a=t[1]^t[11]^t[21]^t[31]^t[41],o=t[2]^t[12]^t[22]^t[32]^t[42],s=t[3]^t[13]^t[23]^t[33]^t[43],u=t[4]^t[14]^t[24]^t[34]^t[44],h=t[5]^t[15]^t[25]^t[35]^t[45],f=t[6]^t[16]^t[26]^t[36]^t[46],c=t[7]^t[17]^t[27]^t[37]^t[47],e=(p=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|s>>>31),r=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(s<<1|o>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=i^(u<<1|h>>>31),r=a^(h<<1|u>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=o^(f<<1|c>>>31),r=s^(c<<1|f>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=u^(p<<1|l>>>31),r=h^(l<<1|p>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=f^(i<<1|a>>>31),r=c^(a<<1|i>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,y=t[0],k=t[1],K=t[11]<<4|t[10]>>>28,q=t[10]<<4|t[11]>>>28,M=t[20]<<3|t[21]>>>29,E=t[21]<<3|t[20]>>>29,st=t[31]<<9|t[30]>>>23,ut=t[30]<<9|t[31]>>>23,V=t[40]<<18|t[41]>>>14,W=t[41]<<18|t[40]>>>14,J=t[2]<<1|t[3]>>>31,j=t[3]<<1|t[2]>>>31,b=t[13]<<12|t[12]>>>20,v=t[12]<<12|t[13]>>>20,G=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,O=t[33]<<13|t[32]>>>19,N=t[32]<<13|t[33]>>>19,ht=t[42]<<2|t[43]>>>30,ft=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,H=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,_=t[25]<<11|t[24]>>>21,g=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,I=t[45]<<29|t[44]>>>3,R=t[44]<<29|t[45]>>>3,m=t[6]<<28|t[7]>>>4,C=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,U=t[26]<<25|t[27]>>>7,D=t[27]<<25|t[26]>>>7,w=t[36]<<21|t[37]>>>11,x=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,P=t[8]<<27|t[9]>>>5,Y=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,z=t[19]<<20|t[18]>>>12,at=t[29]<<7|t[28]>>>25,ot=t[28]<<7|t[29]>>>25,L=t[38]<<8|t[39]>>>24,T=t[39]<<8|t[38]>>>24,B=t[48]<<14|t[49]>>>18,A=t[49]<<14|t[48]>>>18,t[0]=y^~b&_,t[1]=k^~v&g,t[10]=m^~S&M,t[11]=C^~z&E,t[20]=J^~H&U,t[21]=j^~F&D,t[30]=P^~K&G,t[31]=Y^~q&Q,t[40]=et^~nt&at,t[41]=rt^~it&ot,t[2]=b^~_&w,t[3]=v^~g&x,t[12]=S^~M&O,t[13]=z^~E&N,t[22]=H^~U&L,t[23]=F^~D&T,t[32]=K^~G&X,t[33]=q^~Q&Z,t[42]=nt^~at&st,t[43]=it^~ot&ut,t[4]=_^~w&B,t[5]=g^~x&A,t[14]=M^~O&I,t[15]=E^~N&R,t[24]=U^~L&V,t[25]=D^~T&W,t[34]=G^~X&$,t[35]=Q^~Z&tt,t[44]=at^~st&ht,t[45]=ot^~ut&ft,t[6]=w^~B&y,t[7]=x^~A&k,t[16]=O^~I&m,t[17]=N^~R&C,t[26]=L^~V&J,t[27]=T^~W&j,t[36]=X^~$&P,t[37]=Z^~tt&Y,t[46]=st^~ht&et,t[47]=ut^~ft&rt,t[8]=B^~y&b,t[9]=A^~k&v,t[18]=I^~m&S,t[19]=R^~C&z,t[28]=V^~J&H,t[29]=W^~j&F,t[38]=$^~P&K,t[39]=tt^~Y&q,t[48]=ht^~et&nt,t[49]=ft^~rt&it,t[0]^=d[n],t[1]^=d[n+1]};if(u)r.exports=j;else for(F=0;F<H.length;++F)o[H[F]]=j[H[F]]}();var i=e(n.exports);const{sha3_224:a,sha3_256:o,sha3_384:s,sha3_512:u,keccak_224:h,keccak_256:f,keccak_384:c,keccak_512:p,keccak224:l,keccak256:d,keccak384:y,keccak512:k,shake_128:b,shake_256:v,shake128:_,shake256:g,cshake_128:w,cshake_256:x,cshake128:B,cshake256:A,kmac_128:m,kmac_256:C,kmac128:S,kmac256:z,kmacxof_128:M,kmacxof_256:E,kmacxof128:O,kmacxof256:N,tuplehash_128:I,tuplehash_256:R,tuplehash128:J,tuplehash256:j,tuplehashxof_128:H,tuplehashxof_256:F,tuplehashxof128:U,tuplehashxof256:D,parallelhash_128:L,parallelhash_256:T,parallelhash128:V,parallelhash256:W,parallelhashxof_128:P,parallelhashxof_256:Y,parallelhashxof128:K,parallelhashxof256:q}=i;export{B as cshake128,A as cshake256,w as cshake_128,x as cshake_256,i as default,l as keccak224,d as keccak256,y as keccak384,k as keccak512,h as keccak_224,f as keccak_256,c as keccak_384,p as keccak_512,S as kmac128,z as kmac256,m as kmac_128,C as kmac_256,O as kmacxof128,N as kmacxof256,M as kmacxof_128,E as kmacxof_256,V as parallelhash128,W as parallelhash256,L as parallelhash_128,T as parallelhash_256,K as parallelhashxof128,q as parallelhashxof256,P as parallelhashxof_128,Y as parallelhashxof_256,a as sha3_224,o as sha3_256,s as sha3_384,u as sha3_512,_ as shake128,g as shake256,b as shake_128,v as shake_256,J as tuplehash128,j as tuplehash256,I as tuplehash_128,R as tuplehash_256,U as tuplehashxof128,D as tuplehashxof256,H as tuplehashxof_128,F as tuplehashxof_256};