js-sha3 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/build/sha3.min.js +2 -2
- package/build/sha3.min.mjs +9 -0
- package/build/sha3.mjs +702 -0
- package/package.json +21 -3
- package/rollup.config.mjs +23 -0
- package/src/sha3.js +13 -2
- package/src/sha3.mjs +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## v0.10.0 / 2026-07-17
|
|
4
|
+
### Added
|
|
5
|
+
- support ESM #42, #38
|
|
6
|
+
- types index.d.ts to package.json #32
|
|
7
|
+
|
|
8
|
+
## v0.9.3 / 2023-12-16
|
|
9
|
+
### Fixed
|
|
10
|
+
- Fix error in arrayBuffer when there are extra bytes #37
|
|
11
|
+
- fixed output if finalized.
|
|
12
|
+
|
|
3
13
|
## v0.9.2 / 2023-09-16
|
|
4
14
|
### Fixed
|
|
5
15
|
- don't modify global Array and ArrayBuffer prototypes. #33
|
package/README.md
CHANGED
package/build/sha3.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
3
|
*
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.10.0
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
6
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
7
7
|
* @license MIT
|
|
8
8
|
*/
|
|
9
|
-
!function(){"use strict";function t(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 e(e,r,n){t.call(this,e,r,n)}var r="input is invalid type",n="object"==typeof window,i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&"object"==typeof self;!i.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?i=global:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,u=!i.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),c=[4,1024,262144,67108864],h=[0,8,16,24],p=[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],d=[224,256,384,512],l=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],b={128:168,256:136},v=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,A=!u||!i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},g=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(r);if(u&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!v(t)&&!A(t))throw new Error(r);return[t,!1]},B=function(t){return 0===g(t)[0].length},_=function(e,r,n){return function(i){return new t(e,r,e).update(i)[n]()}},
|
|
9
|
+
!function(){"use strict";function t(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 e(e,r,n){t.call(this,e,r,n)}var r="input is invalid type",n="object"==typeof window,i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&"object"==typeof self;!i.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?i=global:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,u=!i.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),c=[4,1024,262144,67108864],h=[0,8,16,24],p=[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],d=[224,256,384,512],l=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],b={128:168,256:136},v=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,A=!u||!i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},g=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(r);if(u&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!v(t)&&!A(t))throw new Error(r);return[t,!1]},B=function(t){return 0===g(t)[0].length},_=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},k=function(e,r,n){return function(i){return new t(e,r,e).update(i)[n]()}},w=function(e,r,n){return function(i,o){return new t(e,r,o).update(i)[n]()}},S=function(t,e,r){return function(e,n,i,o){return z["cshake"+t].update(e,n,i,o)[r]()}},C=function(t,e,r){return function(e,n,i,o){return z["kmac"+t].update(e,n,i,o)[r]()}},x=function(t,e,r,n){for(var i=0;i<y.length;++i){var o=y[i];t[o]=e(r,n,o)}return t},m=function(e,r){var n=k(e,r,"hex");return n.create=function(){return new t(e,r,e)},n.update=function(t){return n.create().update(t)},x(n,k,e,r)},O=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:m},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:m},{name:"shake",padding:[31,7936,2031616,520093696],bits:l,createMethod:function(e,r){var n=w(e,r,"hex");return n.create=function(n){return new t(e,r,n)},n.update=function(t,e){return n.create(e).update(t)},x(n,w,e,r)}},{name:"cshake",padding:c,bits:l,createMethod:function(e,r){var n=b[e],i=S(e,0,"hex");return i.create=function(i,o,a){return B(o)&&B(a)?z["shake"+e].create(i):new t(e,r,i).bytepad([o,a],n)},i.update=function(t,e,r,n){return i.create(e,r,n).update(t)},x(i,S,e,r)}},{name:"kmac",padding:c,bits:l,createMethod:function(t,r){var n=b[t],i=C(t,0,"hex");return i.create=function(i,o,a){return new e(t,r,o).bytepad(["KMAC",a],n).bytepad([i],n)},i.update=function(t,e,r,n){return i.create(t,r,n).update(e)},x(i,C,t,r)}}],z={},N=[],J=0;J<O.length;++J)for(var M=O[J],j=M.bits,E=0;E<j.length;++E){var H=M.name+"_"+j[E];if(N.push(H),z[H]=M.createMethod(j[E],M.padding),"sha3"!==M.name){var I=M.name+j[E];N.push(I),z[I]=z[H]}}t.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=g(t);t=e[0];for(var r,n,i=e[1],o=this.blocks,a=this.byteCount,s=t.length,u=this.blockCount,f=0,c=this.s;f<s;){if(this.reset)for(this.reset=!1,o[0]=this.block,r=1;r<u+1;++r)o[r]=0;if(i)for(r=this.start;f<s&&r<a;++f)(n=t.charCodeAt(f))<128?o[r>>2]|=n<<h[3&r++]:n<2048?(o[r>>2]|=(192|n>>6)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]):n<55296||n>=57344?(o[r>>2]|=(224|n>>12)<<h[3&r++],o[r>>2]|=(128|n>>6&63)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++f)),o[r>>2]|=(240|n>>18)<<h[3&r++],o[r>>2]|=(128|n>>12&63)<<h[3&r++],o[r>>2]|=(128|n>>6&63)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]);else for(r=this.start;f<s&&r<a;++f)o[r>>2]|=t[f]<<h[3&r++];if(this.lastByteIndex=r,r>=a){for(this.start=r-a,this.block=o[u],r=0;r<u;++r)c[r]^=o[r];R(c),this.reset=!0}else this.start=r}return this},t.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),this.update(i),i.length},t.prototype.encodeString=function(t){var e=g(t);t=e[0];var r=e[1],n=0,i=t.length;if(r)for(var o=0;o<t.length;++o){var a=t.charCodeAt(o);a<128?n+=1:a<2048?n+=2:a<55296||a>=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++o)),n+=4)}else n=i;return n+=this.encode(8*n),this.update(t),n},t.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,o=[];return o.length=i,this.update(o),this},t.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];R(n)}},t.prototype.toString=t.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,s="";a<n;){for(o=0;o<e&&a<n;++o,++a)t=r[o],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];a%e==0&&(r=_(r),R(r),o=0)}return i&&(t=r[o],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},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,s=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(s);for(var u=new Uint32Array(t);a<n;){for(o=0;o<e&&a<n;++o,++a)u[a]=r[o];a%e==0&&(r=_(r),R(r))}return i&&(u[a]=r[o],t=t.slice(0,s)),t},t.prototype.buffer=t.prototype.arrayBuffer,t.prototype.digest=t.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,i=this.outputBlocks,o=this.extraBytes,a=0,s=0,u=[];s<i;){for(a=0;a<r&&s<i;++a,++s)t=s<<2,e=n[a],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=_(n),R(n))}return o&&(t=s<<2,e=n[a],u[t]=255&e,o>1&&(u[t+1]=e>>8&255),o>2&&(u[t+2]=e>>16&255)),u},(e.prototype=new t).finalize=function(){return this.encode(this.outputBits,!0),t.prototype.finalize.call(this)};var R=function(t){var e,r,n,i,o,a,s,u,f,c,h,d,l,y,b,v,A,g,B,_,k,w,S,C,x,m,O,z,N,J,M,j,E,H,I,R,F,U,D,V,W,Y,K,q,G,L,P,Q,T,X,Z,$,tt,et,rt,nt,it,ot,at,st,ut,ft,ct;for(n=0;n<48;n+=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],s=t[3]^t[13]^t[23]^t[33]^t[43],u=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],h=t[7]^t[17]^t[27]^t[37]^t[47],e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(a<<1|s>>>31),r=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(s<<1|a>>>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|f>>>31),r=o^(f<<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=a^(c<<1|h>>>31),r=s^(h<<1|c>>>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^(d<<1|l>>>31),r=f^(l<<1|d>>>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=c^(i<<1|o>>>31),r=h^(o<<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],b=t[1],L=t[11]<<4|t[10]>>>28,P=t[10]<<4|t[11]>>>28,z=t[20]<<3|t[21]>>>29,N=t[21]<<3|t[20]>>>29,st=t[31]<<9|t[30]>>>23,ut=t[30]<<9|t[31]>>>23,Y=t[40]<<18|t[41]>>>14,K=t[41]<<18|t[40]>>>14,H=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,v=t[13]<<12|t[12]>>>20,A=t[12]<<12|t[13]>>>20,Q=t[22]<<10|t[23]>>>22,T=t[23]<<10|t[22]>>>22,J=t[33]<<13|t[32]>>>19,M=t[32]<<13|t[33]>>>19,ft=t[42]<<2|t[43]>>>30,ct=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,R=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,g=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,j=t[45]<<29|t[44]>>>3,E=t[44]<<29|t[45]>>>3,C=t[6]<<28|t[7]>>>4,x=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,_=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,q=t[8]<<27|t[9]>>>5,G=t[9]<<27|t[8]>>>5,m=t[18]<<20|t[19]>>>12,O=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,at=t[28]<<7|t[29]>>>25,V=t[38]<<8|t[39]>>>24,W=t[39]<<8|t[38]>>>24,w=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=y^~v&g,t[1]=b^~A&B,t[10]=C^~m&z,t[11]=x^~O&N,t[20]=H^~R&U,t[21]=I^~F&D,t[30]=q^~L&Q,t[31]=G^~P&T,t[40]=et^~nt&ot,t[41]=rt^~it&at,t[2]=v^~g&_,t[3]=A^~B&k,t[12]=m^~z&J,t[13]=O^~N&M,t[22]=R^~U&V,t[23]=F^~D&W,t[32]=L^~Q&X,t[33]=P^~T&Z,t[42]=nt^~ot&st,t[43]=it^~at&ut,t[4]=g^~_&w,t[5]=B^~k&S,t[14]=z^~J&j,t[15]=N^~M&E,t[24]=U^~V&Y,t[25]=D^~W&K,t[34]=Q^~X&$,t[35]=T^~Z&tt,t[44]=ot^~st&ft,t[45]=at^~ut&ct,t[6]=_^~w&y,t[7]=k^~S&b,t[16]=J^~j&C,t[17]=M^~E&x,t[26]=V^~Y&H,t[27]=W^~K&I,t[36]=X^~$&q,t[37]=Z^~tt&G,t[46]=st^~ft&et,t[47]=ut^~ct&rt,t[8]=w^~y&v,t[9]=S^~b&A,t[18]=j^~C&m,t[19]=E^~x&O,t[28]=Y^~H&R,t[29]=K^~I&F,t[38]=$^~q&L,t[39]=tt^~G&P,t[48]=ft^~et&nt,t[49]=ct^~rt&it,t[0]^=p[n],t[1]^=p[n+1]};if(a)module.exports=z;else{for(J=0;J<N.length;++J)i[N[J]]=z[N[J]];s&&define(function(){return z})}}();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
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:{}};
|
|
2
|
+
/**
|
|
3
|
+
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
4
|
+
*
|
|
5
|
+
* @version 0.10.0
|
|
6
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
7
|
+
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
8
|
+
* @license MIT
|
|
9
|
+
*/r=n,function(){var e="input is invalid type",n="object"==typeof window,o=n?window:{};o.JS_SHA3_NO_WINDOW&&(n=!1);var i=!n&&"object"==typeof self;!o.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?o=t:i&&(o=self);for(var a=!o.JS_SHA3_NO_COMMON_JS&&r.exports,s=!o.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,u="0123456789abcdef".split(""),f=[4,1024,262144,67108864],c=[0,8,16,24],h=[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],p=[224,256,384,512],d=[128,256],l=["hex","buffer","arrayBuffer","array","digest"],y={128:168,256:136},k=o.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,b=!s||!o.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},_=function(t){var r=typeof t;if("string"===r)return[t,!0];if("object"!==r||null===t)throw new Error(e);if(s&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!k(t)&&!b(t))throw new Error(e);return[t,!1]},v=function(t){return 0===_(t)[0].length},g=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 I(t,e,t).update(n)[r]()}},w=function(t,e,r){return function(n,o){return new I(t,e,o).update(n)[r]()}},B=function(t,e,r){return function(e,n,o,i){return O["cshake"+t].update(e,n,o,i)[r]()}},S=function(t,e,r){return function(e,n,o,i){return O["kmac"+t].update(e,n,o,i)[r]()}},x=function(t,e,r,n){for(var o=0;o<l.length;++o){var i=l[o];t[i]=e(r,n,i)}return t},C=function(t,e){var r=A(t,e,"hex");return r.create=function(){return new I(t,e,t)},r.update=function(t){return r.create().update(t)},x(r,A,t,e)},m=[{name:"keccak",padding:[1,256,65536,16777216],bits:p,createMethod:C},{name:"sha3",padding:[6,1536,393216,100663296],bits:p,createMethod:C},{name:"shake",padding:[31,7936,2031616,520093696],bits:d,createMethod:function(t,e){var r=w(t,e,"hex");return r.create=function(r){return new I(t,e,r)},r.update=function(t,e){return r.create(e).update(t)},x(r,w,t,e)}},{name:"cshake",padding:f,bits:d,createMethod:function(t,e){var r=y[t],n=B(t,0,"hex");return n.create=function(n,o,i){return v(o)&&v(i)?O["shake"+t].create(n):new I(t,e,n).bytepad([o,i],r)},n.update=function(t,e,r,o){return n.create(e,r,o).update(t)},x(n,B,t,e)}},{name:"kmac",padding:f,bits:d,createMethod:function(t,e){var r=y[t],n=S(t,0,"hex");return n.create=function(n,o,i){return new R(t,e,o).bytepad(["KMAC",i],r).bytepad([n],r)},n.update=function(t,e,r,o){return n.create(t,r,o).update(e)},x(n,S,t,e)}}],O={},z=[],M=0;M<m.length;++M)for(var N=m[M],J=N.bits,j=0;j<J.length;++j){var E=N.name+"_"+J[j];if(z.push(E),O[E]=N.createMethod(J[j],N.padding),"sha3"!==N.name){var H=N.name+J[j];z.push(H),O[H]=O[E]}}function I(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 R(t,e,r){I.call(this,t,e,r)}I.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=_(t);t=e[0];for(var r,n,o=e[1],i=this.blocks,a=this.byteCount,s=t.length,u=this.blockCount,f=0,h=this.s;f<s;){if(this.reset)for(this.reset=!1,i[0]=this.block,r=1;r<u+1;++r)i[r]=0;if(o)for(r=this.start;f<s&&r<a;++f)(n=t.charCodeAt(f))<128?i[r>>2]|=n<<c[3&r++]:n<2048?(i[r>>2]|=(192|n>>6)<<c[3&r++],i[r>>2]|=(128|63&n)<<c[3&r++]):n<55296||n>=57344?(i[r>>2]|=(224|n>>12)<<c[3&r++],i[r>>2]|=(128|n>>6&63)<<c[3&r++],i[r>>2]|=(128|63&n)<<c[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++f)),i[r>>2]|=(240|n>>18)<<c[3&r++],i[r>>2]|=(128|n>>12&63)<<c[3&r++],i[r>>2]|=(128|n>>6&63)<<c[3&r++],i[r>>2]|=(128|63&n)<<c[3&r++]);else for(r=this.start;f<s&&r<a;++f)i[r>>2]|=t[f]<<c[3&r++];if(this.lastByteIndex=r,r>=a){for(this.start=r-a,this.block=i[u],r=0;r<u;++r)h[r]^=i[r];F(h),this.reset=!0}else this.start=r}return this},I.prototype.encode=function(t,e){var r=255&t,n=1,o=[r];for(r=255&(t>>=8);r>0;)o.unshift(r),r=255&(t>>=8),++n;return e?o.push(n):o.unshift(n),this.update(o),o.length},I.prototype.encodeString=function(t){var e=_(t);t=e[0];var r=e[1],n=0,o=t.length;if(r)for(var i=0;i<t.length;++i){var a=t.charCodeAt(i);a<128?n+=1:a<2048?n+=2:a<55296||a>=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++i)),n+=4)}else n=o;return n+=this.encode(8*n),this.update(t),n},I.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var o=(e-r%e)%e,i=[];return i.length=o,this.update(i),this},I.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];F(n)}},I.prototype.toString=I.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,o=this.extraBytes,i=0,a=0,s="";a<n;){for(i=0;i<e&&a<n;++i,++a)t=r[i],s+=u[t>>4&15]+u[15&t]+u[t>>12&15]+u[t>>8&15]+u[t>>20&15]+u[t>>16&15]+u[t>>28&15]+u[t>>24&15];a%e===0&&(r=g(r),F(r),i=0)}return o&&(t=r[i],s+=u[t>>4&15]+u[15&t],o>1&&(s+=u[t>>12&15]+u[t>>8&15]),o>2&&(s+=u[t>>20&15]+u[t>>16&15])),s},I.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,o=this.extraBytes,i=0,a=0,s=this.outputBits>>3;t=o?new ArrayBuffer(n+1<<2):new ArrayBuffer(s);for(var u=new Uint32Array(t);a<n;){for(i=0;i<e&&a<n;++i,++a)u[a]=r[i];a%e===0&&(r=g(r),F(r))}return o&&(u[a]=r[i],t=t.slice(0,s)),t},I.prototype.buffer=I.prototype.arrayBuffer,I.prototype.digest=I.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,o=this.outputBlocks,i=this.extraBytes,a=0,s=0,u=[];s<o;){for(a=0;a<r&&s<o;++a,++s)t=s<<2,e=n[a],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=g(n),F(n))}return i&&(t=s<<2,e=n[a],u[t]=255&e,i>1&&(u[t+1]=e>>8&255),i>2&&(u[t+2]=e>>16&255)),u},R.prototype=new I,R.prototype.finalize=function(){return this.encode(this.outputBits,!0),I.prototype.finalize.call(this)};var F=function(t){var e,r,n,o,i,a,s,u,f,c,p,d,l,y,k,b,_,v,g,A,w,B,S,x,C,m,O,z,M,N,J,j,E,H,I,R,F,U,D,V,W,T,Y,K,P,q,G,L,Q,X,Z,$,tt,et,rt,nt,ot,it,at,st,ut,ft,ct;for(n=0;n<48;n+=2)o=t[0]^t[10]^t[20]^t[30]^t[40],i=t[1]^t[11]^t[21]^t[31]^t[41],a=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],f=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],p=t[7]^t[17]^t[27]^t[37]^t[47],e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(a<<1|s>>>31),r=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(s<<1|a>>>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=o^(u<<1|f>>>31),r=i^(f<<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=a^(c<<1|p>>>31),r=s^(p<<1|c>>>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^(d<<1|l>>>31),r=f^(l<<1|d>>>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=c^(o<<1|i>>>31),r=p^(i<<1|o>>>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],q=t[11]<<4|t[10]>>>28,G=t[10]<<4|t[11]>>>28,z=t[20]<<3|t[21]>>>29,M=t[21]<<3|t[20]>>>29,st=t[31]<<9|t[30]>>>23,ut=t[30]<<9|t[31]>>>23,T=t[40]<<18|t[41]>>>14,Y=t[41]<<18|t[40]>>>14,H=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,b=t[13]<<12|t[12]>>>20,_=t[12]<<12|t[13]>>>20,L=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,N=t[33]<<13|t[32]>>>19,J=t[32]<<13|t[33]>>>19,ft=t[42]<<2|t[43]>>>30,ct=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,R=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,v=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,j=t[45]<<29|t[44]>>>3,E=t[44]<<29|t[45]>>>3,x=t[6]<<28|t[7]>>>4,C=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,ot=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,w=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,m=t[18]<<20|t[19]>>>12,O=t[19]<<20|t[18]>>>12,it=t[29]<<7|t[28]>>>25,at=t[28]<<7|t[29]>>>25,V=t[38]<<8|t[39]>>>24,W=t[39]<<8|t[38]>>>24,B=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=y^~b&v,t[1]=k^~_&g,t[10]=x^~m&z,t[11]=C^~O&M,t[20]=H^~R&U,t[21]=I^~F&D,t[30]=K^~q&L,t[31]=P^~G&Q,t[40]=et^~nt&it,t[41]=rt^~ot&at,t[2]=b^~v&A,t[3]=_^~g&w,t[12]=m^~z&N,t[13]=O^~M&J,t[22]=R^~U&V,t[23]=F^~D&W,t[32]=q^~L&X,t[33]=G^~Q&Z,t[42]=nt^~it&st,t[43]=ot^~at&ut,t[4]=v^~A&B,t[5]=g^~w&S,t[14]=z^~N&j,t[15]=M^~J&E,t[24]=U^~V&T,t[25]=D^~W&Y,t[34]=L^~X&$,t[35]=Q^~Z&tt,t[44]=it^~st&ft,t[45]=at^~ut&ct,t[6]=A^~B&y,t[7]=w^~S&k,t[16]=N^~j&x,t[17]=J^~E&C,t[26]=V^~T&H,t[27]=W^~Y&I,t[36]=X^~$&K,t[37]=Z^~tt&P,t[46]=st^~ft&et,t[47]=ut^~ct&rt,t[8]=B^~y&b,t[9]=S^~k&_,t[18]=j^~x&m,t[19]=E^~C&O,t[28]=T^~H&R,t[29]=Y^~I&F,t[38]=$^~K&q,t[39]=tt^~P&G,t[48]=ft^~et&nt,t[49]=ct^~rt&ot,t[0]^=h[n],t[1]^=h[n+1]};if(a)r.exports=O;else for(M=0;M<z.length;++M)o[z[M]]=O[z[M]]}();var o=e(n.exports);const{sha3_224:i,sha3_256:a,sha3_384:s,sha3_512:u,keccak_224:f,keccak_256:c,keccak_384:h,keccak_512:p,keccak224:d,keccak256:l,keccak384:y,keccak512:k,shake_128:b,shake_256:_,shake128:v,shake256:g,cshake_128:A,cshake_256:w,cshake128:B,cshake256:S,kmac_128:x,kmac_256:C,kmac128:m,kmac256:O}=o;export{B as cshake128,S as cshake256,A as cshake_128,w as cshake_256,o as default,d as keccak224,l as keccak256,y as keccak384,k as keccak512,f as keccak_224,c as keccak_256,h as keccak_384,p as keccak_512,m as kmac128,O as kmac256,x as kmac_128,C as kmac_256,i as sha3_224,a as sha3_256,s as sha3_384,u as sha3_512,v as shake128,g as shake256,b as shake_128,_ as shake_256};
|
package/build/sha3.mjs
ADDED
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
2
|
+
|
|
3
|
+
function getDefaultExportFromCjs (x) {
|
|
4
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
var sha3$1 = {exports: {}};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
11
|
+
*
|
|
12
|
+
* @version 0.10.0
|
|
13
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
14
|
+
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
15
|
+
* @license MIT
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
(function (module) {
|
|
19
|
+
/*jslint bitwise: true */
|
|
20
|
+
(function () {
|
|
21
|
+
|
|
22
|
+
var INPUT_ERROR = 'input is invalid type';
|
|
23
|
+
var FINALIZE_ERROR = 'finalize already called';
|
|
24
|
+
var WINDOW = typeof window === 'object';
|
|
25
|
+
var root = WINDOW ? window : {};
|
|
26
|
+
if (root.JS_SHA3_NO_WINDOW) {
|
|
27
|
+
WINDOW = false;
|
|
28
|
+
}
|
|
29
|
+
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
|
30
|
+
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
|
31
|
+
if (NODE_JS) {
|
|
32
|
+
root = commonjsGlobal;
|
|
33
|
+
} else if (WEB_WORKER) {
|
|
34
|
+
root = self;
|
|
35
|
+
}
|
|
36
|
+
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && 'object' === 'object' && module.exports;
|
|
37
|
+
var ARRAY_BUFFER = !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
|
38
|
+
var HEX_CHARS = '0123456789abcdef'.split('');
|
|
39
|
+
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
|
|
40
|
+
var CSHAKE_PADDING = [4, 1024, 262144, 67108864];
|
|
41
|
+
var KECCAK_PADDING = [1, 256, 65536, 16777216];
|
|
42
|
+
var PADDING = [6, 1536, 393216, 100663296];
|
|
43
|
+
var SHIFT = [0, 8, 16, 24];
|
|
44
|
+
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
|
|
45
|
+
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
|
|
46
|
+
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
|
|
47
|
+
2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
|
|
48
|
+
2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
|
|
49
|
+
var BITS = [224, 256, 384, 512];
|
|
50
|
+
var SHAKE_BITS = [128, 256];
|
|
51
|
+
var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array', 'digest'];
|
|
52
|
+
var CSHAKE_BYTEPAD = {
|
|
53
|
+
'128': 168,
|
|
54
|
+
'256': 136
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
var isArray = root.JS_SHA3_NO_NODE_JS || !Array.isArray
|
|
59
|
+
? function (obj) {
|
|
60
|
+
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
61
|
+
}
|
|
62
|
+
: Array.isArray;
|
|
63
|
+
|
|
64
|
+
var isView = (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView))
|
|
65
|
+
? function (obj) {
|
|
66
|
+
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
67
|
+
}
|
|
68
|
+
: ArrayBuffer.isView;
|
|
69
|
+
|
|
70
|
+
// [message: string, isString: bool]
|
|
71
|
+
var formatMessage = function (message) {
|
|
72
|
+
var type = typeof message;
|
|
73
|
+
if (type === 'string') {
|
|
74
|
+
return [message, true];
|
|
75
|
+
}
|
|
76
|
+
if (type !== 'object' || message === null) {
|
|
77
|
+
throw new Error(INPUT_ERROR);
|
|
78
|
+
}
|
|
79
|
+
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
80
|
+
return [new Uint8Array(message), false];
|
|
81
|
+
}
|
|
82
|
+
if (!isArray(message) && !isView(message)) {
|
|
83
|
+
throw new Error(INPUT_ERROR);
|
|
84
|
+
}
|
|
85
|
+
return [message, false];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
var empty = function (message) {
|
|
89
|
+
return formatMessage(message)[0].length === 0;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var cloneArray = function (array) {
|
|
93
|
+
var newArray = [];
|
|
94
|
+
for (var i = 0; i < array.length; ++i) {
|
|
95
|
+
newArray[i] = array[i];
|
|
96
|
+
}
|
|
97
|
+
return newArray;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
var createOutputMethod = function (bits, padding, outputType) {
|
|
101
|
+
return function (message) {
|
|
102
|
+
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var createShakeOutputMethod = function (bits, padding, outputType) {
|
|
107
|
+
return function (message, outputBits) {
|
|
108
|
+
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
var createCshakeOutputMethod = function (bits, padding, outputType) {
|
|
113
|
+
return function (message, outputBits, n, s) {
|
|
114
|
+
return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
var createKmacOutputMethod = function (bits, padding, outputType) {
|
|
119
|
+
return function (key, message, outputBits, s) {
|
|
120
|
+
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
var createOutputMethods = function (method, createMethod, bits, padding) {
|
|
125
|
+
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
126
|
+
var type = OUTPUT_TYPES[i];
|
|
127
|
+
method[type] = createMethod(bits, padding, type);
|
|
128
|
+
}
|
|
129
|
+
return method;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
var createMethod = function (bits, padding) {
|
|
133
|
+
var method = createOutputMethod(bits, padding, 'hex');
|
|
134
|
+
method.create = function () {
|
|
135
|
+
return new Keccak(bits, padding, bits);
|
|
136
|
+
};
|
|
137
|
+
method.update = function (message) {
|
|
138
|
+
return method.create().update(message);
|
|
139
|
+
};
|
|
140
|
+
return createOutputMethods(method, createOutputMethod, bits, padding);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
var createShakeMethod = function (bits, padding) {
|
|
144
|
+
var method = createShakeOutputMethod(bits, padding, 'hex');
|
|
145
|
+
method.create = function (outputBits) {
|
|
146
|
+
return new Keccak(bits, padding, outputBits);
|
|
147
|
+
};
|
|
148
|
+
method.update = function (message, outputBits) {
|
|
149
|
+
return method.create(outputBits).update(message);
|
|
150
|
+
};
|
|
151
|
+
return createOutputMethods(method, createShakeOutputMethod, bits, padding);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
var createCshakeMethod = function (bits, padding) {
|
|
155
|
+
var w = CSHAKE_BYTEPAD[bits];
|
|
156
|
+
var method = createCshakeOutputMethod(bits, padding, 'hex');
|
|
157
|
+
method.create = function (outputBits, n, s) {
|
|
158
|
+
if (empty(n) && empty(s)) {
|
|
159
|
+
return methods['shake' + bits].create(outputBits);
|
|
160
|
+
} else {
|
|
161
|
+
return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
method.update = function (message, outputBits, n, s) {
|
|
165
|
+
return method.create(outputBits, n, s).update(message);
|
|
166
|
+
};
|
|
167
|
+
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
var createKmacMethod = function (bits, padding) {
|
|
171
|
+
var w = CSHAKE_BYTEPAD[bits];
|
|
172
|
+
var method = createKmacOutputMethod(bits, padding, 'hex');
|
|
173
|
+
method.create = function (key, outputBits, s) {
|
|
174
|
+
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
|
175
|
+
};
|
|
176
|
+
method.update = function (key, message, outputBits, s) {
|
|
177
|
+
return method.create(key, outputBits, s).update(message);
|
|
178
|
+
};
|
|
179
|
+
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
var algorithms = [
|
|
183
|
+
{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod },
|
|
184
|
+
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
|
185
|
+
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
|
186
|
+
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
|
187
|
+
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
var methods = {}, methodNames = [];
|
|
191
|
+
|
|
192
|
+
for (var i = 0; i < algorithms.length; ++i) {
|
|
193
|
+
var algorithm = algorithms[i];
|
|
194
|
+
var bits = algorithm.bits;
|
|
195
|
+
for (var j = 0; j < bits.length; ++j) {
|
|
196
|
+
var methodName = algorithm.name + '_' + bits[j];
|
|
197
|
+
methodNames.push(methodName);
|
|
198
|
+
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
|
|
199
|
+
if (algorithm.name !== 'sha3') {
|
|
200
|
+
var newMethodName = algorithm.name + bits[j];
|
|
201
|
+
methodNames.push(newMethodName);
|
|
202
|
+
methods[newMethodName] = methods[methodName];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function Keccak(bits, padding, outputBits) {
|
|
208
|
+
this.blocks = [];
|
|
209
|
+
this.s = [];
|
|
210
|
+
this.padding = padding;
|
|
211
|
+
this.outputBits = outputBits;
|
|
212
|
+
this.reset = true;
|
|
213
|
+
this.finalized = false;
|
|
214
|
+
this.block = 0;
|
|
215
|
+
this.start = 0;
|
|
216
|
+
this.blockCount = (1600 - (bits << 1)) >> 5;
|
|
217
|
+
this.byteCount = this.blockCount << 2;
|
|
218
|
+
this.outputBlocks = outputBits >> 5;
|
|
219
|
+
this.extraBytes = (outputBits & 31) >> 3;
|
|
220
|
+
|
|
221
|
+
for (var i = 0; i < 50; ++i) {
|
|
222
|
+
this.s[i] = 0;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
Keccak.prototype.update = function (message) {
|
|
227
|
+
if (this.finalized) {
|
|
228
|
+
throw new Error(FINALIZE_ERROR);
|
|
229
|
+
}
|
|
230
|
+
var result = formatMessage(message);
|
|
231
|
+
message = result[0];
|
|
232
|
+
var isString = result[1];
|
|
233
|
+
var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
|
|
234
|
+
blockCount = this.blockCount, index = 0, s = this.s, i, code;
|
|
235
|
+
|
|
236
|
+
while (index < length) {
|
|
237
|
+
if (this.reset) {
|
|
238
|
+
this.reset = false;
|
|
239
|
+
blocks[0] = this.block;
|
|
240
|
+
for (i = 1; i < blockCount + 1; ++i) {
|
|
241
|
+
blocks[i] = 0;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (isString) {
|
|
245
|
+
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
246
|
+
code = message.charCodeAt(index);
|
|
247
|
+
if (code < 0x80) {
|
|
248
|
+
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
|
249
|
+
} else if (code < 0x800) {
|
|
250
|
+
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
|
251
|
+
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
252
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
253
|
+
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
|
254
|
+
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
255
|
+
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
256
|
+
} else {
|
|
257
|
+
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
258
|
+
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
|
|
259
|
+
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
260
|
+
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
261
|
+
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
266
|
+
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
this.lastByteIndex = i;
|
|
270
|
+
if (i >= byteCount) {
|
|
271
|
+
this.start = i - byteCount;
|
|
272
|
+
this.block = blocks[blockCount];
|
|
273
|
+
for (i = 0; i < blockCount; ++i) {
|
|
274
|
+
s[i] ^= blocks[i];
|
|
275
|
+
}
|
|
276
|
+
f(s);
|
|
277
|
+
this.reset = true;
|
|
278
|
+
} else {
|
|
279
|
+
this.start = i;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return this;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
Keccak.prototype.encode = function (x, right) {
|
|
286
|
+
var o = x & 255, n = 1;
|
|
287
|
+
var bytes = [o];
|
|
288
|
+
x = x >> 8;
|
|
289
|
+
o = x & 255;
|
|
290
|
+
while (o > 0) {
|
|
291
|
+
bytes.unshift(o);
|
|
292
|
+
x = x >> 8;
|
|
293
|
+
o = x & 255;
|
|
294
|
+
++n;
|
|
295
|
+
}
|
|
296
|
+
if (right) {
|
|
297
|
+
bytes.push(n);
|
|
298
|
+
} else {
|
|
299
|
+
bytes.unshift(n);
|
|
300
|
+
}
|
|
301
|
+
this.update(bytes);
|
|
302
|
+
return bytes.length;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
Keccak.prototype.encodeString = function (str) {
|
|
306
|
+
var result = formatMessage(str);
|
|
307
|
+
str = result[0];
|
|
308
|
+
var isString = result[1];
|
|
309
|
+
var bytes = 0, length = str.length;
|
|
310
|
+
if (isString) {
|
|
311
|
+
for (var i = 0; i < str.length; ++i) {
|
|
312
|
+
var code = str.charCodeAt(i);
|
|
313
|
+
if (code < 0x80) {
|
|
314
|
+
bytes += 1;
|
|
315
|
+
} else if (code < 0x800) {
|
|
316
|
+
bytes += 2;
|
|
317
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
318
|
+
bytes += 3;
|
|
319
|
+
} else {
|
|
320
|
+
code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
|
|
321
|
+
bytes += 4;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
} else {
|
|
325
|
+
bytes = length;
|
|
326
|
+
}
|
|
327
|
+
bytes += this.encode(bytes * 8);
|
|
328
|
+
this.update(str);
|
|
329
|
+
return bytes;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
Keccak.prototype.bytepad = function (strs, w) {
|
|
333
|
+
var bytes = this.encode(w);
|
|
334
|
+
for (var i = 0; i < strs.length; ++i) {
|
|
335
|
+
bytes += this.encodeString(strs[i]);
|
|
336
|
+
}
|
|
337
|
+
var paddingBytes = (w - bytes % w) % w;
|
|
338
|
+
var zeros = [];
|
|
339
|
+
zeros.length = paddingBytes;
|
|
340
|
+
this.update(zeros);
|
|
341
|
+
return this;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
Keccak.prototype.finalize = function () {
|
|
345
|
+
if (this.finalized) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
this.finalized = true;
|
|
349
|
+
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
|
|
350
|
+
blocks[i >> 2] |= this.padding[i & 3];
|
|
351
|
+
if (this.lastByteIndex === this.byteCount) {
|
|
352
|
+
blocks[0] = blocks[blockCount];
|
|
353
|
+
for (i = 1; i < blockCount + 1; ++i) {
|
|
354
|
+
blocks[i] = 0;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
blocks[blockCount - 1] |= 0x80000000;
|
|
358
|
+
for (i = 0; i < blockCount; ++i) {
|
|
359
|
+
s[i] ^= blocks[i];
|
|
360
|
+
}
|
|
361
|
+
f(s);
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
Keccak.prototype.toString = Keccak.prototype.hex = function () {
|
|
365
|
+
this.finalize();
|
|
366
|
+
|
|
367
|
+
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
368
|
+
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
369
|
+
var hex = '', block;
|
|
370
|
+
while (j < outputBlocks) {
|
|
371
|
+
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
372
|
+
block = s[i];
|
|
373
|
+
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
|
|
374
|
+
HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
|
|
375
|
+
HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
|
|
376
|
+
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
|
377
|
+
}
|
|
378
|
+
if (j % blockCount === 0) {
|
|
379
|
+
s = cloneArray(s);
|
|
380
|
+
f(s);
|
|
381
|
+
i = 0;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (extraBytes) {
|
|
385
|
+
block = s[i];
|
|
386
|
+
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
|
|
387
|
+
if (extraBytes > 1) {
|
|
388
|
+
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
|
|
389
|
+
}
|
|
390
|
+
if (extraBytes > 2) {
|
|
391
|
+
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return hex;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
Keccak.prototype.arrayBuffer = function () {
|
|
398
|
+
this.finalize();
|
|
399
|
+
|
|
400
|
+
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
401
|
+
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
402
|
+
var bytes = this.outputBits >> 3;
|
|
403
|
+
var buffer;
|
|
404
|
+
if (extraBytes) {
|
|
405
|
+
buffer = new ArrayBuffer((outputBlocks + 1) << 2);
|
|
406
|
+
} else {
|
|
407
|
+
buffer = new ArrayBuffer(bytes);
|
|
408
|
+
}
|
|
409
|
+
var array = new Uint32Array(buffer);
|
|
410
|
+
while (j < outputBlocks) {
|
|
411
|
+
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
412
|
+
array[j] = s[i];
|
|
413
|
+
}
|
|
414
|
+
if (j % blockCount === 0) {
|
|
415
|
+
s = cloneArray(s);
|
|
416
|
+
f(s);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (extraBytes) {
|
|
420
|
+
array[j] = s[i];
|
|
421
|
+
buffer = buffer.slice(0, bytes);
|
|
422
|
+
}
|
|
423
|
+
return buffer;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
|
|
427
|
+
|
|
428
|
+
Keccak.prototype.digest = Keccak.prototype.array = function () {
|
|
429
|
+
this.finalize();
|
|
430
|
+
|
|
431
|
+
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
432
|
+
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
433
|
+
var array = [], offset, block;
|
|
434
|
+
while (j < outputBlocks) {
|
|
435
|
+
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
436
|
+
offset = j << 2;
|
|
437
|
+
block = s[i];
|
|
438
|
+
array[offset] = block & 0xFF;
|
|
439
|
+
array[offset + 1] = (block >> 8) & 0xFF;
|
|
440
|
+
array[offset + 2] = (block >> 16) & 0xFF;
|
|
441
|
+
array[offset + 3] = (block >> 24) & 0xFF;
|
|
442
|
+
}
|
|
443
|
+
if (j % blockCount === 0) {
|
|
444
|
+
s = cloneArray(s);
|
|
445
|
+
f(s);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (extraBytes) {
|
|
449
|
+
offset = j << 2;
|
|
450
|
+
block = s[i];
|
|
451
|
+
array[offset] = block & 0xFF;
|
|
452
|
+
if (extraBytes > 1) {
|
|
453
|
+
array[offset + 1] = (block >> 8) & 0xFF;
|
|
454
|
+
}
|
|
455
|
+
if (extraBytes > 2) {
|
|
456
|
+
array[offset + 2] = (block >> 16) & 0xFF;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return array;
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
function Kmac(bits, padding, outputBits) {
|
|
463
|
+
Keccak.call(this, bits, padding, outputBits);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
Kmac.prototype = new Keccak();
|
|
467
|
+
|
|
468
|
+
Kmac.prototype.finalize = function () {
|
|
469
|
+
this.encode(this.outputBits, true);
|
|
470
|
+
return Keccak.prototype.finalize.call(this);
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
var f = function (s) {
|
|
474
|
+
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
|
475
|
+
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
|
476
|
+
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
|
|
477
|
+
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
|
|
478
|
+
for (n = 0; n < 48; n += 2) {
|
|
479
|
+
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
|
|
480
|
+
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
|
|
481
|
+
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
|
|
482
|
+
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
|
|
483
|
+
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
|
|
484
|
+
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
|
|
485
|
+
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
|
|
486
|
+
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
|
|
487
|
+
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
|
|
488
|
+
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
|
|
489
|
+
|
|
490
|
+
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
|
|
491
|
+
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
|
|
492
|
+
s[0] ^= h;
|
|
493
|
+
s[1] ^= l;
|
|
494
|
+
s[10] ^= h;
|
|
495
|
+
s[11] ^= l;
|
|
496
|
+
s[20] ^= h;
|
|
497
|
+
s[21] ^= l;
|
|
498
|
+
s[30] ^= h;
|
|
499
|
+
s[31] ^= l;
|
|
500
|
+
s[40] ^= h;
|
|
501
|
+
s[41] ^= l;
|
|
502
|
+
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
|
|
503
|
+
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
|
|
504
|
+
s[2] ^= h;
|
|
505
|
+
s[3] ^= l;
|
|
506
|
+
s[12] ^= h;
|
|
507
|
+
s[13] ^= l;
|
|
508
|
+
s[22] ^= h;
|
|
509
|
+
s[23] ^= l;
|
|
510
|
+
s[32] ^= h;
|
|
511
|
+
s[33] ^= l;
|
|
512
|
+
s[42] ^= h;
|
|
513
|
+
s[43] ^= l;
|
|
514
|
+
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
|
|
515
|
+
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
|
|
516
|
+
s[4] ^= h;
|
|
517
|
+
s[5] ^= l;
|
|
518
|
+
s[14] ^= h;
|
|
519
|
+
s[15] ^= l;
|
|
520
|
+
s[24] ^= h;
|
|
521
|
+
s[25] ^= l;
|
|
522
|
+
s[34] ^= h;
|
|
523
|
+
s[35] ^= l;
|
|
524
|
+
s[44] ^= h;
|
|
525
|
+
s[45] ^= l;
|
|
526
|
+
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
|
|
527
|
+
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
|
|
528
|
+
s[6] ^= h;
|
|
529
|
+
s[7] ^= l;
|
|
530
|
+
s[16] ^= h;
|
|
531
|
+
s[17] ^= l;
|
|
532
|
+
s[26] ^= h;
|
|
533
|
+
s[27] ^= l;
|
|
534
|
+
s[36] ^= h;
|
|
535
|
+
s[37] ^= l;
|
|
536
|
+
s[46] ^= h;
|
|
537
|
+
s[47] ^= l;
|
|
538
|
+
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
|
|
539
|
+
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
|
|
540
|
+
s[8] ^= h;
|
|
541
|
+
s[9] ^= l;
|
|
542
|
+
s[18] ^= h;
|
|
543
|
+
s[19] ^= l;
|
|
544
|
+
s[28] ^= h;
|
|
545
|
+
s[29] ^= l;
|
|
546
|
+
s[38] ^= h;
|
|
547
|
+
s[39] ^= l;
|
|
548
|
+
s[48] ^= h;
|
|
549
|
+
s[49] ^= l;
|
|
550
|
+
|
|
551
|
+
b0 = s[0];
|
|
552
|
+
b1 = s[1];
|
|
553
|
+
b32 = (s[11] << 4) | (s[10] >>> 28);
|
|
554
|
+
b33 = (s[10] << 4) | (s[11] >>> 28);
|
|
555
|
+
b14 = (s[20] << 3) | (s[21] >>> 29);
|
|
556
|
+
b15 = (s[21] << 3) | (s[20] >>> 29);
|
|
557
|
+
b46 = (s[31] << 9) | (s[30] >>> 23);
|
|
558
|
+
b47 = (s[30] << 9) | (s[31] >>> 23);
|
|
559
|
+
b28 = (s[40] << 18) | (s[41] >>> 14);
|
|
560
|
+
b29 = (s[41] << 18) | (s[40] >>> 14);
|
|
561
|
+
b20 = (s[2] << 1) | (s[3] >>> 31);
|
|
562
|
+
b21 = (s[3] << 1) | (s[2] >>> 31);
|
|
563
|
+
b2 = (s[13] << 12) | (s[12] >>> 20);
|
|
564
|
+
b3 = (s[12] << 12) | (s[13] >>> 20);
|
|
565
|
+
b34 = (s[22] << 10) | (s[23] >>> 22);
|
|
566
|
+
b35 = (s[23] << 10) | (s[22] >>> 22);
|
|
567
|
+
b16 = (s[33] << 13) | (s[32] >>> 19);
|
|
568
|
+
b17 = (s[32] << 13) | (s[33] >>> 19);
|
|
569
|
+
b48 = (s[42] << 2) | (s[43] >>> 30);
|
|
570
|
+
b49 = (s[43] << 2) | (s[42] >>> 30);
|
|
571
|
+
b40 = (s[5] << 30) | (s[4] >>> 2);
|
|
572
|
+
b41 = (s[4] << 30) | (s[5] >>> 2);
|
|
573
|
+
b22 = (s[14] << 6) | (s[15] >>> 26);
|
|
574
|
+
b23 = (s[15] << 6) | (s[14] >>> 26);
|
|
575
|
+
b4 = (s[25] << 11) | (s[24] >>> 21);
|
|
576
|
+
b5 = (s[24] << 11) | (s[25] >>> 21);
|
|
577
|
+
b36 = (s[34] << 15) | (s[35] >>> 17);
|
|
578
|
+
b37 = (s[35] << 15) | (s[34] >>> 17);
|
|
579
|
+
b18 = (s[45] << 29) | (s[44] >>> 3);
|
|
580
|
+
b19 = (s[44] << 29) | (s[45] >>> 3);
|
|
581
|
+
b10 = (s[6] << 28) | (s[7] >>> 4);
|
|
582
|
+
b11 = (s[7] << 28) | (s[6] >>> 4);
|
|
583
|
+
b42 = (s[17] << 23) | (s[16] >>> 9);
|
|
584
|
+
b43 = (s[16] << 23) | (s[17] >>> 9);
|
|
585
|
+
b24 = (s[26] << 25) | (s[27] >>> 7);
|
|
586
|
+
b25 = (s[27] << 25) | (s[26] >>> 7);
|
|
587
|
+
b6 = (s[36] << 21) | (s[37] >>> 11);
|
|
588
|
+
b7 = (s[37] << 21) | (s[36] >>> 11);
|
|
589
|
+
b38 = (s[47] << 24) | (s[46] >>> 8);
|
|
590
|
+
b39 = (s[46] << 24) | (s[47] >>> 8);
|
|
591
|
+
b30 = (s[8] << 27) | (s[9] >>> 5);
|
|
592
|
+
b31 = (s[9] << 27) | (s[8] >>> 5);
|
|
593
|
+
b12 = (s[18] << 20) | (s[19] >>> 12);
|
|
594
|
+
b13 = (s[19] << 20) | (s[18] >>> 12);
|
|
595
|
+
b44 = (s[29] << 7) | (s[28] >>> 25);
|
|
596
|
+
b45 = (s[28] << 7) | (s[29] >>> 25);
|
|
597
|
+
b26 = (s[38] << 8) | (s[39] >>> 24);
|
|
598
|
+
b27 = (s[39] << 8) | (s[38] >>> 24);
|
|
599
|
+
b8 = (s[48] << 14) | (s[49] >>> 18);
|
|
600
|
+
b9 = (s[49] << 14) | (s[48] >>> 18);
|
|
601
|
+
|
|
602
|
+
s[0] = b0 ^ (~b2 & b4);
|
|
603
|
+
s[1] = b1 ^ (~b3 & b5);
|
|
604
|
+
s[10] = b10 ^ (~b12 & b14);
|
|
605
|
+
s[11] = b11 ^ (~b13 & b15);
|
|
606
|
+
s[20] = b20 ^ (~b22 & b24);
|
|
607
|
+
s[21] = b21 ^ (~b23 & b25);
|
|
608
|
+
s[30] = b30 ^ (~b32 & b34);
|
|
609
|
+
s[31] = b31 ^ (~b33 & b35);
|
|
610
|
+
s[40] = b40 ^ (~b42 & b44);
|
|
611
|
+
s[41] = b41 ^ (~b43 & b45);
|
|
612
|
+
s[2] = b2 ^ (~b4 & b6);
|
|
613
|
+
s[3] = b3 ^ (~b5 & b7);
|
|
614
|
+
s[12] = b12 ^ (~b14 & b16);
|
|
615
|
+
s[13] = b13 ^ (~b15 & b17);
|
|
616
|
+
s[22] = b22 ^ (~b24 & b26);
|
|
617
|
+
s[23] = b23 ^ (~b25 & b27);
|
|
618
|
+
s[32] = b32 ^ (~b34 & b36);
|
|
619
|
+
s[33] = b33 ^ (~b35 & b37);
|
|
620
|
+
s[42] = b42 ^ (~b44 & b46);
|
|
621
|
+
s[43] = b43 ^ (~b45 & b47);
|
|
622
|
+
s[4] = b4 ^ (~b6 & b8);
|
|
623
|
+
s[5] = b5 ^ (~b7 & b9);
|
|
624
|
+
s[14] = b14 ^ (~b16 & b18);
|
|
625
|
+
s[15] = b15 ^ (~b17 & b19);
|
|
626
|
+
s[24] = b24 ^ (~b26 & b28);
|
|
627
|
+
s[25] = b25 ^ (~b27 & b29);
|
|
628
|
+
s[34] = b34 ^ (~b36 & b38);
|
|
629
|
+
s[35] = b35 ^ (~b37 & b39);
|
|
630
|
+
s[44] = b44 ^ (~b46 & b48);
|
|
631
|
+
s[45] = b45 ^ (~b47 & b49);
|
|
632
|
+
s[6] = b6 ^ (~b8 & b0);
|
|
633
|
+
s[7] = b7 ^ (~b9 & b1);
|
|
634
|
+
s[16] = b16 ^ (~b18 & b10);
|
|
635
|
+
s[17] = b17 ^ (~b19 & b11);
|
|
636
|
+
s[26] = b26 ^ (~b28 & b20);
|
|
637
|
+
s[27] = b27 ^ (~b29 & b21);
|
|
638
|
+
s[36] = b36 ^ (~b38 & b30);
|
|
639
|
+
s[37] = b37 ^ (~b39 & b31);
|
|
640
|
+
s[46] = b46 ^ (~b48 & b40);
|
|
641
|
+
s[47] = b47 ^ (~b49 & b41);
|
|
642
|
+
s[8] = b8 ^ (~b0 & b2);
|
|
643
|
+
s[9] = b9 ^ (~b1 & b3);
|
|
644
|
+
s[18] = b18 ^ (~b10 & b12);
|
|
645
|
+
s[19] = b19 ^ (~b11 & b13);
|
|
646
|
+
s[28] = b28 ^ (~b20 & b22);
|
|
647
|
+
s[29] = b29 ^ (~b21 & b23);
|
|
648
|
+
s[38] = b38 ^ (~b30 & b32);
|
|
649
|
+
s[39] = b39 ^ (~b31 & b33);
|
|
650
|
+
s[48] = b48 ^ (~b40 & b42);
|
|
651
|
+
s[49] = b49 ^ (~b41 & b43);
|
|
652
|
+
|
|
653
|
+
s[0] ^= RC[n];
|
|
654
|
+
s[1] ^= RC[n + 1];
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
if (COMMON_JS) {
|
|
659
|
+
module.exports = methods;
|
|
660
|
+
} else {
|
|
661
|
+
for (i = 0; i < methodNames.length; ++i) {
|
|
662
|
+
root[methodNames[i]] = methods[methodNames[i]];
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
})();
|
|
666
|
+
} (sha3$1));
|
|
667
|
+
|
|
668
|
+
var sha3Exports = sha3$1.exports;
|
|
669
|
+
var sha3 = /*@__PURE__*/getDefaultExportFromCjs(sha3Exports);
|
|
670
|
+
|
|
671
|
+
const {
|
|
672
|
+
sha3_224,
|
|
673
|
+
sha3_256,
|
|
674
|
+
sha3_384,
|
|
675
|
+
sha3_512,
|
|
676
|
+
|
|
677
|
+
keccak_224,
|
|
678
|
+
keccak_256,
|
|
679
|
+
keccak_384,
|
|
680
|
+
keccak_512,
|
|
681
|
+
keccak224,
|
|
682
|
+
keccak256,
|
|
683
|
+
keccak384,
|
|
684
|
+
keccak512,
|
|
685
|
+
|
|
686
|
+
shake_128,
|
|
687
|
+
shake_256,
|
|
688
|
+
shake128,
|
|
689
|
+
shake256,
|
|
690
|
+
|
|
691
|
+
cshake_128,
|
|
692
|
+
cshake_256,
|
|
693
|
+
cshake128,
|
|
694
|
+
cshake256,
|
|
695
|
+
|
|
696
|
+
kmac_128,
|
|
697
|
+
kmac_256,
|
|
698
|
+
kmac128,
|
|
699
|
+
kmac256
|
|
700
|
+
} = sha3;
|
|
701
|
+
|
|
702
|
+
export { cshake128, cshake256, cshake_128, cshake_256, sha3 as default, keccak224, keccak256, keccak384, keccak512, keccak_224, keccak_256, keccak_384, keccak_512, kmac128, kmac256, kmac_128, kmac_256, sha3_224, sha3_256, sha3_384, sha3_512, shake128, shake256, shake_128, shake_256 };
|
package/package.json
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-sha3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
|
|
5
5
|
"main": "src/sha3.js",
|
|
6
|
+
"module": "build/sha3.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"import": "./build/sha3.mjs",
|
|
11
|
+
"require": "./src/sha3.js",
|
|
12
|
+
"default": "./src/sha3.js"
|
|
13
|
+
},
|
|
14
|
+
"./src/sha3.js": "./src/sha3.js",
|
|
15
|
+
"./build/sha3.min.js": "./build/sha3.min.js",
|
|
16
|
+
"./build/sha3.mjs": "./build/sha3.mjs",
|
|
17
|
+
"./build/sha3.min.mjs": "./build/sha3.min.mjs",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"types": "./index.d.ts",
|
|
6
21
|
"devDependencies": {
|
|
22
|
+
"@rollup/plugin-commonjs": "^28.0.5",
|
|
23
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
7
24
|
"expect.js": "~0.3.1",
|
|
8
|
-
"mocha": "
|
|
25
|
+
"mocha": "^11.7.6",
|
|
9
26
|
"nyc": "^15.1.0",
|
|
27
|
+
"rollup": "^4.43.0",
|
|
10
28
|
"tiny-worker": "^2.3.0",
|
|
11
29
|
"uglify-js": "^3.1.9"
|
|
12
30
|
},
|
|
@@ -14,7 +32,7 @@
|
|
|
14
32
|
"test": "nyc mocha tests/node-test.js",
|
|
15
33
|
"report": "nyc --reporter=html --reporter=text mocha tests/node-test.js",
|
|
16
34
|
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
|
17
|
-
"build": "uglifyjs src/sha3.js -c -m --comments --output build/sha3.min.js"
|
|
35
|
+
"build": "rollup -c && uglifyjs src/sha3.js -c -m --comments --output build/sha3.min.js"
|
|
18
36
|
},
|
|
19
37
|
"repository": {
|
|
20
38
|
"type": "git",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
2
|
+
import terser from '@rollup/plugin-terser';
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
{
|
|
6
|
+
input: 'src/sha3.mjs',
|
|
7
|
+
output: {
|
|
8
|
+
file: 'build/sha3.mjs',
|
|
9
|
+
format: 'es'
|
|
10
|
+
},
|
|
11
|
+
plugins: [commonjs({
|
|
12
|
+
strictRequires: false
|
|
13
|
+
})]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
input: 'build/sha3.mjs',
|
|
17
|
+
output: {
|
|
18
|
+
file: 'build/sha3.min.mjs',
|
|
19
|
+
format: 'es'
|
|
20
|
+
},
|
|
21
|
+
plugins: [terser()]
|
|
22
|
+
}
|
|
23
|
+
];
|
package/src/sha3.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
3
|
*
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.10.0
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
6
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
7
7
|
* @license MIT
|
|
@@ -81,6 +81,14 @@
|
|
|
81
81
|
return formatMessage(message)[0].length === 0;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
var cloneArray = function (array) {
|
|
85
|
+
var newArray = [];
|
|
86
|
+
for (var i = 0; i < array.length; ++i) {
|
|
87
|
+
newArray[i] = array[i];
|
|
88
|
+
}
|
|
89
|
+
return newArray;
|
|
90
|
+
}
|
|
91
|
+
|
|
84
92
|
var createOutputMethod = function (bits, padding, outputType) {
|
|
85
93
|
return function (message) {
|
|
86
94
|
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
|
@@ -360,6 +368,7 @@
|
|
|
360
368
|
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
|
361
369
|
}
|
|
362
370
|
if (j % blockCount === 0) {
|
|
371
|
+
s = cloneArray(s);
|
|
363
372
|
f(s);
|
|
364
373
|
i = 0;
|
|
365
374
|
}
|
|
@@ -395,11 +404,12 @@
|
|
|
395
404
|
array[j] = s[i];
|
|
396
405
|
}
|
|
397
406
|
if (j % blockCount === 0) {
|
|
407
|
+
s = cloneArray(s);
|
|
398
408
|
f(s);
|
|
399
409
|
}
|
|
400
410
|
}
|
|
401
411
|
if (extraBytes) {
|
|
402
|
-
array[
|
|
412
|
+
array[j] = s[i];
|
|
403
413
|
buffer = buffer.slice(0, bytes);
|
|
404
414
|
}
|
|
405
415
|
return buffer;
|
|
@@ -423,6 +433,7 @@
|
|
|
423
433
|
array[offset + 3] = (block >> 24) & 0xFF;
|
|
424
434
|
}
|
|
425
435
|
if (j % blockCount === 0) {
|
|
436
|
+
s = cloneArray(s);
|
|
426
437
|
f(s);
|
|
427
438
|
}
|
|
428
439
|
}
|
package/src/sha3.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import sha3 from './sha3.js';
|
|
2
|
+
|
|
3
|
+
export const {
|
|
4
|
+
sha3_224,
|
|
5
|
+
sha3_256,
|
|
6
|
+
sha3_384,
|
|
7
|
+
sha3_512,
|
|
8
|
+
|
|
9
|
+
keccak_224,
|
|
10
|
+
keccak_256,
|
|
11
|
+
keccak_384,
|
|
12
|
+
keccak_512,
|
|
13
|
+
keccak224,
|
|
14
|
+
keccak256,
|
|
15
|
+
keccak384,
|
|
16
|
+
keccak512,
|
|
17
|
+
|
|
18
|
+
shake_128,
|
|
19
|
+
shake_256,
|
|
20
|
+
shake128,
|
|
21
|
+
shake256,
|
|
22
|
+
|
|
23
|
+
cshake_128,
|
|
24
|
+
cshake_256,
|
|
25
|
+
cshake128,
|
|
26
|
+
cshake256,
|
|
27
|
+
|
|
28
|
+
kmac_128,
|
|
29
|
+
kmac_256,
|
|
30
|
+
kmac128,
|
|
31
|
+
kmac256
|
|
32
|
+
} = sha3;
|
|
33
|
+
|
|
34
|
+
export default sha3;
|