diff --git a/CHANGELOG.md b/CHANGELOG.md
index 27d9448..1396ba5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,14 @@
# Change Log
+## v0.6.0 / 2017-06-15
+### Added
+- cSHAKE method.
+- KMAC method.
+- alias methods without underscore like shake128, keccak512.
+
+### Changed
+- throw error if input type is incorrect.
+
## v0.5.7 / 2016-12-30
### Fixed
- ArrayBuffer detection in old browsers.
@@ -12,6 +21,7 @@
### Added
- TypeScript support.
- ArrayBuffer method.
+
### Deprecated
- Buffer method.
@@ -38,6 +48,7 @@
## v0.4.1 / 2015-09-18
### Added
- Integer array output.
+
### Fixed
- Shake output incorrect when it's greater than 1088.
@@ -58,6 +69,7 @@
## v0.2.0 / 2015-04-04
### Added
- NIST's May 2014 SHA-3 version.
+
### Changed
- Rename original methods to keccak.
diff --git a/LICENSE.txt b/LICENSE.txt
index 5b6aafa..e74b8a4 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright 2015-2016 Chen, Yi-Cyuan
+Copyright 2015-2017 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 7894834..b41001c 100644
--- a/README.md
+++ b/README.md
@@ -19,8 +19,8 @@ A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 enco
[Keccak-384 Online](http://emn178.github.io/online-tools/keccak_384.html)
[Keccak-256 Online](http://emn178.github.io/online-tools/keccak_256.html)
[Keccak-224 Online](http://emn178.github.io/online-tools/keccak_224.html)
-[Shake-128 Online](http://emn178.github.io/online-tools/shake_128.html)
-[Shake-256 Online](http://emn178.github.io/online-tools/shake_256.html)
+[Shake128 Online](http://emn178.github.io/online-tools/shake_128.html)
+[Shake256 Online](http://emn178.github.io/online-tools/shake_256.html)
## Download
[Compress](https://raw.github.com/emn178/js-sha3/master/build/sha3.min.js)
@@ -42,23 +42,27 @@ sha3_512('Message to hash');
sha3_384('Message to hash');
sha3_256('Message to hash');
sha3_224('Message to hash');
-keccak_512('Message to hash');
-keccak_384('Message to hash');
-keccak_256('Message to hash');
-keccak_224('Message to hash');
-shake_128('Message to hash', 256);
-shake_256('Message to hash', 512);
+keccak512('Message to hash');
+keccak384('Message to hash');
+keccak256('Message to hash');
+keccak224('Message to hash');
+shake128('Message to hash', 256);
+shake256('Message to hash', 512);
+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');
// Support ArrayBuffer output
-var buffer = keccak_224.buffer('Message to hash');
+var buffer = keccak224.buffer('Message to hash');
// Support Array output
-var buffer = keccak_224.array('Message to hash');
+var buffer = keccak224.array('Message to hash');
// update hash
sha3_512.update('Message ').update('to ').update('hash').hex();
// specify shake output bits at first update
-shake_128.update('Message ', 256).update('to ').update('hash').hex();
+shake128.update('Message ', 256).update('to ').update('hash').hex();
// or to use create
var hash = sha3_512.create();
@@ -67,10 +71,16 @@ hash.update('...');
hash.hex();
// specify shake output bits when creating
-var hash = shake_128.create(256);
+var hash = shake128.create(256);
hash.update('...');
hash.update('...');
hash.hex();
+
+// specify cshake output bits, function name and customization when creating
+var hash = cshake128.create(256, 'function name', 'customization');
+
+// specify kmac key, output bits and customization when creating
+var hash = kmac128.create('key', 256, 'customization');
```
If you use node.js, you should require the module first:
```JavaScript
@@ -78,12 +88,16 @@ sha3_512 = require('js-sha3').sha3_512;
sha3_384 = require('js-sha3').sha3_384;
sha3_256 = require('js-sha3').sha3_256;
sha3_224 = require('js-sha3').sha3_224;
-keccak_512 = require('js-sha3').keccak_512;
-keccak_384 = require('js-sha3').keccak_384;
-keccak_256 = require('js-sha3').keccak_256;
-keccak_224 = require('js-sha3').keccak_224;
-shake_128 = require('js-sha3').shake_128;
-shake_256 = require('js-sha3').shake_256;
+keccak512 = require('js-sha3').keccak512;
+keccak384 = require('js-sha3').keccak384;
+keccak256 = require('js-sha3').keccak256;
+keccak224 = require('js-sha3').keccak224;
+shake128 = require('js-sha3').shake128;
+shake256 = require('js-sha3').shake256;
+cshake128 = require('js-sha3').cshake128;
+cshake256 = require('js-sha3').cshake256;
+kmac128 = require('js-sha3').kmac128;
+kmac256 = require('js-sha3').kmac256;
```
If you use TypeScript, you can import like this:
```TypeScript
@@ -129,46 +143,46 @@ sha3_224('The quick brown fox jumps over the lazy dog');
sha3_224('The quick brown fox jumps over the lazy dog.');
// 2d0708903833afabdd232a20201176e8b58c5be8a6fe74265ac54db0
-keccak_512('');
+keccak512('');
// 0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e
-keccak_512('The quick brown fox jumps over the lazy dog');
+keccak512('The quick brown fox jumps over the lazy dog');
// d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609
-keccak_512('The quick brown fox jumps over the lazy dog.');
+keccak512('The quick brown fox jumps over the lazy dog.');
// ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760
-keccak_384('');
+keccak384('');
// 2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff
-keccak_384('The quick brown fox jumps over the lazy dog');
+keccak384('The quick brown fox jumps over the lazy dog');
// 283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3
-keccak_384('The quick brown fox jumps over the lazy dog.');
+keccak384('The quick brown fox jumps over the lazy dog.');
// 9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b
-keccak_256('');
+keccak256('');
// c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
-keccak_256('The quick brown fox jumps over the lazy dog');
+keccak256('The quick brown fox jumps over the lazy dog');
// 4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15
-keccak_256('The quick brown fox jumps over the lazy dog.');
+keccak256('The quick brown fox jumps over the lazy dog.');
// 578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d
-keccak_224('');
+keccak224('');
// f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd
-keccak_224('The quick brown fox jumps over the lazy dog');
+keccak224('The quick brown fox jumps over the lazy dog');
// 310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe
-keccak_224('The quick brown fox jumps over the lazy dog.');
+keccak224('The quick brown fox jumps over the lazy dog.');
// c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab
-shake_128('', 256);
+shake128('', 256);
// 7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26
-shake_256('', 512);
+shake256('', 512);
// 46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be
```
It also supports UTF-8 encoding:
@@ -187,16 +201,16 @@ sha3_256('中文');
sha3_224('中文');
// 106d169e10b61c2a2a05554d3e631ec94467f8316640f29545d163ee
-keccak_512('中文');
+keccak512('中文');
// 2f6a1bd50562230229af34b0ccf46b8754b89d23ae2c5bf7840b4acfcef86f87395edc0a00b2bfef53bafebe3b79de2e3e01cbd8169ddbb08bde888dcc893524
-keccak_384('中文');
+keccak384('中文');
// 743f64bb7544c6ed923be4741b738dde18b7cee384a3a09c4e01acaaac9f19222cdee137702bd3aa05dc198373d87d6c
-keccak_256('中文');
+keccak256('中文');
// 70a2b6579047f0a977fcb5e9120a4e07067bea9abb6916fbc2d13ffb9a4e4eee
-keccak_224('中文');
+keccak224('中文');
// f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd
```
diff --git a/bower.json b/bower.json
index c264ffc..922cd2e 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "js-sha3",
- "version": "0.5.7",
+ "version": "0.6.0",
"main": ["src/sha3.js"],
"ignore": [
"samples",
diff --git a/build/sha3.min.js b/build/sha3.min.js
index 3d74878..2f02fa9 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.5.7
+ * @version 0.6.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
- * @copyright Chen, Yi-Cyuan 2015-2016
+ * @copyright Chen, Yi-Cyuan 2015-2017
* @license MIT
*/
-!function(){"use strict";function t(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,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 o=0;50>o;++o)this.s[o]=0}var e="object"==typeof window?window:{},r=!e.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;r&&(e=global);for(var o=!e.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,s="0123456789abcdef".split(""),i=[31,7936,2031616,520093696],n=[1,256,65536,16777216],a=[6,1536,393216,100663296],u=[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],f=[224,256,384,512],c=[128,256],p=["hex","buffer","arrayBuffer","array"],l=function(e,r,o){return function(s){return new t(e,r,e).update(s)[o]()}},d=function(e,r,o){return function(s,i){return new t(e,r,i).update(s)[o]()}},y=function(e,r){var o=l(e,r,"hex");o.create=function(){return new t(e,r,e)},o.update=function(t){return o.create().update(t)};for(var s=0;s
h;){if(this.reset)for(this.reset=!1,i[0]=this.block,r=1;a+1>r;++r)i[r]=0;if(e)for(r=this.start;s>h&&n>r;++h)i[r>>2]|=t[h]<h&&n>r;++h)o=t.charCodeAt(h),128>o?i[r>>2]|=o<o?(i[r>>2]|=(192|o>>6)<>2]|=(128|63&o)<o||o>=57344?(i[r>>2]|=(224|o>>12)<>2]|=(128|o>>6&63)<>2]|=(128|63&o)<>2]|=(240|o>>18)<>2]|=(128|o>>12&63)<>2]|=(128|o>>6&63)<>2]|=(128|63&o)<=n){for(this.start=r-n,this.block=i[a],r=0;a>r;++r)f[r]^=i[r];A(f),this.reset=!0}else this.start=r}return this},t.prototype.finalize=function(){var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,o=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;r+1>e;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;r>e;++e)o[e]^=t[e];A(o)},t.prototype.toString=t.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,o=this.outputBlocks,i=this.extraBytes,n=0,a=0,u="";o>a;){for(n=0;e>n&&o>a;++n,++a)t=r[n],u+=s[t>>4&15]+s[15&t]+s[t>>12&15]+s[t>>8&15]+s[t>>20&15]+s[t>>16&15]+s[t>>28&15]+s[t>>24&15];a%e===0&&(A(r),n=0)}return i&&(t=r[n],i>0&&(u+=s[t>>4&15]+s[15&t]),i>1&&(u+=s[t>>12&15]+s[t>>8&15]),i>2&&(u+=s[t>>20&15]+s[t>>16&15])),u},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,o=this.outputBlocks,s=this.extraBytes,i=0,n=0,a=this.outputBits>>3;t=new ArrayBuffer(s?o+1<<2:a);for(var u=new Uint32Array(t);o>n;){for(i=0;e>i&&o>n;++i,++n)u[n]=r[i];n%e===0&&A(r)}return s&&(u[i]=r[i],t=t.slice(0,a)),t},t.prototype.buffer=t.prototype.arrayBuffer,t.prototype.digest=t.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,o=this.s,s=this.outputBlocks,i=this.extraBytes,n=0,a=0,u=[];s>a;){for(n=0;r>n&&s>a;++n,++a)t=a<<2,e=o[n],u[t]=255&e,u[t+1]=e>>8&255,u[t+2]=e>>16&255,u[t+3]=e>>24&255;a%r===0&&A(o)}return i&&(t=a<<2,e=o[n],i>0&&(u[t]=255&e),i>1&&(u[t+1]=e>>8&255),i>2&&(u[t+2]=e>>16&255)),u};var A=function(t){var e,r,o,s,i,n,a,u,f,c,p,l,d,y,b,v,k,B,g,x,C,w,_,A,m,S,M,O,z,J,N,j,I,H,U,D,E,q,F,G,K,L,P,Q,R,T,V,W,X,Y,Z,$,tt,et,rt,ot,st,it,nt,at,ut,ht,ft;for(o=0;48>o;o+=2)s=t[0]^t[10]^t[20]^t[30]^t[40],i=t[1]^t[11]^t[21]^t[31]^t[41],n=t[2]^t[12]^t[22]^t[32]^t[42],a=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],l=t[8]^t[18]^t[28]^t[38]^t[48],d=t[9]^t[19]^t[29]^t[39]^t[49],e=l^(n<<1|a>>>31),r=d^(a<<1|n>>>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=s^(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=n^(c<<1|p>>>31),r=a^(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^(l<<1|d>>>31),r=f^(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=c^(s<<1|i>>>31),r=p^(i<<1|s>>>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],T=t[11]<<4|t[10]>>>28,V=t[10]<<4|t[11]>>>28,O=t[20]<<3|t[21]>>>29,z=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,ut=t[30]<<9|t[31]>>>23,L=t[40]<<18|t[41]>>>14,P=t[41]<<18|t[40]>>>14,H=t[2]<<1|t[3]>>>31,U=t[3]<<1|t[2]>>>31,v=t[13]<<12|t[12]>>>20,k=t[12]<<12|t[13]>>>20,W=t[22]<<10|t[23]>>>22,X=t[23]<<10|t[22]>>>22,J=t[33]<<13|t[32]>>>19,N=t[32]<<13|t[33]>>>19,ht=t[42]<<2|t[43]>>>30,ft=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,D=t[14]<<6|t[15]>>>26,E=t[15]<<6|t[14]>>>26,B=t[25]<<11|t[24]>>>21,g=t[24]<<11|t[25]>>>21,Y=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,j=t[45]<<29|t[44]>>>3,I=t[44]<<29|t[45]>>>3,A=t[6]<<28|t[7]>>>4,m=t[7]<<28|t[6]>>>4,ot=t[17]<<23|t[16]>>>9,st=t[16]<<23|t[17]>>>9,q=t[26]<<25|t[27]>>>7,F=t[27]<<25|t[26]>>>7,x=t[36]<<21|t[37]>>>11,C=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,R=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,M=t[19]<<20|t[18]>>>12,it=t[29]<<7|t[28]>>>25,nt=t[28]<<7|t[29]>>>25,G=t[38]<<8|t[39]>>>24,K=t[39]<<8|t[38]>>>24,w=t[48]<<14|t[49]>>>18,_=t[49]<<14|t[48]>>>18,t[0]=y^~v&B,t[1]=b^~k&g,t[10]=A^~S&O,t[11]=m^~M&z,t[20]=H^~D&q,t[21]=U^~E&F,t[30]=Q^~T&W,t[31]=R^~V&X,t[40]=et^~ot&it,t[41]=rt^~st&nt,t[2]=v^~B&x,t[3]=k^~g&C,t[12]=S^~O&J,t[13]=M^~z&N,t[22]=D^~q&G,t[23]=E^~F&K,t[32]=T^~W&Y,t[33]=V^~X&Z,t[42]=ot^~it&at,t[43]=st^~nt&ut,t[4]=B^~x&w,t[5]=g^~C&_,t[14]=O^~J&j,t[15]=z^~N&I,t[24]=q^~G&L,t[25]=F^~K&P,t[34]=W^~Y&$,t[35]=X^~Z&tt,t[44]=it^~at&ht,t[45]=nt^~ut&ft,t[6]=x^~w&y,t[7]=C^~_&b,t[16]=J^~j&A,t[17]=N^~I&m,t[26]=G^~L&H,t[27]=K^~P&U,t[36]=Y^~$&Q,t[37]=Z^~tt&R,t[46]=at^~ht&et,t[47]=ut^~ft&rt,t[8]=w^~y&v,t[9]=_^~b&k,t[18]=j^~A&S,t[19]=I^~m&M,t[28]=L^~H&D,t[29]=P^~U&E,t[38]=$^~Q&T,t[39]=tt^~R&V,t[48]=ht^~et&ot,t[49]=ft^~rt&st,t[0]^=h[o],t[1]^=h[o+1]};if(o)module.exports=k;else for(var g=0;g>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;50>n;++n)this.s[n]=0}function e(e,r,n){t.call(this,e,r,n)}var r="object"==typeof window?window:{},n=!r.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;n&&(r=global);var o=!r.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,i=!r.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,a="0123456789abcdef".split(""),s=[31,7936,2031616,520093696],u=[4,1024,262144,67108864],f=[1,256,65536,16777216],c=[6,1536,393216,100663296],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],y=[128,256],l=["hex","buffer","arrayBuffer","array"],b={128:168,256:136};(r.JS_SHA3_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)});for(var v=function(e,r,n){return function(o){return new t(e,r,e).update(o)[n]()}},A=function(e,r,n){return function(o,i){return new t(e,r,i).update(o)[n]()}},g=function(t,e,r){return function(e,n,o,i){return S["cshake"+t].update(e,n,o,i)[r]()}},k=function(t,e,r){return function(e,n,o,i){return S["kmac"+t].update(e,n,o,i)[r]()}},B=function(t,e,r,n){for(var o=0;oc;){if(this.reset)for(this.reset=!1,s[0]=this.block,o=1;f+1>o;++o)s[o]=0;if(e)for(o=this.start;n>c&&u>o;++c)s[o>>2]|=t[c]<c&&u>o;++c)a=t.charCodeAt(c),128>a?s[o>>2]|=a<a?(s[o>>2]|=(192|a>>6)<>2]|=(128|63&a)<a||a>=57344?(s[o>>2]|=(224|a>>12)<>2]|=(128|a>>6&63)<>2]|=(128|63&a)<>2]|=(240|a>>18)<>2]|=(128|a>>12&63)<>2]|=(128|a>>6&63)<>2]|=(128|63&a)<=u){for(this.start=o-u,this.block=s[f],o=0;f>o;++o)p[o]^=s[o];U(p),this.reset=!0}else this.start=o}return this},t.prototype.encode=function(t,e){var r=255&t,n=1,o=[r];for(t>>=8,r=255&t;r>0;)o.unshift(r),t>>=8,r=255&t,++n;return e?o.push(n):o.unshift(n),this.update(o),o.length},t.prototype.encodeString=function(t){t=t||"";var e="string"!=typeof t;e&&t.constructor===r.ArrayBuffer&&(t=new Uint8Array(t));var n=t.length;if(!(!e||"number"==typeof n&&(Array.isArray(t)||i&&ArrayBuffer.isView(t))))throw"input is invalid type";var o=0;if(e)o=n;else for(var a=0;as?o+=1:2048>s?o+=2:55296>s||s>=57344?o+=3:(s=65536+((1023&s)<<10|1023&t.charCodeAt(++a)),o+=4)}return o+=this.encode(8*o),this.update(t),o},t.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;r+1>e;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;r>e;++e)n[e]^=t[e];U(n)},t.prototype.toString=t.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,o=this.extraBytes,i=0,s=0,u="";n>s;){for(i=0;e>i&&n>s;++i,++s)t=r[i],u+=a[t>>4&15]+a[15&t]+a[t>>12&15]+a[t>>8&15]+a[t>>20&15]+a[t>>16&15]+a[t>>28&15]+a[t>>24&15];s%e===0&&(U(r),i=0)}return o&&(t=r[i],o>0&&(u+=a[t>>4&15]+a[15&t]),o>1&&(u+=a[t>>12&15]+a[t>>8&15]),o>2&&(u+=a[t>>20&15]+a[t>>16&15])),u},t.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=new ArrayBuffer(o?n+1<<2:s);for(var u=new Uint32Array(t);n>a;){for(i=0;e>i&&n>a;++i,++a)u[a]=r[i];a%e===0&&U(r)}return o&&(u[i]=r[i],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,o=this.outputBlocks,i=this.extraBytes,a=0,s=0,u=[];o>s;){for(a=0;r>a&&o>s;++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&&U(n)}return i&&(t=s<<2,e=n[a],i>0&&(u[t]=255&e),i>1&&(u[t+1]=e>>8&255),i>2&&(u[t+2]=e>>16&255)),u},e.prototype=new t,e.prototype.finalize=function(){return this.encode(this.outputBits,!0),t.prototype.finalize.call(this)};var U=function(t){var e,r,n,o,i,a,s,u,f,c,h,d,y,l,b,v,A,g,k,B,w,_,C,m,x,S,M,O,J,N,z,j,H,U,E,I,R,D,F,V,K,Y,q,G,L,P,Q,T,W,X,Z,$,tt,et,rt,nt,ot,it,at,st,ut,ft,ct;for(n=0;48>n;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],h=t[7]^t[17]^t[27]^t[37]^t[47],d=t[8]^t[18]^t[28]^t[38]^t[48],y=t[9]^t[19]^t[29]^t[39]^t[49],e=d^(a<<1|s>>>31),r=y^(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|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|y>>>31),r=f^(y<<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=h^(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,l=t[0],b=t[1],P=t[11]<<4|t[10]>>>28,Q=t[10]<<4|t[11]>>>28,O=t[20]<<3|t[21]>>>29,J=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,q=t[41]<<18|t[40]>>>14,U=t[2]<<1|t[3]>>>31,E=t[3]<<1|t[2]>>>31,v=t[13]<<12|t[12]>>>20,A=t[12]<<12|t[13]>>>20,T=t[22]<<10|t[23]>>>22,W=t[23]<<10|t[22]>>>22,N=t[33]<<13|t[32]>>>19,z=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,I=t[14]<<6|t[15]>>>26,R=t[15]<<6|t[14]>>>26,g=t[25]<<11|t[24]>>>21,k=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,H=t[44]<<29|t[45]>>>3,m=t[6]<<28|t[7]>>>4,x=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,ot=t[16]<<23|t[17]>>>9,D=t[26]<<25|t[27]>>>7,F=t[27]<<25|t[26]>>>7,B=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,G=t[8]<<27|t[9]>>>5,L=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,M=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,K=t[39]<<8|t[38]>>>24,_=t[48]<<14|t[49]>>>18,C=t[49]<<14|t[48]>>>18,t[0]=l^~v&g,t[1]=b^~A&k,t[10]=m^~S&O,t[11]=x^~M&J,t[20]=U^~I&D,t[21]=E^~R&F,t[30]=G^~P&T,t[31]=L^~Q&W,t[40]=et^~nt&it,t[41]=rt^~ot&at,t[2]=v^~g&B,t[3]=A^~k&w,t[12]=S^~O&N,t[13]=M^~J&z,t[22]=I^~D&V,t[23]=R^~F&K,t[32]=P^~T&X,t[33]=Q^~W&Z,t[42]=nt^~it&st,t[43]=ot^~at&ut,t[4]=g^~B&_,t[5]=k^~w&C,t[14]=O^~N&j,t[15]=J^~z&H,t[24]=D^~V&Y,t[25]=F^~K&q,t[34]=T^~X&$,t[35]=W^~Z&tt,t[44]=it^~st&ft,t[45]=at^~ut&ct,t[6]=B^~_&l,t[7]=w^~C&b,t[16]=N^~j&m,t[17]=z^~H&x,t[26]=V^~Y&U,t[27]=K^~q&E,t[36]=X^~$&G,t[37]=Z^~tt&L,t[46]=st^~ft&et,t[47]=ut^~ct&rt,t[8]=_^~l&v,t[9]=C^~b&A,t[18]=j^~m&S,t[19]=H^~x&M,t[28]=Y^~U&I,t[29]=q^~E&R,t[38]=$^~G&P,t[39]=tt^~L&Q,t[48]=ft^~et&nt,t[49]=ct^~rt&ot,t[0]^=p[n],t[1]^=p[n+1]};if(o)module.exports=S;else for(var O=0;O> 8;
+ o = x & 255;
+ while (o > 0) {
+ bytes.unshift(o);
+ x = x >> 8;
+ o = x & 255;
+ ++n;
+ }
+ if (right) {
+ bytes.push(n);
+ } else {
+ bytes.unshift(n);
+ }
+ this.update(bytes);
+ return bytes.length;
+ };
+
+ Keccak.prototype.encodeString = function (str) {
+ str = str || '';
+ var notString = typeof str !== 'string';
+ if (notString && str.constructor === root.ArrayBuffer) {
+ str = new Uint8Array(str);
+ }
+ var length = str.length;
+ if (notString) {
+ if (typeof length !== 'number' ||
+ !Array.isArray(str) &&
+ !(ARRAY_BUFFER && ArrayBuffer.isView(str))) {
+ throw 'input is invalid type';
+ }
+ }
+ var bytes = 0;
+ if (notString) {
+ bytes = length;
+ } else {
+ for (var i = 0; i < str.length; ++i) {
+ var code = str.charCodeAt(i);
+ if (code < 0x80) {
+ bytes += 1;
+ } else if (code < 0x800) {
+ bytes += 2;
+ } else if (code < 0xd800 || code >= 0xe000) {
+ bytes += 3;
+ } else {
+ code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
+ bytes += 4;
+ }
+ }
+ }
+ bytes += this.encode(bytes * 8);
+ this.update(str);
+ return bytes;
+ };
+
+ Keccak.prototype.bytepad = function (strs, w) {
+ var bytes = this.encode(w);
+ for (var i = 0;i < strs.length;++i) {
+ bytes += this.encodeString(strs[i]);
+ }
+ var paddingBytes = w - bytes % w;
+ var zeros = [];
+ zeros.length = paddingBytes;
+ this.update(zeros);
+ return this;
+ };
+
Keccak.prototype.finalize = function () {
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
blocks[i >> 2] |= this.padding[i & 3];
@@ -280,6 +416,17 @@
return array;
};
+ function Kmac(bits, padding, outputBits) {
+ Keccak.call(this, bits, padding, outputBits);
+ }
+
+ Kmac.prototype = new Keccak();
+
+ Kmac.prototype.finalize = function () {
+ this.encode(this.outputBits, true);
+ return Keccak.prototype.finalize.call(this);
+ };
+
var f = function (s) {
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
diff --git a/tests/index.html b/tests/index.html
index 7f46290..9a8121e 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -15,6 +15,8 @@
+
+