diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e50f48..571ba65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## v0.14.0 / 2026-11-08 +### Fixed +- Wrong digest for strings whose last UTF-8 character crosses a block boundary #62 + ## v0.13.0 / 2026-08-07 ### Added - ParallelHash128, ParallelHash256, ParallelHashXOF128, and ParallelHashXOF256 (NIST SP 800-185) diff --git a/bower.json b/bower.json index b9d57a9..a43b374 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "js-sha3", - "version": "0.13.0", + "version": "0.14.0", "main": ["src/sha3.js"], "ignore": [ "samples", diff --git a/build/sha3.min.js b/build/sha3.min.js index ccf471b..6a018be 100644 --- a/build/sha3.min.js +++ b/build/sha3.min.js @@ -1,9 +1,9 @@ /** * [js-sha3]{@link https://github.com/emn178/js-sha3} * - * @version 0.13.0 + * @version 0.14.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2015-2026 * @license MIT */ -!function(){"use strict";function t(t,e,n){this.blocks=[],this.s=[],this.padding=e,this.outputBits=n,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=n>>5,this.extraBytes=(31&n)>>3;for(var r=0;r<50;++r)this.s[r]=0}function e(e,n,r,i){t.call(this,e,n,r),this.xof=i}function n(t,n,r,i){e.call(this,t,n,r,i),this.inputActive=!1,this.inputBytesRemaining=0}function r(t,n,r,i,o){e.call(this,t,n,r,i),this.bits=t,this.blockSize=o,this.inner=null,this.innerBytes=0,this.blockNumber=0}var i="input is invalid type",o="finalize already called",a="tuple input is incomplete",u="object"==typeof window,s=u?window:{};s.JS_SHA3_NO_WINDOW&&(u=!1);var h=!u&&"object"==typeof self;!s.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?s=global:h&&(s=self);for(var f=!s.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,c="function"==typeof define&&define.amd,p=!s.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),d=[31,7936,2031616,520093696],y=[4,1024,262144,67108864],b=[0,8,16,24],v=[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],g=[224,256,384,512],w=[128,256],B=["hex","buffer","arrayBuffer","array","digest"],A={128:168,256:136},k=s.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,_=!p||!s.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},m=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(i);if(p&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!k(t)&&!_(t))throw new Error(i);return[t,!1]},x=function(t){return 0===m(t)[0].length},C=function(t){for(var e=[],n=0;n268435455)throw new Error("block size is invalid");var s=new r(t,e,a,n,o).bytepad(["ParallelHash",u],i);return s.encode(o,!1),s},o.update=function(t,e,n,r){return o.create(e,n,r).update(t)},I(o,function(t,e,r){return O(t,0,n,r)},t,e)},F=[{name:"keccak",padding:[1,256,65536,16777216],bits:g,createMethod:R},{name:"sha3",padding:[6,1536,393216,100663296],bits:g,createMethod:R},{name:"shake",padding:d,bits:w,createMethod:function(e,n){var r=z(e,n,"hex");return r.create=function(r){return new t(e,n,r)},r.update=function(t,e){return r.create(e).update(t)},I(r,z,e,n)}},{name:"cshake",padding:y,bits:w,createMethod:function(e,n){var r=A[e],i=M(e,0,"hex");return i.create=function(i,o,a){return x(o)&&x(a)?U["shake"+e].create(i):new t(e,n,i).bytepad([o,a],r)},i.update=function(t,e,n,r){return i.create(e,n,r).update(t)},I(i,M,e,n)}},{name:"kmac",padding:y,bits:w,createMethod:function(t,e){return J(t,e,!1)}},{name:"kmacxof",padding:y,bits:w,createMethod:function(t,e){return J(t,e,!0)}},{name:"tuplehash",padding:y,bits:w,createMethod:function(t,e){return j(t,e,!1)}},{name:"tuplehashxof",padding:y,bits:w,createMethod:function(t,e){return j(t,e,!0)}},{name:"parallelhash",padding:y,bits:w,createMethod:function(t,e){return H(t,e,!1)}},{name:"parallelhashxof",padding:y,bits:w,createMethod:function(t,e){return H(t,e,!0)}}],U={},D=[],L=0;L>2]|=r<>2]|=(192|r>>6)<>2]|=(128|63&r)<=57344?(a[n>>2]|=(224|r>>12)<>2]|=(128|r>>6&63)<>2]|=(128|63&r)<>2]|=(240|r>>18)<>2]|=(128|r>>12&63)<>2]|=(128|r>>6&63)<>2]|=(128|63&r)<>2]|=t[f]<=u){for(this.start=n-u,this.block=a[h],n=0;n>=8);r>0;)o.unshift(r),r=255&(e>>=8),++i;return n?o.push(i):o.unshift(i),t.prototype.update.call(this,o),o.length},t.prototype.encodeString=function(e){var n=m(e);e=n[0];var r=n[1],i=0,o=e.length;if(r)for(var a=0;a=57344?i+=3:(u=65536+((1023&u)<<10|1023&e.charCodeAt(++a)),i+=4)}else i=o;return i+=this.encode(8*i),t.prototype.update.call(this,e),i},t.prototype.bytepad=function(e,n){for(var r=this.encode(n),i=0;i>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[n],e=1;e>4&15]+l[15&t]+l[t>>12&15]+l[t>>8&15]+l[t>>20&15]+l[t>>16&15]+l[t>>28&15]+l[t>>24&15];a%e==0&&(n=C(n),T(n),o=0)}return i&&(t=n[o],u+=l[t>>4&15]+l[15&t],i>1&&(u+=l[t>>12&15]+l[t>>8&15]),i>2&&(u+=l[t>>20&15]+l[t>>16&15])),u},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,o=0,a=0,u=this.outputBits>>3;t=i?new ArrayBuffer(r+1<<2):new ArrayBuffer(u);for(var s=new Uint32Array(t);a>8&255,s[t+2]=e>>16&255,s[t+3]=e>>24&255;u%n==0&&(r=C(r),T(r))}return o&&(t=u<<2,e=r[a],s[t]=255&e,o>1&&(s[t+1]=e>>8&255),o>2&&(s[t+2]=e>>16&255)),s},(e.prototype=new t).finalize=function(){return this.finalized||this.encode(this.xof?0:this.outputBits,!0),t.prototype.finalize.call(this)},(n.prototype=new e).getMessageByteLength=function(t){var e=m(t);if(t=e[0],!e[1])return t.length;for(var n=0,r=0;r=57344?n+=3:(++r,n+=4)}return n},n.prototype.beginInput=function(t){if(this.inputActive)throw new Error(a);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},n.prototype._updateChunk=function(t,n){return e.prototype.update.call(this,t),this.inputBytesRemaining-=n,0===this.inputBytesRemaining&&(this.inputActive=!1),this},n.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)},n.prototype.update=function(t){var e=this.getMessageByteLength(t);return this.beginInput(e),this._updateChunk(t,e)},n.prototype.finalize=function(){if(this.inputActive)throw new Error(a);return e.prototype.finalize.call(this)},(r.prototype=new e)._finishInner=function(){e.prototype.update.call(this,this.inner.array()),this.inner=null,this.innerBytes=0,++this.blockNumber},r.prototype._updateBytes=function(e){var n=e.length;if(n)for(var r=e.subarray||e.slice,i=this.blockSize,o=0;o>>6,i[u++]=128|63&n):n<55296||n>=57344?(i[u++]=224|n>>>12,i[u++]=128|n>>>6&63,i[u++]=128|63&n):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++r)),i[u++]=240|n>>>18,i[u++]=128|n>>>12&63,i[u++]=128|n>>>6&63,i[u++]=128|63&n);t=i}return this._updateBytes(t),this},r.prototype.finalize=function(){return this.finalized||(this.inner&&this._finishInner(),this.encode(this.blockNumber,!0)),e.prototype.finalize.call(this)};var T=function(t){var e,n,r,i,o,a,u,s,h,f,c,p,l,d,y,b,g,w,B,A,k,_,m,x,C,S,z,M,E,N,O,I,R,J,j,H,F,U,D,L,V,W,Y,K,P,T,q,G,Q,X,Z,$,tt,et,nt,rt,it,ot,at,ut,st,ht,ft;for(r=0;r<48;r+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],o=t[1]^t[11]^t[21]^t[31]^t[41],a=t[2]^t[12]^t[22]^t[32]^t[42],u=t[3]^t[13]^t[23]^t[33]^t[43],s=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])^(a<<1|u>>>31),n=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(u<<1|a>>>31),t[0]^=e,t[1]^=n,t[10]^=e,t[11]^=n,t[20]^=e,t[21]^=n,t[30]^=e,t[31]^=n,t[40]^=e,t[41]^=n,e=i^(s<<1|h>>>31),n=o^(h<<1|s>>>31),t[2]^=e,t[3]^=n,t[12]^=e,t[13]^=n,t[22]^=e,t[23]^=n,t[32]^=e,t[33]^=n,t[42]^=e,t[43]^=n,e=a^(f<<1|c>>>31),n=u^(c<<1|f>>>31),t[4]^=e,t[5]^=n,t[14]^=e,t[15]^=n,t[24]^=e,t[25]^=n,t[34]^=e,t[35]^=n,t[44]^=e,t[45]^=n,e=s^(p<<1|l>>>31),n=h^(l<<1|p>>>31),t[6]^=e,t[7]^=n,t[16]^=e,t[17]^=n,t[26]^=e,t[27]^=n,t[36]^=e,t[37]^=n,t[46]^=e,t[47]^=n,e=f^(i<<1|o>>>31),n=c^(o<<1|i>>>31),t[8]^=e,t[9]^=n,t[18]^=e,t[19]^=n,t[28]^=e,t[29]^=n,t[38]^=e,t[39]^=n,t[48]^=e,t[49]^=n,d=t[0],y=t[1],T=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,ut=t[31]<<9|t[30]>>>23,st=t[30]<<9|t[31]>>>23,W=t[40]<<18|t[41]>>>14,Y=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,g=t[12]<<12|t[13]>>>20,G=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,N=t[33]<<13|t[32]>>>19,O=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,nt=t[4]<<30|t[5]>>>2,H=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,B=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,x=t[6]<<28|t[7]>>>4,C=t[7]<<28|t[6]>>>4,rt=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,A=t[36]<<21|t[37]>>>11,k=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,K=t[8]<<27|t[9]>>>5,P=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,z=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,at=t[28]<<7|t[29]>>>25,L=t[38]<<8|t[39]>>>24,V=t[39]<<8|t[38]>>>24,_=t[48]<<14|t[49]>>>18,m=t[49]<<14|t[48]>>>18,t[0]=d^~b&w,t[1]=y^~g&B,t[10]=x^~S&M,t[11]=C^~z&E,t[20]=J^~H&U,t[21]=j^~F&D,t[30]=K^~T&G,t[31]=P^~q&Q,t[40]=et^~rt&ot,t[41]=nt^~it&at,t[2]=b^~w&A,t[3]=g^~B&k,t[12]=S^~M&N,t[13]=z^~E&O,t[22]=H^~U&L,t[23]=F^~D&V,t[32]=T^~G&X,t[33]=q^~Q&Z,t[42]=rt^~ot&ut,t[43]=it^~at&st,t[4]=w^~A&_,t[5]=B^~k&m,t[14]=M^~N&I,t[15]=E^~O&R,t[24]=U^~L&W,t[25]=D^~V&Y,t[34]=G^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~ut&ht,t[45]=at^~st&ft,t[6]=A^~_&d,t[7]=k^~m&y,t[16]=N^~I&x,t[17]=O^~R&C,t[26]=L^~W&J,t[27]=V^~Y&j,t[36]=X^~$&K,t[37]=Z^~tt&P,t[46]=ut^~ht&et,t[47]=st^~ft&nt,t[8]=_^~d&b,t[9]=m^~y&g,t[18]=I^~x&S,t[19]=R^~C&z,t[28]=W^~J&H,t[29]=Y^~j&F,t[38]=$^~K&T,t[39]=tt^~P&q,t[48]=ht^~et&rt,t[49]=ft^~nt&it,t[0]^=v[r],t[1]^=v[r+1]};if(f)module.exports=U;else{for(L=0;L>5,this.byteCount=this.blockCount<<2,this.outputBlocks=n>>5,this.extraBytes=(31&n)>>3;for(var r=0;r<50;++r)this.s[r]=0}function e(e,n,r,i){t.call(this,e,n,r),this.xof=i}function n(t,n,r,i){e.call(this,t,n,r,i),this.inputActive=!1,this.inputBytesRemaining=0}function r(t,n,r,i,o){e.call(this,t,n,r,i),this.bits=t,this.blockSize=o,this.inner=null,this.innerBytes=0,this.blockNumber=0}var i="input is invalid type",o="finalize already called",a="tuple input is incomplete",u="object"==typeof window,s=u?window:{};s.JS_SHA3_NO_WINDOW&&(u=!1);var h=!u&&"object"==typeof self;!s.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?s=global:h&&(s=self);for(var f=!s.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,c="function"==typeof define&&define.amd,p=!s.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),d=[31,7936,2031616,520093696],y=[4,1024,262144,67108864],b=[0,8,16,24],v=[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],g=[224,256,384,512],w=[128,256],B=["hex","buffer","arrayBuffer","array","digest"],A={128:168,256:136},k=s.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,_=!p||!s.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},m=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(i);if(p&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!k(t)&&!_(t))throw new Error(i);return[t,!1]},x=function(t){return 0===m(t)[0].length},C=function(t){for(var e=[],n=0;n268435455)throw new Error("block size is invalid");var s=new r(t,e,a,n,o).bytepad(["ParallelHash",u],i);return s.encode(o,!1),s},o.update=function(t,e,n,r){return o.create(e,n,r).update(t)},I(o,function(t,e,r){return O(t,0,n,r)},t,e)},F=[{name:"keccak",padding:[1,256,65536,16777216],bits:g,createMethod:R},{name:"sha3",padding:[6,1536,393216,100663296],bits:g,createMethod:R},{name:"shake",padding:d,bits:w,createMethod:function(e,n){var r=z(e,n,"hex");return r.create=function(r){return new t(e,n,r)},r.update=function(t,e){return r.create(e).update(t)},I(r,z,e,n)}},{name:"cshake",padding:y,bits:w,createMethod:function(e,n){var r=A[e],i=M(e,0,"hex");return i.create=function(i,o,a){return x(o)&&x(a)?U["shake"+e].create(i):new t(e,n,i).bytepad([o,a],r)},i.update=function(t,e,n,r){return i.create(e,n,r).update(t)},I(i,M,e,n)}},{name:"kmac",padding:y,bits:w,createMethod:function(t,e){return J(t,e,!1)}},{name:"kmacxof",padding:y,bits:w,createMethod:function(t,e){return J(t,e,!0)}},{name:"tuplehash",padding:y,bits:w,createMethod:function(t,e){return j(t,e,!1)}},{name:"tuplehashxof",padding:y,bits:w,createMethod:function(t,e){return j(t,e,!0)}},{name:"parallelhash",padding:y,bits:w,createMethod:function(t,e){return H(t,e,!1)}},{name:"parallelhashxof",padding:y,bits:w,createMethod:function(t,e){return H(t,e,!0)}}],U={},D=[],L=0;L>2]|=r<>2]|=(192|r>>6)<>2]|=(128|63&r)<=57344?(a[n>>2]|=(224|r>>12)<>2]|=(128|r>>6&63)<>2]|=(128|63&r)<>2]|=(240|r>>18)<>2]|=(128|r>>12&63)<>2]|=(128|r>>6&63)<>2]|=(128|63&r)<>2]|=t[f]<=u){for(this.start=n-u,this.block=a[h],n=0;n>=8);r>0;)o.unshift(r),r=255&(e>>=8),++i;return n?o.push(i):o.unshift(i),t.prototype.update.call(this,o),o.length},t.prototype.encodeString=function(e){var n=m(e);e=n[0];var r=n[1],i=0,o=e.length;if(r)for(var a=0;a=57344?i+=3:(u=65536+((1023&u)<<10|1023&e.charCodeAt(++a)),i+=4)}else i=o;return i+=this.encode(8*i),t.prototype.update.call(this,e),i},t.prototype.bytepad=function(e,n){for(var r=this.encode(n),i=0;i>2]|=this.padding[3&e],this.lastByteIndex>=this.byteCount)for(t[0]=t[n],e=1;e>4&15]+l[15&t]+l[t>>12&15]+l[t>>8&15]+l[t>>20&15]+l[t>>16&15]+l[t>>28&15]+l[t>>24&15];a%e==0&&(n=C(n),T(n),o=0)}return i&&(t=n[o],u+=l[t>>4&15]+l[15&t],i>1&&(u+=l[t>>12&15]+l[t>>8&15]),i>2&&(u+=l[t>>20&15]+l[t>>16&15])),u},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,o=0,a=0,u=this.outputBits>>3;t=i?new ArrayBuffer(r+1<<2):new ArrayBuffer(u);for(var s=new Uint32Array(t);a>8&255,s[t+2]=e>>16&255,s[t+3]=e>>24&255;u%n==0&&(r=C(r),T(r))}return o&&(t=u<<2,e=r[a],s[t]=255&e,o>1&&(s[t+1]=e>>8&255),o>2&&(s[t+2]=e>>16&255)),s},(e.prototype=new t).finalize=function(){return this.finalized||this.encode(this.xof?0:this.outputBits,!0),t.prototype.finalize.call(this)},(n.prototype=new e).getMessageByteLength=function(t){var e=m(t);if(t=e[0],!e[1])return t.length;for(var n=0,r=0;r=57344?n+=3:(++r,n+=4)}return n},n.prototype.beginInput=function(t){if(this.inputActive)throw new Error(a);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},n.prototype._updateChunk=function(t,n){return e.prototype.update.call(this,t),this.inputBytesRemaining-=n,0===this.inputBytesRemaining&&(this.inputActive=!1),this},n.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)},n.prototype.update=function(t){var e=this.getMessageByteLength(t);return this.beginInput(e),this._updateChunk(t,e)},n.prototype.finalize=function(){if(this.inputActive)throw new Error(a);return e.prototype.finalize.call(this)},(r.prototype=new e)._finishInner=function(){e.prototype.update.call(this,this.inner.array()),this.inner=null,this.innerBytes=0,++this.blockNumber},r.prototype._updateBytes=function(e){var n=e.length;if(n)for(var r=e.subarray||e.slice,i=this.blockSize,o=0;o>>6,i[u++]=128|63&n):n<55296||n>=57344?(i[u++]=224|n>>>12,i[u++]=128|n>>>6&63,i[u++]=128|63&n):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++r)),i[u++]=240|n>>>18,i[u++]=128|n>>>12&63,i[u++]=128|n>>>6&63,i[u++]=128|63&n);t=i}return this._updateBytes(t),this},r.prototype.finalize=function(){return this.finalized||(this.inner&&this._finishInner(),this.encode(this.blockNumber,!0)),e.prototype.finalize.call(this)};var T=function(t){var e,n,r,i,o,a,u,s,h,f,c,p,l,d,y,b,g,w,B,A,k,_,m,x,C,S,z,M,E,N,O,I,R,J,j,H,F,U,D,L,V,W,Y,K,P,T,q,G,Q,X,Z,$,tt,et,nt,rt,it,ot,at,ut,st,ht,ft;for(r=0;r<48;r+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],o=t[1]^t[11]^t[21]^t[31]^t[41],a=t[2]^t[12]^t[22]^t[32]^t[42],u=t[3]^t[13]^t[23]^t[33]^t[43],s=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])^(a<<1|u>>>31),n=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(u<<1|a>>>31),t[0]^=e,t[1]^=n,t[10]^=e,t[11]^=n,t[20]^=e,t[21]^=n,t[30]^=e,t[31]^=n,t[40]^=e,t[41]^=n,e=i^(s<<1|h>>>31),n=o^(h<<1|s>>>31),t[2]^=e,t[3]^=n,t[12]^=e,t[13]^=n,t[22]^=e,t[23]^=n,t[32]^=e,t[33]^=n,t[42]^=e,t[43]^=n,e=a^(f<<1|c>>>31),n=u^(c<<1|f>>>31),t[4]^=e,t[5]^=n,t[14]^=e,t[15]^=n,t[24]^=e,t[25]^=n,t[34]^=e,t[35]^=n,t[44]^=e,t[45]^=n,e=s^(p<<1|l>>>31),n=h^(l<<1|p>>>31),t[6]^=e,t[7]^=n,t[16]^=e,t[17]^=n,t[26]^=e,t[27]^=n,t[36]^=e,t[37]^=n,t[46]^=e,t[47]^=n,e=f^(i<<1|o>>>31),n=c^(o<<1|i>>>31),t[8]^=e,t[9]^=n,t[18]^=e,t[19]^=n,t[28]^=e,t[29]^=n,t[38]^=e,t[39]^=n,t[48]^=e,t[49]^=n,d=t[0],y=t[1],T=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,ut=t[31]<<9|t[30]>>>23,st=t[30]<<9|t[31]>>>23,W=t[40]<<18|t[41]>>>14,Y=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,g=t[12]<<12|t[13]>>>20,G=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,N=t[33]<<13|t[32]>>>19,O=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,nt=t[4]<<30|t[5]>>>2,H=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,B=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,x=t[6]<<28|t[7]>>>4,C=t[7]<<28|t[6]>>>4,rt=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,A=t[36]<<21|t[37]>>>11,k=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,K=t[8]<<27|t[9]>>>5,P=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,z=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,at=t[28]<<7|t[29]>>>25,L=t[38]<<8|t[39]>>>24,V=t[39]<<8|t[38]>>>24,_=t[48]<<14|t[49]>>>18,m=t[49]<<14|t[48]>>>18,t[0]=d^~b&w,t[1]=y^~g&B,t[10]=x^~S&M,t[11]=C^~z&E,t[20]=J^~H&U,t[21]=j^~F&D,t[30]=K^~T&G,t[31]=P^~q&Q,t[40]=et^~rt&ot,t[41]=nt^~it&at,t[2]=b^~w&A,t[3]=g^~B&k,t[12]=S^~M&N,t[13]=z^~E&O,t[22]=H^~U&L,t[23]=F^~D&V,t[32]=T^~G&X,t[33]=q^~Q&Z,t[42]=rt^~ot&ut,t[43]=it^~at&st,t[4]=w^~A&_,t[5]=B^~k&m,t[14]=M^~N&I,t[15]=E^~O&R,t[24]=U^~L&W,t[25]=D^~V&Y,t[34]=G^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~ut&ht,t[45]=at^~st&ft,t[6]=A^~_&d,t[7]=k^~m&y,t[16]=N^~I&x,t[17]=O^~R&C,t[26]=L^~W&J,t[27]=V^~Y&j,t[36]=X^~$&K,t[37]=Z^~tt&P,t[46]=ut^~ht&et,t[47]=st^~ft&nt,t[8]=_^~d&b,t[9]=m^~y&g,t[18]=I^~x&S,t[19]=R^~C&z,t[28]=W^~J&H,t[29]=Y^~j&F,t[38]=$^~K&T,t[39]=tt^~P&q,t[48]=ht^~et&rt,t[49]=ft^~nt&it,t[0]^=v[r],t[1]^=v[r+1]};if(f)module.exports=U;else{for(L=0;L268435455)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>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>2]|=i<>2]|=(192|i>>6)<>2]|=(128|63&i)<=57344?(o[r>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=t[f]<=s){for(this.start=r-s,this.block=o[h],r=0;r>=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=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>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e>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>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=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>>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;F268435455)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>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>2]|=i<>2]|=(192|i>>6)<>2]|=(128|63&i)<=57344?(o[r>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=t[f]<=s){for(this.start=r-s,this.block=o[h],r=0;r>=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=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>2]|=this.padding[3&e],this.lastByteIndex>=this.byteCount)for(t[0]=t[r],e=1;e>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>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=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>>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> 2] |= this.padding[i & 3]; - if (this.lastByteIndex === this.byteCount) { + if (this.lastByteIndex >= this.byteCount) { blocks[0] = blocks[blockCount]; for (i = 1; i < blockCount + 1; ++i) { blocks[i] = 0; diff --git a/package-lock.json b/package-lock.json index 2da74fb..b44e1b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "js-sha3", - "version": "0.13.0", + "version": "0.14.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "js-sha3", - "version": "0.13.0", + "version": "0.14.0", "license": "MIT", "devDependencies": { "@rollup/plugin-commonjs": "^28.0.5", diff --git a/package.json b/package.json index 681d826..c5b5099 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-sha3", - "version": "0.13.0", + "version": "0.14.0", "description": "A simple SHA-3 / Keccak / SHAKE / cSHAKE / KMAC / TupleHash / ParallelHash hash function for JavaScript supports UTF-8 encoding.", "main": "src/sha3.js", "module": "build/sha3.mjs", diff --git a/src/sha3.js b/src/sha3.js index 7cf1b25..6ffaf95 100644 --- a/src/sha3.js +++ b/src/sha3.js @@ -1,7 +1,7 @@ /** * [js-sha3]{@link https://github.com/emn178/js-sha3} * - * @version 0.13.0 + * @version 0.14.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2015-2026 * @license MIT @@ -417,7 +417,7 @@ this.finalized = true; var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s; blocks[i >> 2] |= this.padding[i & 3]; - if (this.lastByteIndex === this.byteCount) { + if (this.lastByteIndex >= this.byteCount) { blocks[0] = blocks[blockCount]; for (i = 1; i < blockCount + 1; ++i) { blocks[i] = 0; diff --git a/tests/test.js b/tests/test.js index 885365a..c6f62e5 100644 --- a/tests/test.js +++ b/tests/test.js @@ -24,6 +24,10 @@ '35dfaf82d2ce4be79393dc90e327b4dd15b1c150d8a30f59d8d1b42ca4fc3c87f50b77da36acccf9dc76494d07fc57cfcc9470e627c38f95bce4deab311b87e0': 'aécio', '33ef254289f36527c93cd203ef1973aec1eff7475c23fa842c3092b0d30965d13b0805c61d0aa92c51245c56bfe26978c35c00f26eb558a043982043ee8b178c': '𠜎' }, + 'UTF-8 crossing block boundary': { + '639bc16dfb4baf0e8b32ec1c0e6ae0904a780cf68bb922f503cf96c3eded9ea096a3ae7c0f4addfbf37caf8cc2769cd10a496f5711855abf61d0286b3052e498': Array(72).join('a') + 'é', + '6d2a97560295a71d222a59af1b745d2d0e6bf0d776fd3c3e2073ad88a0c60e57b4eedf3f4cd26e36e967343bad190074bd2b5ed1ad2312ee68a2ef773cf94697': Array(72).join('a') + '𠜎' + }, 'UTF-8 more than 128 bytes': { 'accb127bb24b0ffbb7550dc637222d2f78538a8a186c98bc5efdad685b9b396639f34148bf0b94ed470f0e9c3665dc3b4c1cb321bacd32dd317a646295e073d9': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', '5b70eaad083f1b86fd535b6812e02f5f2876a4bd8b43aede8d62ae71bb1743ebd919dc41be56d73ba45b67b2876ff215d0575788560e7b0c92b879f8a2fc3111': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。' @@ -51,6 +55,10 @@ '70b447f1bd5ce5a4753ccf7a3697eca0315954774374bc1042aff19582ccc32d5067f7da6c2bea9d6d344e11924cbe72': 'aécio', '7add8d544b0a7cf188b54b1697a046f77e49d5f292e7ffe56feeed90a500b0bf026b9b68892888a1bafb9f8cb89ed874': '𠜎' }, + 'UTF-8 crossing block boundary': { + '2adacd2e5baa621c6e2b34105246d27f70432668be218b90d8c05a71e128f1c7e01cf9f622274114f31a0ac9bc874a51': Array(104).join('a') + 'é', + '44ae4704e24fc0b8eb245df40b822016aa9762a0e72626da760010c3b5d8e8d210c86aa6a925a990a02608ea10d3210c': Array(104).join('a') + '𠜎' + }, 'UTF-8 more than 128 bytes': { '7d0f80fe5c79a04a2a37a30a440e0cc068eb78fe6c3182246ede29645c144b5d33c44607cb2c3111ba77ffc66107f1cd': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', 'e344b95c6a961a27793eff00fa5103ef78b4180fe41c93fc60a31aff49b3b5e95a92c84fda9a6c80fa403b7df58db59f': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。' @@ -70,6 +78,10 @@ '65c756408eb6c35a1ffa2d7e09711bdc9f0b28716b1376223844a2b4c52b6718': 'aécio', 'babe9afc555b0311700dfb0b5b6296d49347b3d770480baedfcdc47a4aea6e82': '𠜎' }, + 'UTF-8 crossing block boundary': { + 'be0c47012a6b606f80c1a0d1b61d07d001b210234be8dd47e6cbc094160432dd': Array(136).join('a') + 'é', + 'a3e416e00eb9a844202cda999bde4a5af531ebe428796e4d56762d49877eb9dd': Array(136).join('a') + '𠜎' + }, 'UTF-8 more than 128 bytes': { '4b2f36e4320b86e6ead0ad001e47e6d9e7fcf0044cd5a5fd65490a633c0372a4': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', '558a7f843b1ac5e7a8bbef90357876bcce0612992d0dfa2907e95521612f507f': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。' @@ -89,6 +101,10 @@ 'b16bad54608dc01864a5d7510d4c19b09f3a0f39cfc4ba1e53aa952a': 'aécio', 'f59253c41cb87e5cd953311656716cb5b64dbafc9e8155f0dd68123c': '𠜎' }, + 'UTF-8 crossing block boundary': { + 'b5e1dd79fbbf42a1831f55f15eb4a945b3a40fb8e382ddffb00dd2c5': Array(144).join('a') + 'é', + '95ef8807f0c48a6d5209eadb4250ac0fbbf1c9a7a4b19195e200b901': Array(144).join('a') + '𠜎' + }, 'UTF-8 more than 128 bytes': { '135c13deb71fdf6fb77b52b720c43ddd6ce7467f9147a74248557114': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', 'bd05581e02445c53e05aad2014f6a3819d77a9dff918b8c6bf60bd06': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。' @@ -108,6 +124,10 @@ 'c452ec93e83d4795fcab62a76eed0d88f2231a995ce108ac8f130246f87c4a11cb18a2c1a688a5695906a6f863e71bbe8997c6610319ab97f12d2e5bf0afe458': 'aécio', '8a2d72022ce19d989dbe6a0017faccbf5dc2e22c162d1c5eb168864d32dd1a71e1b4782652c148cf6ca47b77a72c96fff682e72bdfef0566d4b7cca3c9ccc59d': '𠜎' }, + 'UTF-8 crossing block boundary': { + '99e3f901f7b8f09cd99ed422fcdd2a999598a8ab9c32730b9d99b442242fdcd2974618735777f57b8973f329e170487eb56c0c17524bea7a720edabde7b1e020': Array(72).join('a') + 'é', + '0aa818b80fc628c435cb9f90975e40573e7e5f9efb7101c90c982ade2daa3ac324b235e2065af8702353d99dcec1627248e2519d246d196246f5ff1f538878a6': Array(72).join('a') + '𠜎' + }, 'UTF-8 more than 128 bytes': { '6a67c28aa1946ca1be8382b861aac4aaf20052f495db9b6902d13adfa603eaba5d169f8896b86d461b2949283eb98e503c3f0640188ea7d6731526fc06568d37': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', 'd04ff5b0e85e9968be2a4d4e133c15c7ccee7497198bb651599a97d11d00bca6048d329ab75aa454566cd532648fa1cb4551985d9d645de9fa43a311a9ee8e4d': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。' @@ -127,6 +147,10 @@ '08990555e131af8597687614309da4c5053ce866f348544da0a0c2c78c2cc79680ebb57cfbe238286e78ea133a037897': 'aécio', '2a80f59abf3111f38a35a3daa25123b495f90e9736bd300e35911d19abdd8806498c581333f198ccbbf2252b57c2925d': '𠜎' }, + 'UTF-8 crossing block boundary': { + 'ca105aaf06261204de3b068a2fd2d8587ac8267417a41490e6ee8aa81453e89e8bb5cc0d1fbe9116c8b50c27dd2428d9': Array(104).join('a') + 'é', + '1712217829147c6acb2bb14ff6bf245e15fb28629a5b68b7aead07c48a87ab5c2bbcfc9b06d31a594d848e76247801cf': Array(104).join('a') + '𠜎' + }, 'UTF-8 more than 128 bytes': { 'a3b043a2f69e4326a05d478fa4c8aa2bd7612453d775af37665a0b96ef2207cdc74c50cdba1629796a5136fe77300b05': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', '66414c090cc3fe9c396d313cbaa100aefd335e851838b29382568b7f57357ada7c54b8fa8c17f859945bba88b2c2e332': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。' @@ -146,6 +170,10 @@ 'd7d569202f04daf90432810d6163112b2695d7820da979327ebd894efb0276dc': 'aécio', '16a7cc7a58444cbf7e939611910ddc82e7cba65a99d3e8e08cfcda53180a2180': '𠜎' }, + 'UTF-8 crossing block boundary': { + '520699913aab3b7e02e624bdcff04e2830be50cd244a41e04bf8f22de65f90c4': Array(136).join('a') + 'é', + 'ac7e0a188a9129385e9f8de8d975193c602b8505c4081a182d6c41a1b9b0092e': Array(136).join('a') + '𠜎' + }, 'UTF-8 more than 128 bytes': { 'd1021d2d4c5c7e88098c40f422af68493b4b64c913cbd68220bf5e6127c37a88': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', 'ffabf9bba2127c4928d360c9905cb4911f0ec21b9c3b89f3b242bccc68389e36': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。' @@ -165,6 +193,10 @@ '66f3db76bf8cb35726cb278bac412d187c3484ab2083dc50ef5ffb55': 'aécio', '3bfa94845726f4cd5cf17d19b5eacac17b3694790e13a76d5c81c7c2': '𠜎' }, + 'UTF-8 crossing block boundary': { + 'bc835bf25312b764f5ac035058d7cd4f0e46fed1b207872156ada8b6': Array(144).join('a') + 'é', + '83ca71f6261c89d3458ceeb65f8593aa26542b33cfade266d1806769': Array(144).join('a') + '𠜎' + }, 'UTF-8 more than 128 bytes': { 'd59eef8f394ef7d96967bb0bde578785c033f7f0a21913d6ba41ed1b': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一', '27123a2a3860d1041d4769778c4b078732bf4300f7e1c56536ab2644': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。'