From 5f95ceb7331116585945fcbffbdabdcfd3bc8278 Mon Sep 17 00:00:00 2001 From: Yi-Cyuan Chen Date: Sat, 18 Jul 2026 10:14:36 +0800 Subject: [PATCH] ### Added - KMACXOF128 and KMACXOF256 (NIST SP 800-185) --- CHANGELOG.md | 4 ++ LICENSE.txt | 2 +- README.md | 6 ++ bower.json | 2 +- build/sha3.min.js | 6 +- build/sha3.min.mjs | 6 +- build/sha3.mjs | 102 +++++++++++++-------------- index.d.ts | 4 ++ package.json | 2 +- src/sha3.js | 96 ++++++++++++------------- src/sha3.mjs | 4 ++ tests/node-test.js | 6 ++ tests/test-kmac.js | 151 +++++++++++++++++++++++++--------------- tests/test-tuplehash.js | 2 +- 14 files changed, 220 insertions(+), 173 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a36874f..24172d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## v0.12.0 / 2026-07-18 +### Added +- KMACXOF128 and KMACXOF256 (NIST SP 800-185) + ## v0.11.0 / 2026-07-18 ### Added - TupleHash128, TupleHash256, TupleHashXOF128, and TupleHashXOF256 (NIST SP 800-185) diff --git a/LICENSE.txt b/LICENSE.txt index c1ee2fb..3391622 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2015-2023 Chen, Yi-Cyuan +Copyright 2015-2026 Chen, Yi-Cyuan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 5ad4ee4..c006ad4 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ cshake128('Message to hash', 256, 'function name', 'customization'); cshake256('Message to hash', 512, 'function name', 'customization'); kmac128('key', 'Message to hash', 256, 'customization'); kmac256('key', 'Message to hash', 512, 'customization'); +kmacxof128('key', 'Message to hash', 256, 'customization'); +kmacxof256('key', 'Message to hash', 512, 'customization'); tuplehash128(['abc', 'd'], 256, 'customization'); tuplehash256(['abc', 'd'], 512, 'customization'); tuplehashxof128(['abc', 'd'], 256, 'customization'); @@ -129,6 +131,8 @@ const { cshake256, kmac128, kmac256, + kmacxof128, + kmacxof256, tuplehash128, tuplehash256, tuplehashxof128, @@ -154,6 +158,8 @@ import { cshake256, kmac128, kmac256, + kmacxof128, + kmacxof256, tuplehash128, tuplehash256, tuplehashxof128, diff --git a/bower.json b/bower.json index 38e1e57..cb5c582 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "js-sha3", - "version": "0.9.3", + "version": "0.12.0", "main": ["src/sha3.js"], "ignore": [ "samples", diff --git a/build/sha3.min.js b/build/sha3.min.js index 84474f2..97bb320 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.11.0 + * @version 0.12.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] - * @copyright Chen, Yi-Cyuan 2015-2023 + * @copyright Chen, Yi-Cyuan 2015-2026 * @license MIT */ -!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)}function r(e,r,n,i){t.call(this,e,r,n),this.xof=!!i,this.inputActive=!1,this.inputBytesRemaining=0}var n="input is invalid type",i="finalize already called",o="tuple input is incomplete",u="object"==typeof window,a=u?window:{};a.JS_SHA3_NO_WINDOW&&(u=!1);var s=!u&&"object"==typeof self;!a.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?a=global:s&&(a=self);for(var h=!a.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,f="function"==typeof define&&define.amd,c=!a.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,p="0123456789abcdef".split(""),l=[4,1024,262144,67108864],d=[0,8,16,24],y=[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],v=[128,256],b=["hex","buffer","arrayBuffer","array","digest"],w={128:168,256:136},A=a.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,B=!c||!a.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},k=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(n);if(c&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!A(t)&&!B(t))throw new Error(n);return[t,!1]},_=function(t){return 0===k(t)[0].length},m=function(t){for(var e=[],r=0;r>2]|=n<>2]|=(192|n>>6)<>2]|=(128|63&n)<=57344?(u[r>>2]|=(224|n>>12)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<>2]|=(240|n>>18)<>2]|=(128|n>>12&63)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<>2]|=t[f]<=a){for(this.start=r-a,this.block=u[h],r=0;r>=8);n>0;)o.unshift(n),n=255&(e>>=8),++i;return r?o.push(i):o.unshift(i),t.prototype.update.call(this,o),o.length},t.prototype.encodeString=function(e){var r=k(e);e=r[0];var n=r[1],i=0,o=e.length;if(n)for(var u=0;u=57344?i+=3:(a=65536+((1023&a)<<10|1023&e.charCodeAt(++u)),i+=4)}else i=o;return i+=this.encode(8*i),t.prototype.update.call(this,e),i},t.prototype.bytepad=function(e,r){for(var n=this.encode(r),i=0;i>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e>4&15]+p[15&t]+p[t>>12&15]+p[t>>8&15]+p[t>>20&15]+p[t>>16&15]+p[t>>28&15]+p[t>>24&15];u%e==0&&(r=m(r),V(r),o=0)}return i&&(t=r[o],a+=p[t>>4&15]+p[15&t],i>1&&(a+=p[t>>12&15]+p[t>>8&15]),i>2&&(a+=p[t>>20&15]+p[t>>16&15])),a},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,u=0,a=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(a);for(var s=new Uint32Array(t);u>8&255,s[t+2]=e>>16&255,s[t+3]=e>>24&255;a%r==0&&(n=m(n),V(n))}return o&&(t=a<<2,e=n[u],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.outputBits,!0),t.prototype.finalize.call(this)},(r.prototype=new t).getMessageByteLength=function(t){var e=k(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},r.prototype.beginInput=function(t){if(this.finalized)throw new Error(i);if(this.inputActive)throw new Error(o);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=!1,this.inputBytesRemaining=0):(this.inputActive=!0,this.inputBytesRemaining=t),this},r.prototype.updateChunk=function(e){if(this.finalized)throw new Error(i);if(!this.inputActive)throw new Error("no active tuple input");var r=this.getMessageByteLength(e);if(r>this.inputBytesRemaining)throw new Error("tuple input exceeds declared length");return t.prototype.update.call(this,e),this.inputBytesRemaining-=r,0===this.inputBytesRemaining&&(this.inputActive=!1),this},r.prototype.update=function(t){if(this.finalized)throw new Error(i);if(this.inputActive)throw new Error(o);var e=this.getMessageByteLength(t);return this.beginInput(e),0===e?this:this.updateChunk(t)},r.prototype.finalize=function(){if(this.inputActive)throw new Error(o);return this.finalized||this.encode(this.xof?0:this.outputBits,!0),t.prototype.finalize.call(this)};var V=function(t){var e,r,n,i,o,u,a,s,h,f,c,p,l,d,g,v,b,w,A,B,k,_,m,x,S,C,z,E,M,O,R,N,J,j,I,H,F,U,D,L,V,W,Y,K,T,q,G,P,Q,X,Z,$,tt,et,rt,nt,it,ot,ut,at,st,ht,ft;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],u=t[2]^t[12]^t[22]^t[32]^t[42],a=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])^(u<<1|a>>>31),r=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(a<<1|u>>>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^(s<<1|h>>>31),r=o^(h<<1|s>>>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=u^(f<<1|c>>>31),r=a^(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=s^(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|o>>>31),r=c^(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,d=t[0],g=t[1],q=t[11]<<4|t[10]>>>28,G=t[10]<<4|t[11]>>>28,E=t[20]<<3|t[21]>>>29,M=t[21]<<3|t[20]>>>29,at=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,I=t[3]<<1|t[2]>>>31,v=t[13]<<12|t[12]>>>20,b=t[12]<<12|t[13]>>>20,P=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,O=t[33]<<13|t[32]>>>19,R=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,w=t[25]<<11|t[24]>>>21,A=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,N=t[45]<<29|t[44]>>>3,J=t[44]<<29|t[45]>>>3,x=t[6]<<28|t[7]>>>4,S=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,B=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,T=t[9]<<27|t[8]>>>5,C=t[18]<<20|t[19]>>>12,z=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,ut=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^~v&w,t[1]=g^~b&A,t[10]=x^~C&E,t[11]=S^~z&M,t[20]=j^~H&U,t[21]=I^~F&D,t[30]=K^~q&P,t[31]=T^~G&Q,t[40]=et^~nt&ot,t[41]=rt^~it&ut,t[2]=v^~w&B,t[3]=b^~A&k,t[12]=C^~E&O,t[13]=z^~M&R,t[22]=H^~U&L,t[23]=F^~D&V,t[32]=q^~P&X,t[33]=G^~Q&Z,t[42]=nt^~ot&at,t[43]=it^~ut&st,t[4]=w^~B&_,t[5]=A^~k&m,t[14]=E^~O&N,t[15]=M^~R&J,t[24]=U^~L&W,t[25]=D^~V&Y,t[34]=P^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~at&ht,t[45]=ut^~st&ft,t[6]=B^~_&d,t[7]=k^~m&g,t[16]=O^~N&x,t[17]=R^~J&S,t[26]=L^~W&j,t[27]=V^~Y&I,t[36]=X^~$&K,t[37]=Z^~tt&T,t[46]=at^~ht&et,t[47]=st^~ft&rt,t[8]=_^~d&v,t[9]=m^~g&b,t[18]=N^~x&C,t[19]=J^~S&z,t[28]=W^~j&H,t[29]=Y^~I&F,t[38]=$^~K&q,t[39]=tt^~T&G,t[48]=ht^~et&nt,t[49]=ft^~rt&it,t[0]^=y[n],t[1]^=y[n+1]};if(h)module.exports=J;else{for(I=0;I>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,i){t.call(this,e,r,n),this.xof=i}function r(t,r,n,i){e.call(this,t,r,n,i),this.inputActive=!1,this.inputBytesRemaining=0}var n="input is invalid type",i="tuple input is incomplete",o="object"==typeof window,u=o?window:{};u.JS_SHA3_NO_WINDOW&&(o=!1);var a=!o&&"object"==typeof self;!u.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?u=global:a&&(u=self);for(var s=!u.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,f="function"==typeof define&&define.amd,h=!u.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),p=[4,1024,262144,67108864],d=[0,8,16,24],l=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],y=[224,256,384,512],g=[128,256],v=["hex","buffer","arrayBuffer","array","digest"],b={128:168,256:136},w=u.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,A=!h||!u.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},B=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(n);if(h&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!w(t)&&!A(t))throw new Error(n);return[t,!1]},k=function(t){return 0===B(t)[0].length},_=function(t){for(var e=[],r=0;r>2]|=n<>2]|=(192|n>>6)<>2]|=(128|63&n)<=57344?(o[r>>2]|=(224|n>>12)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<>2]|=(240|n>>18)<>2]|=(128|n>>12&63)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<>2]|=t[f]<=u){for(this.start=r-u,this.block=o[s],r=0;r>=8);n>0;)o.unshift(n),n=255&(e>>=8),++i;return r?o.push(i):o.unshift(i),t.prototype.update.call(this,o),o.length},t.prototype.encodeString=function(e){var r=B(e);e=r[0];var n=r[1],i=0,o=e.length;if(n)for(var u=0;u=57344?i+=3:(a=65536+((1023&a)<<10|1023&e.charCodeAt(++u)),i+=4)}else i=o;return i+=this.encode(8*i),t.prototype.update.call(this,e),i},t.prototype.bytepad=function(e,r){for(var n=this.encode(r),i=0;i>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e>4&15]+c[15&t]+c[t>>12&15]+c[t>>8&15]+c[t>>20&15]+c[t>>16&15]+c[t>>28&15]+c[t>>24&15];u%e==0&&(r=_(r),V(r),o=0)}return i&&(t=r[o],a+=c[t>>4&15]+c[15&t],i>1&&(a+=c[t>>12&15]+c[t>>8&15]),i>2&&(a+=c[t>>20&15]+c[t>>16&15])),a},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,u=0,a=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(a);for(var s=new Uint32Array(t);u>8&255,s[t+2]=e>>16&255,s[t+3]=e>>24&255;a%r==0&&(n=_(n),V(n))}return o&&(t=a<<2,e=n[u],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)},(r.prototype=new e).getMessageByteLength=function(t){var e=B(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},r.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},r.prototype._updateChunk=function(t,r){return e.prototype.update.call(this,t),this.inputBytesRemaining-=r,0===this.inputBytesRemaining&&(this.inputActive=!1),this},r.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)},r.prototype.update=function(t){var e=this.getMessageByteLength(t);return this.beginInput(e),this._updateChunk(t,e)},r.prototype.finalize=function(){if(this.inputActive)throw new Error(i);return e.prototype.finalize.call(this)};var V=function(t){var e,r,n,i,o,u,a,s,f,h,c,p,d,y,g,v,b,w,A,B,k,_,m,x,C,S,M,z,E,O,R,N,J,j,I,H,F,U,D,L,V,W,Y,K,T,q,G,P,Q,X,Z,$,tt,et,rt,nt,it,ot,ut,at,st,ft,ht;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],u=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],s=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],h=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])^(u<<1|a>>>31),r=(d=t[9]^t[19]^t[29]^t[39]^t[49])^(a<<1|u>>>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^(s<<1|f>>>31),r=o^(f<<1|s>>>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=u^(h<<1|c>>>31),r=a^(c<<1|h>>>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=s^(p<<1|d>>>31),r=f^(d<<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=h^(i<<1|o>>>31),r=c^(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],g=t[1],q=t[11]<<4|t[10]>>>28,G=t[10]<<4|t[11]>>>28,z=t[20]<<3|t[21]>>>29,E=t[21]<<3|t[20]>>>29,at=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,I=t[3]<<1|t[2]>>>31,v=t[13]<<12|t[12]>>>20,b=t[12]<<12|t[13]>>>20,P=t[22]<<10|t[23]>>>22,Q=t[23]<<10|t[22]>>>22,O=t[33]<<13|t[32]>>>19,R=t[32]<<13|t[33]>>>19,ft=t[42]<<2|t[43]>>>30,ht=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,w=t[25]<<11|t[24]>>>21,A=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,N=t[45]<<29|t[44]>>>3,J=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,it=t[16]<<23|t[17]>>>9,U=t[26]<<25|t[27]>>>7,D=t[27]<<25|t[26]>>>7,B=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,T=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,M=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,ut=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]=y^~v&w,t[1]=g^~b&A,t[10]=x^~S&z,t[11]=C^~M&E,t[20]=j^~H&U,t[21]=I^~F&D,t[30]=K^~q&P,t[31]=T^~G&Q,t[40]=et^~nt&ot,t[41]=rt^~it&ut,t[2]=v^~w&B,t[3]=b^~A&k,t[12]=S^~z&O,t[13]=M^~E&R,t[22]=H^~U&L,t[23]=F^~D&V,t[32]=q^~P&X,t[33]=G^~Q&Z,t[42]=nt^~ot&at,t[43]=it^~ut&st,t[4]=w^~B&_,t[5]=A^~k&m,t[14]=z^~O&N,t[15]=E^~R&J,t[24]=U^~L&W,t[25]=D^~V&Y,t[34]=P^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~at&ft,t[45]=ut^~st&ht,t[6]=B^~_&y,t[7]=k^~m&g,t[16]=O^~N&x,t[17]=R^~J&C,t[26]=L^~W&j,t[27]=V^~Y&I,t[36]=X^~$&K,t[37]=Z^~tt&T,t[46]=at^~ft&et,t[47]=st^~ht&rt,t[8]=_^~y&v,t[9]=m^~g&b,t[18]=N^~x&S,t[19]=J^~C&M,t[28]=W^~j&H,t[29]=Y^~I&F,t[38]=$^~K&q,t[39]=tt^~T&G,t[48]=ft^~et&nt,t[49]=ht^~rt&it,t[0]^=l[n],t[1]^=l[n+1]};if(s)module.exports=J;else{for(I=0;I>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 L(t,e,r){D.call(this,t,e,r)}function T(t,e,r,n){D.call(this,t,e,r),this.xof=!!n,this.inputActive=!1,this.inputBytesRemaining=0}D.prototype.update=function(t){if(this.finalized)throw new Error(n);var e=w(t);t=e[0];for(var r,i,o=e[1],a=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?(a[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=a[h],r=0;r>=8);r>0;)i.unshift(r),r=255&(t>>=8),++n;return e?i.push(n):i.unshift(n),D.prototype.update.call(this,i),i.length},D.prototype.encodeString=function(t){var e=w(t);t=e[0];var r=e[1],n=0,i=t.length;if(r)for(var o=0;o=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++o)),n+=4)}else n=i;return n+=this.encode(8*n),D.prototype.update.call(this,t),n},D.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];a%e===0&&(r=A(r),V(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},D.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>8&255,u[t+2]=e>>16&255,u[t+3]=e>>24&255;s%r===0&&(n=A(n),V(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},L.prototype=new D,L.prototype.finalize=function(){return this.finalized||this.encode(this.outputBits,!0),D.prototype.finalize.call(this)},T.prototype=new D,T.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},T.prototype.beginInput=function(t){if(this.finalized)throw new Error(n);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=!1,this.inputBytesRemaining=0):(this.inputActive=!0,this.inputBytesRemaining=t),this},T.prototype.updateChunk=function(t){if(this.finalized)throw new Error(n);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 D.prototype.update.call(this,t),this.inputBytesRemaining-=e,0===this.inputBytesRemaining&&(this.inputActive=!1),this},T.prototype.update=function(t){if(this.finalized)throw new Error(n);if(this.inputActive)throw new Error(i);var e=this.getMessageByteLength(t);return this.beginInput(e),0===e?this:this.updateChunk(t)},T.prototype.finalize=function(){if(this.inputActive)throw new Error(i);return this.finalized||this.encode(this.xof?0:this.outputBits,!0),D.prototype.finalize.call(this)};var V=function(t){var e,r,n,i,o,a,s,u,h,f,c,p,d,y,g,k,v,b,w,_,A,B,x,m,S,C,z,E,M,O,R,N,J,j,I,H,F,U,D,L,T,V,W,Y,K,P,q,G,Q,X,Z,$,tt,et,rt,nt,it,ot,at,st,ut,ht,ft;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],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|s>>>31),r=(d=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|h>>>31),r=o^(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=a^(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|d>>>31),r=h^(d<<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|o>>>31),r=c^(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],g=t[1],P=t[11]<<4|t[10]>>>28,q=t[10]<<4|t[11]>>>28,E=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,V=t[40]<<18|t[41]>>>14,W=t[41]<<18|t[40]>>>14,j=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,k=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,R=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,b=t[25]<<11|t[24]>>>21,w=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,N=t[45]<<29|t[44]>>>3,J=t[44]<<29|t[45]>>>3,m=t[6]<<28|t[7]>>>4,S=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,A=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,Y=t[8]<<27|t[9]>>>5,K=t[9]<<27|t[8]>>>5,C=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,T=t[39]<<8|t[38]>>>24,B=t[48]<<14|t[49]>>>18,x=t[49]<<14|t[48]>>>18,t[0]=y^~k&b,t[1]=g^~v&w,t[10]=m^~C&E,t[11]=S^~z&M,t[20]=j^~H&U,t[21]=I^~F&D,t[30]=Y^~P&G,t[31]=K^~q&Q,t[40]=et^~nt&ot,t[41]=rt^~it&at,t[2]=k^~b&_,t[3]=v^~w&A,t[12]=C^~E&O,t[13]=z^~M&R,t[22]=H^~U&L,t[23]=F^~D&T,t[32]=P^~G&X,t[33]=q^~Q&Z,t[42]=nt^~ot&st,t[43]=it^~at&ut,t[4]=b^~_&B,t[5]=w^~A&x,t[14]=E^~O&N,t[15]=M^~R&J,t[24]=U^~L&V,t[25]=D^~T&W,t[34]=G^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~st&ht,t[45]=at^~ut&ft,t[6]=_^~B&y,t[7]=A^~x&g,t[16]=O^~N&m,t[17]=R^~J&S,t[26]=L^~V&j,t[27]=T^~W&I,t[36]=X^~$&Y,t[37]=Z^~tt&K,t[46]=st^~ht&et,t[47]=ut^~ft&rt,t[8]=B^~y&k,t[9]=x^~g&v,t[18]=N^~m&C,t[19]=J^~S&z,t[28]=V^~j&H,t[29]=W^~I&F,t[38]=$^~Y&P,t[39]=tt^~K&q,t[48]=ht^~et&nt,t[49]=ft^~rt&it,t[0]^=l[n],t[1]^=l[n+1]};if(u)r.exports=R;else for(J=0;J>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 L(t,e,r,n){D.call(this,t,e,r),this.xof=n}function T(t,e,r,n){L.call(this,t,e,r,n),this.inputActive=!1,this.inputBytesRemaining=0}D.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=b(t);t=e[0];for(var r,n,i=e[1],o=this.blocks,a=this.byteCount,u=t.length,s=this.blockCount,h=0,f=this.s;h>2]|=n<>2]|=(192|n>>6)<>2]|=(128|63&n)<=57344?(o[r>>2]|=(224|n>>12)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<>2]|=(240|n>>18)<>2]|=(128|n>>12&63)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<>2]|=t[h]<=a){for(this.start=r-a,this.block=o[s],r=0;r>=8);r>0;)i.unshift(r),r=255&(t>>=8),++n;return e?i.push(n):i.unshift(n),D.prototype.update.call(this,i),i.length},D.prototype.encodeString=function(t){var e=b(t);t=e[0];var r=e[1],n=0,i=t.length;if(r)for(var o=0;o=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++o)),n+=4)}else n=i;return n+=this.encode(8*n),D.prototype.update.call(this,t),n},D.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]+h[15&t]+h[t>>12&15]+h[t>>8&15]+h[t>>20&15]+h[t>>16&15]+h[t>>28&15]+h[t>>24&15];a%e===0&&(r=w(r),V(r),o=0)}return i&&(t=r[o],u+=h[t>>4&15]+h[15&t],i>1&&(u+=h[t>>12&15]+h[t>>8&15]),i>2&&(u+=h[t>>20&15]+h[t>>16&15])),u},D.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,u=this.outputBits>>3;t=i?new ArrayBuffer(n+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%r===0&&(n=w(n),V(n))}return o&&(t=u<<2,e=n[a],s[t]=255&e,o>1&&(s[t+1]=e>>8&255),o>2&&(s[t+2]=e>>16&255)),s},L.prototype=new D,L.prototype.finalize=function(){return this.finalized||this.encode(this.xof?0:this.outputBits,!0),D.prototype.finalize.call(this)},T.prototype=new L,T.prototype.getMessageByteLength=function(t){var e=b(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},T.prototype.beginInput=function(t){if(this.inputActive)throw new Error(n);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},T.prototype._updateChunk=function(t,e){return L.prototype.update.call(this,t),this.inputBytesRemaining-=e,0===this.inputBytesRemaining&&(this.inputActive=!1),this},T.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)},T.prototype.update=function(t){var e=this.getMessageByteLength(t);return this.beginInput(e),this._updateChunk(t,e)},T.prototype.finalize=function(){if(this.inputActive)throw new Error(n);return L.prototype.finalize.call(this)};var V=function(t){var e,r,n,i,o,a,u,s,h,f,c,l,d,y,k,g,v,b,_,w,A,x,B,m,C,S,M,z,E,O,R,N,J,j,I,H,F,U,D,L,T,V,W,Y,K,P,q,G,Q,X,Z,$,tt,et,rt,nt,it,ot,at,ut,st,ht,ft;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],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=(l=t[8]^t[18]^t[28]^t[38]^t[48])^(a<<1|u>>>31),r=(d=t[9]^t[19]^t[29]^t[39]^t[49])^(u<<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^(s<<1|h>>>31),r=o^(h<<1|s>>>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^(f<<1|c>>>31),r=u^(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=s^(l<<1|d>>>31),r=h^(d<<1|l>>>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|o>>>31),r=c^(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],k=t[1],P=t[11]<<4|t[10]>>>28,q=t[10]<<4|t[11]>>>28,z=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,V=t[40]<<18|t[41]>>>14,W=t[41]<<18|t[40]>>>14,j=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,g=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,R=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,b=t[25]<<11|t[24]>>>21,_=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,N=t[45]<<29|t[44]>>>3,J=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,A=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,Y=t[8]<<27|t[9]>>>5,K=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,M=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,T=t[39]<<8|t[38]>>>24,x=t[48]<<14|t[49]>>>18,B=t[49]<<14|t[48]>>>18,t[0]=y^~g&b,t[1]=k^~v&_,t[10]=m^~S&z,t[11]=C^~M&E,t[20]=j^~H&U,t[21]=I^~F&D,t[30]=Y^~P&G,t[31]=K^~q&Q,t[40]=et^~nt&ot,t[41]=rt^~it&at,t[2]=g^~b&w,t[3]=v^~_&A,t[12]=S^~z&O,t[13]=M^~E&R,t[22]=H^~U&L,t[23]=F^~D&T,t[32]=P^~G&X,t[33]=q^~Q&Z,t[42]=nt^~ot&ut,t[43]=it^~at&st,t[4]=b^~w&x,t[5]=_^~A&B,t[14]=z^~O&N,t[15]=E^~R&J,t[24]=U^~L&V,t[25]=D^~T&W,t[34]=G^~X&$,t[35]=Q^~Z&tt,t[44]=ot^~ut&ht,t[45]=at^~st&ft,t[6]=w^~x&y,t[7]=A^~B&k,t[16]=O^~N&m,t[17]=R^~J&C,t[26]=L^~V&j,t[27]=T^~W&I,t[36]=X^~$&Y,t[37]=Z^~tt&K,t[46]=ut^~ht&et,t[47]=st^~ft&rt,t[8]=x^~y&g,t[9]=B^~k&v,t[18]=N^~m&S,t[19]=J^~C&M,t[28]=V^~j&H,t[29]=W^~I&F,t[38]=$^~Y&P,t[39]=tt^~K&q,t[48]=ht^~et&nt,t[49]=ft^~rt&it,t[0]^=p[n],t[1]^=p[n+1]};if(u)r.exports=R;else for(J=0;J this.inputBytesRemaining) { - throw new Error(TUPLE_LENGTH_ERROR); - } - Keccak.prototype.update.call(this, message); + TupleHash.prototype._updateChunk = function (message, byteLength) { + Kmac.prototype.update.call(this, message); this.inputBytesRemaining -= byteLength; if (this.inputBytesRemaining === 0) { this.inputActive = false; @@ -582,29 +573,28 @@ var sha3$1 = {exports: {}}; return this; }; - TupleHash.prototype.update = function (message) { - if (this.finalized) { - throw new Error(FINALIZE_ERROR); - } - if (this.inputActive) { - throw new Error(TUPLE_INCOMPLETE_ERROR); + TupleHash.prototype.updateChunk = function (message) { + if (!this.inputActive) { + throw new Error(TUPLE_ACTIVE_ERROR); } var byteLength = this.getMessageByteLength(message); - this.beginInput(byteLength); - if (byteLength === 0) { - return this; + if (byteLength > this.inputBytesRemaining) { + throw new Error(TUPLE_LENGTH_ERROR); } - return this.updateChunk(message); + return this._updateChunk(message, byteLength); + }; + + TupleHash.prototype.update = function (message) { + var byteLength = this.getMessageByteLength(message); + this.beginInput(byteLength); + return this._updateChunk(message, byteLength); }; TupleHash.prototype.finalize = function () { if (this.inputActive) { throw new Error(TUPLE_INCOMPLETE_ERROR); } - if (!this.finalized) { - this.encode(this.xof ? 0 : this.outputBits, true); - } - return Keccak.prototype.finalize.call(this); + return Kmac.prototype.finalize.call(this); }; var f = function (s) { @@ -834,6 +824,10 @@ const { kmac_256, kmac128, kmac256, + kmacxof_128, + kmacxof_256, + kmacxof128, + kmacxof256, tuplehash_128, tuplehash_256, @@ -845,4 +839,4 @@ const { tuplehashxof256 } = sha3; -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, tuplehash128, tuplehash256, tuplehash_128, tuplehash_256, tuplehashxof128, tuplehashxof256, tuplehashxof_128, tuplehashxof_256 }; +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, kmacxof128, kmacxof256, kmacxof_128, kmacxof_256, sha3_224, sha3_256, sha3_384, sha3_512, shake128, shake256, shake_128, shake_256, tuplehash128, tuplehash256, tuplehash_128, tuplehash_256, tuplehashxof128, tuplehashxof256, tuplehashxof_128, tuplehashxof_256 }; diff --git a/index.d.ts b/index.d.ts index ad3aabc..0cde75a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -405,6 +405,10 @@ export var kmac_128: KmacHash; export var kmac_256: KmacHash; export var kmac128: KmacHash; export var kmac256: KmacHash; +export var kmacxof_128: KmacHash; +export var kmacxof_256: KmacHash; +export var kmacxof128: KmacHash; +export var kmacxof256: KmacHash; export var tuplehash_128: TupleHashMethod; export var tuplehash_256: TupleHashMethod; export var tuplehash128: TupleHashMethod; diff --git a/package.json b/package.json index f581825..630ed45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-sha3", - "version": "0.11.0", + "version": "0.12.0", "description": "A simple SHA-3 / Keccak / SHAKE / cSHAKE / KMAC / TupleHash 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 0f7bde0..598d4a1 100644 --- a/src/sha3.js +++ b/src/sha3.js @@ -1,9 +1,9 @@ /** * [js-sha3]{@link https://github.com/emn178/js-sha3} * - * @version 0.11.0 + * @version 0.12.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] - * @copyright Chen, Yi-Cyuan 2015-2023 + * @copyright Chen, Yi-Cyuan 2015-2026 * @license MIT */ /*jslint bitwise: true */ @@ -111,9 +111,15 @@ }; }; - var createKmacOutputMethod = function (bits, padding, outputType) { + var createKmacOutputMethod = function (bits, padding, xof, outputType) { return function (key, message, outputBits, s) { - return methods['kmac' + bits].update(key, message, outputBits, s)[outputType](); + return methods[(xof ? 'kmacxof' : 'kmac') + bits].update(key, message, outputBits, s)[outputType](); + }; + }; + + var createTupleHashOutputMethod = function (bits, padding, xof, outputType) { + return function (inputs, outputBits, s) { + return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType](); }; }; @@ -163,22 +169,18 @@ return createOutputMethods(method, createCshakeOutputMethod, bits, padding); }; - var createKmacMethod = function (bits, padding) { + var createKmacMethod = function (bits, padding, xof) { var w = CSHAKE_BYTEPAD[bits]; - var method = createKmacOutputMethod(bits, padding, 'hex'); + var method = createKmacOutputMethod(bits, padding, xof, 'hex'); method.create = function (key, outputBits, s) { - return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w); + return new Kmac(bits, padding, outputBits, xof).bytepad(['KMAC', s], w).bytepad([key], w); }; method.update = function (key, message, outputBits, s) { return method.create(key, outputBits, s).update(message); }; - return createOutputMethods(method, createKmacOutputMethod, bits, padding); - }; - - var createTupleHashOutputMethod = function (bits, padding, xof, outputType) { - return function (inputs, outputBits, s) { - return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType](); - }; + return createOutputMethods(method, function (b, p, outputType) { + return createKmacOutputMethod(b, p, xof, outputType); + }, bits, padding); }; var createTupleHashMethod = function (bits, padding, xof) { @@ -207,7 +209,12 @@ { name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod }, { name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod }, { name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod }, - { name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }, + { name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) { + return createKmacMethod(bits, padding, false); + }}, + { name: 'kmacxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) { + return createKmacMethod(bits, padding, true); + }}, { name: 'tuplehash', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) { return createTupleHashMethod(bits, padding, false); }}, @@ -488,27 +495,27 @@ return array; }; - function Kmac(bits, padding, outputBits) { + function Kmac(bits, padding, outputBits, xof) { Keccak.call(this, bits, padding, outputBits); + this.xof = xof; } Kmac.prototype = new Keccak(); Kmac.prototype.finalize = function () { if (!this.finalized) { - this.encode(this.outputBits, true); + this.encode(this.xof ? 0 : this.outputBits, true); } return Keccak.prototype.finalize.call(this); }; function TupleHash(bits, padding, outputBits, xof) { - Keccak.call(this, bits, padding, outputBits); - this.xof = !!xof; + Kmac.call(this, bits, padding, outputBits, xof); this.inputActive = false; this.inputBytesRemaining = 0; } - TupleHash.prototype = new Keccak(); + TupleHash.prototype = new Kmac(); TupleHash.prototype.getMessageByteLength = function (message) { var result = formatMessage(message); @@ -534,9 +541,6 @@ }; TupleHash.prototype.beginInput = function (byteLength) { - if (this.finalized) { - throw new Error(FINALIZE_ERROR); - } if (this.inputActive) { throw new Error(TUPLE_INCOMPLETE_ERROR); } @@ -545,28 +549,15 @@ throw new Error(TUPLE_BYTE_LENGTH_ERROR); } this.encode(byteLength * 8, false); - if (byteLength === 0) { - this.inputActive = false; - this.inputBytesRemaining = 0; - } else { + if (byteLength !== 0) { this.inputActive = true; this.inputBytesRemaining = byteLength; } return this; }; - TupleHash.prototype.updateChunk = function (message) { - if (this.finalized) { - throw new Error(FINALIZE_ERROR); - } - if (!this.inputActive) { - throw new Error(TUPLE_ACTIVE_ERROR); - } - var byteLength = this.getMessageByteLength(message); - if (byteLength > this.inputBytesRemaining) { - throw new Error(TUPLE_LENGTH_ERROR); - } - Keccak.prototype.update.call(this, message); + TupleHash.prototype._updateChunk = function (message, byteLength) { + Kmac.prototype.update.call(this, message); this.inputBytesRemaining -= byteLength; if (this.inputBytesRemaining === 0) { this.inputActive = false; @@ -574,29 +565,28 @@ return this; }; - TupleHash.prototype.update = function (message) { - if (this.finalized) { - throw new Error(FINALIZE_ERROR); - } - if (this.inputActive) { - throw new Error(TUPLE_INCOMPLETE_ERROR); + TupleHash.prototype.updateChunk = function (message) { + if (!this.inputActive) { + throw new Error(TUPLE_ACTIVE_ERROR); } var byteLength = this.getMessageByteLength(message); - this.beginInput(byteLength); - if (byteLength === 0) { - return this; + if (byteLength > this.inputBytesRemaining) { + throw new Error(TUPLE_LENGTH_ERROR); } - return this.updateChunk(message); + return this._updateChunk(message, byteLength); + }; + + TupleHash.prototype.update = function (message) { + var byteLength = this.getMessageByteLength(message); + this.beginInput(byteLength); + return this._updateChunk(message, byteLength); }; TupleHash.prototype.finalize = function () { if (this.inputActive) { throw new Error(TUPLE_INCOMPLETE_ERROR); } - if (!this.finalized) { - this.encode(this.xof ? 0 : this.outputBits, true); - } - return Keccak.prototype.finalize.call(this); + return Kmac.prototype.finalize.call(this); }; var f = function (s) { diff --git a/src/sha3.mjs b/src/sha3.mjs index e810805..7ddb2a5 100644 --- a/src/sha3.mjs +++ b/src/sha3.mjs @@ -29,6 +29,10 @@ export const { kmac_256, kmac128, kmac256, + kmacxof_128, + kmacxof_256, + kmacxof128, + kmacxof256, tuplehash_128, tuplehash_256, diff --git a/tests/node-test.js b/tests/node-test.js index b411cc5..969cbf8 100644 --- a/tests/node-test.js +++ b/tests/node-test.js @@ -16,6 +16,8 @@ function unset() { shake256 = null; kmac128 = null; kmac256 = null; + kmacxof128 = null; + kmacxof256 = null; tuplehash128 = null; tuplehash256 = null; tuplehashxof128 = null; @@ -45,6 +47,8 @@ function requireToGlobal() { cshake256 = sha3.cshake256; kmac128 = sha3.kmac128; kmac256 = sha3.kmac256; + kmacxof128 = sha3.kmacxof128; + kmacxof256 = sha3.kmacxof256; tuplehash128 = sha3.tuplehash128; tuplehash256 = sha3.tuplehash256; tuplehashxof128 = sha3.tuplehashxof128; @@ -117,6 +121,8 @@ define = function (func) { cshake256 = sha3.cshake256; kmac128 = sha3.kmac128; kmac256 = sha3.kmac256; + kmacxof128 = sha3.kmacxof128; + kmacxof256 = sha3.kmacxof256; tuplehash128 = sha3.tuplehash128; tuplehash256 = sha3.tuplehash256; tuplehashxof128 = sha3.tuplehashxof128; diff --git a/tests/test-kmac.js b/tests/test-kmac.js index bb3c01e..3583c4b 100644 --- a/tests/test-kmac.js +++ b/tests/test-kmac.js @@ -1,42 +1,47 @@ -(function (kmac256, kmac128) { +(function (kmac256, kmac128, kmacxof256, kmacxof128) { // http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/KMAC_samples.pdf + // https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/KMACXOF_samples.pdf + var key = [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F]; + var shortInput = [0x00, 0x01, 0x02, 0x03]; + var longInput = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7 + ]; + var testCases = [ { name: 'kmac128', method: kmac128, cases: [ { - input: [0x00, 0x01, 0x02, 0x03], + input: shortInput, bits: 256, - key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F], + key: key, s: '', output: 'e5780b0d3ea6f7d3a429c5706aa43a00fadbd7d49628839e3187243f456ee14e' }, { - input: [0x00, 0x01, 0x02, 0x03], + input: shortInput, bits: 256, - key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F], + key: key, s: 'My Tagged Application', output: '3b1fba963cd8b0b59e8c1a6d71888b7143651af8ba0a7070c0979e2811324aa5' }, { - input: [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, - 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, - 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7 - ], + input: longInput, bits: 256, - key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F], + key: key, s: 'My Tagged Application', output: '1f5b4e6cca02209e0dcb5ca635b89a15e271ecc760071dfd805faa38f9729230' } @@ -47,51 +52,23 @@ method: kmac256, cases: [ { - input: [0x00, 0x01, 0x02, 0x03], + input: shortInput, bits: 512, - key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F], + key: key, s: 'My Tagged Application', output: '20c570c31346f703c9ac36c61c03cb64c3970d0cfc787e9b79599d273a68d2f7f69d4cc3de9d104a351689f27cf6f5951f0103f33f4f24871024d9c27773a8dd' }, { - input: [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, - 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, - 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7 - ], + input: longInput, bits: 512, - key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F], + key: key, s: '', output: '75358cf39e41494e949707927cee0af20a3ff553904c86b08f21cc414bcfd691589d27cf5e15369cbbff8b9a4c2eb17800855d0235ff635da82533ec6b759b69' }, { - input: [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, - 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, - 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7 - ], + input: longInput, bits: 512, - key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F], + key: key, s: 'My Tagged Application', output: 'b58618f71f92e1d56c1b8c55ddd7cd188b97b4ca4d99831eb2699a837da2e4d970fbacfde50033aea585f1a2708510c32d07880801bd182898fe476876fc8965' }, @@ -103,6 +80,60 @@ output: '031801b0b50ebeef772fbe7a279bc144' } ] + }, + { + name: 'kmacxof128', + method: kmacxof128, + cases: [ + { + input: shortInput, + bits: 256, + key: key, + s: '', + output: 'cd83740bbd92ccc8cf032b1481a0f4460e7ca9dd12b08a0c4031178bacd6ec35' + }, + { + input: shortInput, + bits: 256, + key: key, + s: 'My Tagged Application', + output: '31a44527b4ed9f5c6101d11de6d26f0620aa5c341def41299657fe9df1a3b16c' + }, + { + input: longInput, + bits: 256, + key: key, + s: 'My Tagged Application', + output: '47026c7cd793084aa0283c253ef658490c0db61438b8326fe9bddf281b83ae0f' + } + ] + }, + { + name: 'kmacxof256', + method: kmacxof256, + cases: [ + { + input: shortInput, + bits: 512, + key: key, + s: 'My Tagged Application', + output: '1755133f1534752aad0748f2c706fb5c784512cab835cd15676b16c0c6647fa96faa7af634a0bf8ff6df39374fa00fad9a39e322a7c92065a64eb1fb0801eb2b' + }, + { + input: longInput, + bits: 512, + key: key, + s: '', + output: 'ff7b171f1e8a2b24683eed37830ee797538ba8dc563f6da1e667391a75edc02ca633079f81ce12a25f45615ec89972031d18337331d24ceb8f8ca8e6a19fd98b' + }, + { + input: longInput, + bits: 512, + key: key, + s: 'My Tagged Application', + output: 'd5be731c954ed7732846bb59dbe3a8e30f83e77a4bff4459f2f1c2b4ecebb8ce67ba01c62e8ab8578d2d499bd1bb276768781190020a306a97de281dcc30305d' + } + ] } ]; @@ -115,4 +146,12 @@ }); }); }); -})(kmac256, kmac128); + + describe('#kmacxof aliases', function () { + it('should export identical aliases', function () { + var sha3 = require('../src/sha3.js'); + expect(sha3.kmacxof128).to.be(sha3.kmacxof_128); + expect(sha3.kmacxof256).to.be(sha3.kmacxof_256); + }); + }); +})(kmac256, kmac128, kmacxof256, kmacxof128); diff --git a/tests/test-tuplehash.js b/tests/test-tuplehash.js index c6190e5..d1d0179 100644 --- a/tests/test-tuplehash.js +++ b/tests/test-tuplehash.js @@ -203,7 +203,7 @@ expect(array).to.eql(digest); expect(Array.prototype.slice.call(new Uint8Array(buffer))).to.eql(array); expect(function () { hash.update(t1); }).to.throwError(/finalize already called/); - expect(function () { hash.updateChunk(t1); }).to.throwError(/finalize already called/); + expect(function () { hash.updateChunk(t1); }).to.throwError(/no active tuple input/); }); it('should require customization like KMAC', function () {