js-sha3 0.5.3 → 0.5.7
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/.covignore +1 -1
- package/.npmignore +3 -2
- package/CHANGELOG.md +74 -50
- package/README.md +10 -2
- package/bower.json +9 -9
- package/build/sha3.min.js +8 -21
- package/index.d.ts +92 -0
- package/package.json +39 -34
- package/src/sha3.js +475 -470
- package/tests/node-test.js +28 -1
- package/tests/test.js +316 -313
package/.covignore
CHANGED
package/.npmignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
covreporter
|
|
1
|
+
/node_modules/
|
|
2
|
+
/covreporter/
|
|
3
|
+
/my_test/
|
package/CHANGELOG.md
CHANGED
|
@@ -1,50 +1,74 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
## v0.5.7 / 2016-12-30
|
|
4
|
+
### Fixed
|
|
5
|
+
- ArrayBuffer detection in old browsers.
|
|
6
|
+
|
|
7
|
+
## v0.5.6 / 2016-12-29
|
|
8
|
+
### Fixed
|
|
9
|
+
- ArrayBuffer dosen't work in Webpack.
|
|
10
|
+
|
|
11
|
+
## v0.5.5 / 2016-09-26
|
|
12
|
+
### Added
|
|
13
|
+
- TypeScript support.
|
|
14
|
+
- ArrayBuffer method.
|
|
15
|
+
### Deprecated
|
|
16
|
+
- Buffer method.
|
|
17
|
+
|
|
18
|
+
## v0.5.4 / 2016-09-12
|
|
19
|
+
### Fixed
|
|
20
|
+
- CommonJS detection.
|
|
21
|
+
|
|
22
|
+
## v0.5.3 / 2016-09-08
|
|
23
|
+
### Added
|
|
24
|
+
- Some missing files to npm package.
|
|
25
|
+
|
|
26
|
+
## v0.5.2 / 2016-06-06
|
|
27
|
+
### Fixed
|
|
28
|
+
- Shake output incorrect in the special length.
|
|
29
|
+
|
|
30
|
+
## v0.5.1 / 2015-10-27
|
|
31
|
+
### Fixed
|
|
32
|
+
- Version in package.json and bower.json.
|
|
33
|
+
|
|
34
|
+
## v0.5.0 / 2015-09-23
|
|
35
|
+
### Added
|
|
36
|
+
- Hash object with create/update interface.
|
|
37
|
+
|
|
38
|
+
## v0.4.1 / 2015-09-18
|
|
39
|
+
### Added
|
|
40
|
+
- Integer array output.
|
|
41
|
+
### Fixed
|
|
42
|
+
- Shake output incorrect when it's greater than 1088.
|
|
43
|
+
|
|
44
|
+
## v0.4.0 / 2015-09-17
|
|
45
|
+
### Added
|
|
46
|
+
- ArrayBuffer output.
|
|
47
|
+
- Shake alogirthms.
|
|
48
|
+
|
|
49
|
+
## v0.3.1 / 2015-05-22
|
|
50
|
+
### Fixed
|
|
51
|
+
- Some bugs.
|
|
52
|
+
|
|
53
|
+
## v0.3.0 / 2015-05-21
|
|
54
|
+
### Added
|
|
55
|
+
- Integer array input.
|
|
56
|
+
- ArrayBuffer input.
|
|
57
|
+
|
|
58
|
+
## v0.2.0 / 2015-04-04
|
|
59
|
+
### Added
|
|
60
|
+
- NIST's May 2014 SHA-3 version.
|
|
61
|
+
### Changed
|
|
62
|
+
- Rename original methods to keccak.
|
|
63
|
+
|
|
64
|
+
## v0.1.2 / 2015-02-27
|
|
65
|
+
### Changed
|
|
66
|
+
- Improve performance.
|
|
67
|
+
|
|
68
|
+
## v0.1.1 / 2015-02-26
|
|
69
|
+
### Changed
|
|
70
|
+
- Improve performance.
|
|
71
|
+
|
|
72
|
+
## v0.1.0 / 2015-02-23
|
|
73
|
+
### Added
|
|
74
|
+
- First version implementation.
|
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# js-sha3
|
|
2
2
|
|
|
3
3
|
[](https://travis-ci.org/emn178/js-sha3)
|
|
4
|
-
[](https://coveralls.io/r/emn178/js-sha3?branch=master)
|
|
4
|
+
[](https://coveralls.io/r/emn178/js-sha3?branch=master)
|
|
5
|
+
[](https://nodei.co/npm/js-sha3/)
|
|
5
6
|
|
|
6
7
|
A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.
|
|
7
8
|
|
|
8
9
|
## Notice
|
|
9
|
-
Sha3 methods has been renamed to keccak since v0.2.0. It means that sha3 methods of v0.1.x are equal to keccak methods of v0.2.x and later.
|
|
10
|
+
* Sha3 methods has been renamed to keccak since v0.2.0. It means that sha3 methods of v0.1.x are equal to keccak methods of v0.2.x and later.
|
|
11
|
+
* `buffer` method is deprecated. This maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
|
|
10
12
|
|
|
11
13
|
## Demo
|
|
12
14
|
[SHA3-512 Online](http://emn178.github.io/online-tools/sha3_512.html)
|
|
@@ -17,6 +19,8 @@ Sha3 methods has been renamed to keccak since v0.2.0. It means that sha3 methods
|
|
|
17
19
|
[Keccak-384 Online](http://emn178.github.io/online-tools/keccak_384.html)
|
|
18
20
|
[Keccak-256 Online](http://emn178.github.io/online-tools/keccak_256.html)
|
|
19
21
|
[Keccak-224 Online](http://emn178.github.io/online-tools/keccak_224.html)
|
|
22
|
+
[Shake-128 Online](http://emn178.github.io/online-tools/shake_128.html)
|
|
23
|
+
[Shake-256 Online](http://emn178.github.io/online-tools/shake_256.html)
|
|
20
24
|
|
|
21
25
|
## Download
|
|
22
26
|
[Compress](https://raw.github.com/emn178/js-sha3/master/build/sha3.min.js)
|
|
@@ -81,6 +85,10 @@ keccak_224 = require('js-sha3').keccak_224;
|
|
|
81
85
|
shake_128 = require('js-sha3').shake_128;
|
|
82
86
|
shake_256 = require('js-sha3').shake_256;
|
|
83
87
|
```
|
|
88
|
+
If you use TypeScript, you can import like this:
|
|
89
|
+
```TypeScript
|
|
90
|
+
import { sha3_512 } from 'js-sha3';
|
|
91
|
+
```
|
|
84
92
|
|
|
85
93
|
## Example
|
|
86
94
|
Code
|
package/bower.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "js-sha3",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"main": ["src/sha3.js"],
|
|
5
|
-
"ignore": [
|
|
6
|
-
"samples",
|
|
7
|
-
"tests"
|
|
8
|
-
]
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "js-sha3",
|
|
3
|
+
"version": "0.5.7",
|
|
4
|
+
"main": ["src/sha3.js"],
|
|
5
|
+
"ignore": [
|
|
6
|
+
"samples",
|
|
7
|
+
"tests"
|
|
8
|
+
]
|
|
9
|
+
}
|
package/build/sha3.min.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
|
-
*
|
|
4
|
-
* @version 0.5.
|
|
5
|
-
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
|
-
* @copyright Chen, Yi-Cyuan 2015-2016
|
|
7
|
-
* @license MIT
|
|
1
|
+
/**
|
|
2
|
+
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
|
+
*
|
|
4
|
+
* @version 0.5.7
|
|
5
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
|
+
* @copyright Chen, Yi-Cyuan 2015-2016
|
|
7
|
+
* @license MIT
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
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],t=[224,256,384,512],w=["hex","buffer","array"],ia=function(a,b,c){return function(e){return(new n(a,b,a)).update(e)[c]()}},ja=function(a,b,c){return function(e,g){return(new n(a,b,g)).update(e)[c]()}},q=function(a,b){var c=ia(a,b,"hex");c.create=function(){return new n(a,
|
|
11
|
-
b,a)};c.update=function(a){return c.create().update(a)};for(var e=0;e<w.length;++e){var g=w[e];c[g]=ia(a,b,g)}return c},t=[{name:"keccak",padding:[1,256,65536,16777216],bits:t,createMethod:q},{name:"sha3",padding:[6,1536,393216,100663296],bits:t,createMethod:q},{name:"shake",padding:[31,7936,2031616,520093696],bits:[128,256],createMethod:function(a,b){var c=ja(a,b,"hex");c.create=function(c){return new n(a,b,c)};c.update=function(a,b){return c.create(b).update(a)};for(var e=0;e<w.length;++e){var g=
|
|
12
|
-
w[e];c[g]=ja(a,b,g)}return c}}],x={},ea=0;ea<t.length;++ea)for(var u=t[ea],fa=u.bits,q=u.createMethod,q=0;q<fa.length;++q){var la=u.createMethod(fa[q],u.padding);x[u.name+"_"+fa[q]]=la}n.prototype.update=function(a){var b="string"!=typeof a;b&&a.constructor==r.ArrayBuffer&&(a=new Uint8Array(a));for(var c=a.length,e=this.blocks,g=this.byteCount,k=this.blockCount,h=0,f=this.s,d,m;h<c;){if(this.reset)for(this.reset=!1,e[0]=this.block,d=1;d<k+1;++d)e[d]=0;if(b)for(d=this.start;h<c&&d<g;++h)e[d>>2]|=a[h]<<
|
|
13
|
-
p[d++&3];else for(d=this.start;h<c&&d<g;++h)m=a.charCodeAt(h),128>m?e[d>>2]|=m<<p[d++&3]:(2048>m?e[d>>2]|=(192|m>>6)<<p[d++&3]:(55296>m||57344<=m?e[d>>2]|=(224|m>>12)<<p[d++&3]:(m=65536+((m&1023)<<10|a.charCodeAt(++h)&1023),e[d>>2]|=(240|m>>18)<<p[d++&3],e[d>>2]|=(128|m>>12&63)<<p[d++&3]),e[d>>2]|=(128|m>>6&63)<<p[d++&3]),e[d>>2]|=(128|m&63)<<p[d++&3]);this.lastByteIndex=d;if(d>=g){this.start=d-g;this.block=e[k];for(d=0;d<k;++d)f[d]^=e[d];v(f);this.reset=!0}else this.start=d}return this};n.prototype.finalize=
|
|
14
|
-
function(){var a=this.blocks,b=this.lastByteIndex,c=this.blockCount,e=this.s;a[b>>2]|=this.padding[b&3];if(this.lastByteIndex==this.byteCount)for(a[0]=a[c],b=1;b<c+1;++b)a[b]=0;a[c-1]|=2147483648;for(b=0;b<c;++b)e[b]^=a[b];v(e)};n.prototype.toString=n.prototype.hex=function(){this.finalize();for(var a=this.blockCount,b=this.s,c=this.outputBlocks,e=this.extraBytes,g=0,k=0,h="",f;k<c;){for(g=0;g<a&&k<c;++g,++k)f=b[g],h+=l[f>>4&15]+l[f&15]+l[f>>12&15]+l[f>>8&15]+l[f>>20&15]+l[f>>16&15]+l[f>>28&15]+l[f>>
|
|
15
|
-
24&15];0==k%a&&(v(b),g=0)}e&&(f=b[g],0<e&&(h+=l[f>>4&15]+l[f&15]),1<e&&(h+=l[f>>12&15]+l[f>>8&15]),2<e&&(h+=l[f>>20&15]+l[f>>16&15]));return h};n.prototype.buffer=function(){this.finalize();var a=this.blockCount,b=this.s,c=this.outputBlocks,e=this.extraBytes,g=0,k=0,h=this.outputBits>>3,f;f=e?new ArrayBuffer(c+1<<2):new ArrayBuffer(h);for(var d=new Uint32Array(f);k<c;){for(g=0;g<a&&k<c;++g,++k)d[k]=b[g];0==k%a&&v(b)}e&&(d[g]=b[g],f=f.slice(0,h));return f};n.prototype.digest=n.prototype.array=function(){this.finalize();
|
|
16
|
-
for(var a=this.blockCount,b=this.s,c=this.outputBlocks,e=this.extraBytes,g=0,k=0,h=[],f,d;k<c;){for(g=0;g<a&&k<c;++g,++k)f=k<<2,d=b[g],h[f]=d&255,h[f+1]=d>>8&255,h[f+2]=d>>16&255,h[f+3]=d>>24&255;0==k%a&&v(b)}e&&(f=k<<2,d=b[g],0<e&&(h[f]=d&255),1<e&&(h[f+1]=d>>8&255),2<e&&(h[f+2]=d>>16&255));return h};var v=function(a){var b,c,e,g,k,h,f,d,m,l,n,p,q,r,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ba,ca,da;for(e=0;48>e;e+=2)g=a[0]^a[10]^a[20]^a[30]^a[40],k=a[1]^a[11]^a[21]^a[31]^
|
|
17
|
-
a[41],h=a[2]^a[12]^a[22]^a[32]^a[42],f=a[3]^a[13]^a[23]^a[33]^a[43],d=a[4]^a[14]^a[24]^a[34]^a[44],m=a[5]^a[15]^a[25]^a[35]^a[45],l=a[6]^a[16]^a[26]^a[36]^a[46],n=a[7]^a[17]^a[27]^a[37]^a[47],p=a[8]^a[18]^a[28]^a[38]^a[48],q=a[9]^a[19]^a[29]^a[39]^a[49],b=p^(h<<1|f>>>31),c=q^(f<<1|h>>>31),a[0]^=b,a[1]^=c,a[10]^=b,a[11]^=c,a[20]^=b,a[21]^=c,a[30]^=b,a[31]^=c,a[40]^=b,a[41]^=c,b=g^(d<<1|m>>>31),c=k^(m<<1|d>>>31),a[2]^=b,a[3]^=c,a[12]^=b,a[13]^=c,a[22]^=b,a[23]^=c,a[32]^=b,a[33]^=c,a[42]^=b,a[43]^=c,
|
|
18
|
-
b=h^(l<<1|n>>>31),c=f^(n<<1|l>>>31),a[4]^=b,a[5]^=c,a[14]^=b,a[15]^=c,a[24]^=b,a[25]^=c,a[34]^=b,a[35]^=c,a[44]^=b,a[45]^=c,b=d^(p<<1|q>>>31),c=m^(q<<1|p>>>31),a[6]^=b,a[7]^=c,a[16]^=b,a[17]^=c,a[26]^=b,a[27]^=c,a[36]^=b,a[37]^=c,a[46]^=b,a[47]^=c,b=l^(g<<1|k>>>31),c=n^(k<<1|g>>>31),a[8]^=b,a[9]^=c,a[18]^=b,a[19]^=c,a[28]^=b,a[29]^=c,a[38]^=b,a[39]^=c,a[48]^=b,a[49]^=c,b=a[0],c=a[1],M=a[11]<<4|a[10]>>>28,N=a[10]<<4|a[11]>>>28,u=a[20]<<3|a[21]>>>29,v=a[21]<<3|a[20]>>>29,aa=a[31]<<9|a[30]>>>23,ba=a[30]<<
|
|
19
|
-
9|a[31]>>>23,I=a[40]<<18|a[41]>>>14,J=a[41]<<18|a[40]>>>14,A=a[2]<<1|a[3]>>>31,B=a[3]<<1|a[2]>>>31,g=a[13]<<12|a[12]>>>20,k=a[12]<<12|a[13]>>>20,O=a[22]<<10|a[23]>>>22,P=a[23]<<10|a[22]>>>22,w=a[33]<<13|a[32]>>>19,x=a[32]<<13|a[33]>>>19,ca=a[42]<<2|a[43]>>>30,da=a[43]<<2|a[42]>>>30,U=a[5]<<30|a[4]>>>2,V=a[4]<<30|a[5]>>>2,C=a[14]<<6|a[15]>>>26,D=a[15]<<6|a[14]>>>26,h=a[25]<<11|a[24]>>>21,f=a[24]<<11|a[25]>>>21,Q=a[34]<<15|a[35]>>>17,R=a[35]<<15|a[34]>>>17,y=a[45]<<29|a[44]>>>3,z=a[44]<<29|a[45]>>>
|
|
20
|
-
3,p=a[6]<<28|a[7]>>>4,q=a[7]<<28|a[6]>>>4,W=a[17]<<23|a[16]>>>9,X=a[16]<<23|a[17]>>>9,E=a[26]<<25|a[27]>>>7,F=a[27]<<25|a[26]>>>7,d=a[36]<<21|a[37]>>>11,m=a[37]<<21|a[36]>>>11,S=a[47]<<24|a[46]>>>8,T=a[46]<<24|a[47]>>>8,K=a[8]<<27|a[9]>>>5,L=a[9]<<27|a[8]>>>5,r=a[18]<<20|a[19]>>>12,t=a[19]<<20|a[18]>>>12,Y=a[29]<<7|a[28]>>>25,Z=a[28]<<7|a[29]>>>25,G=a[38]<<8|a[39]>>>24,H=a[39]<<8|a[38]>>>24,l=a[48]<<14|a[49]>>>18,n=a[49]<<14|a[48]>>>18,a[0]=b^~g&h,a[1]=c^~k&f,a[10]=p^~r&u,a[11]=q^~t&v,a[20]=A^~C&
|
|
21
|
-
E,a[21]=B^~D&F,a[30]=K^~M&O,a[31]=L^~N&P,a[40]=U^~W&Y,a[41]=V^~X&Z,a[2]=g^~h&d,a[3]=k^~f&m,a[12]=r^~u&w,a[13]=t^~v&x,a[22]=C^~E&G,a[23]=D^~F&H,a[32]=M^~O&Q,a[33]=N^~P&R,a[42]=W^~Y&aa,a[43]=X^~Z&ba,a[4]=h^~d&l,a[5]=f^~m&n,a[14]=u^~w&y,a[15]=v^~x&z,a[24]=E^~G&I,a[25]=F^~H&J,a[34]=O^~Q&S,a[35]=P^~R&T,a[44]=Y^~aa&ca,a[45]=Z^~ba&da,a[6]=d^~l&b,a[7]=m^~n&c,a[16]=w^~y&p,a[17]=x^~z&q,a[26]=G^~I&A,a[27]=H^~J&B,a[36]=Q^~S&K,a[37]=R^~T&L,a[46]=aa^~ca&U,a[47]=ba^~da&V,a[8]=l^~b&g,a[9]=n^~c&k,a[18]=y^~p&r,a[19]=
|
|
22
|
-
z^~q&t,a[28]=I^~A&C,a[29]=J^~B&D,a[38]=S^~K&M,a[39]=T^~L&N,a[48]=ca^~U&W,a[49]=da^~V&X,a[0]^=ha[e],a[1]^=ha[e+1]};if(!r.JS_SHA3_TEST&&ga)module.exports=x;else if(r)for(var ka in x)r[ka]=x[ka]})(this);
|
|
9
|
+
!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<p.length;++s){var i=p[s];o[i]=l(e,r,i)}return o},b=function(e,r){var o=d(e,r,"hex");o.create=function(o){return new t(e,r,o)},o.update=function(t,e){return o.create(e).update(t)};for(var s=0;s<p.length;++s){var i=p[s];o[i]=d(e,r,i)}return o},v=[{name:"keccak",padding:n,bits:f,createMethod:y},{name:"sha3",padding:a,bits:f,createMethod:y},{name:"shake",padding:i,bits:c,createMethod:b}],k={},B=[],g=0;g<v.length;++g)for(var x=v[g],C=x.bits,w=0;w<C.length;++w){var _=x.name+"_"+C[w];B.push(_),k[_]=x.createMethod(C[w],x.padding)}t.prototype.update=function(t){var e="string"!=typeof t;e&&t.constructor===ArrayBuffer&&(t=new Uint8Array(t));for(var r,o,s=t.length,i=this.blocks,n=this.byteCount,a=this.blockCount,h=0,f=this.s;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]<<u[3&r++];else for(r=this.start;s>h&&n>r;++h)o=t.charCodeAt(h),128>o?i[r>>2]|=o<<u[3&r++]:2048>o?(i[r>>2]|=(192|o>>6)<<u[3&r++],i[r>>2]|=(128|63&o)<<u[3&r++]):55296>o||o>=57344?(i[r>>2]|=(224|o>>12)<<u[3&r++],i[r>>2]|=(128|o>>6&63)<<u[3&r++],i[r>>2]|=(128|63&o)<<u[3&r++]):(o=65536+((1023&o)<<10|1023&t.charCodeAt(++h)),i[r>>2]|=(240|o>>18)<<u[3&r++],i[r>>2]|=(128|o>>12&63)<<u[3&r++],i[r>>2]|=(128|o>>6&63)<<u[3&r++],i[r>>2]|=(128|63&o)<<u[3&r++]);if(this.lastByteIndex=r,r>=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<B.length;++g)e[B[g]]=k[B[g]]}();
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
type Message = string | number[] | ArrayBuffer | Uint8Array;
|
|
2
|
+
|
|
3
|
+
interface Hasher {
|
|
4
|
+
/**
|
|
5
|
+
* Update hash
|
|
6
|
+
*
|
|
7
|
+
* @param message The message you want to hash.
|
|
8
|
+
*/
|
|
9
|
+
update(message: Message): Hasher;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Return hash in hex string.
|
|
13
|
+
*/
|
|
14
|
+
hex(): string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Return hash in hex string.
|
|
18
|
+
*/
|
|
19
|
+
toString(): string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Return hash in ArrayBuffer.
|
|
23
|
+
*/
|
|
24
|
+
arrayBuffer(): ArrayBuffer;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Return hash in integer array.
|
|
28
|
+
*/
|
|
29
|
+
digest(): number[];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Return hash in integer array.
|
|
33
|
+
*/
|
|
34
|
+
array(): number[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface Hash {
|
|
38
|
+
/**
|
|
39
|
+
* Hash and return hex string.
|
|
40
|
+
*
|
|
41
|
+
* @param message The message you want to hash.
|
|
42
|
+
*/
|
|
43
|
+
(message: Message): string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Create a hash object.
|
|
47
|
+
*/
|
|
48
|
+
create(): Hasher;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create a hash object and hash message.
|
|
52
|
+
*
|
|
53
|
+
* @param message The message you want to hash.
|
|
54
|
+
*/
|
|
55
|
+
update(message: Message): Hasher;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ShakeHash {
|
|
59
|
+
/**
|
|
60
|
+
* Hash and return hex string.
|
|
61
|
+
*
|
|
62
|
+
* @param message The message you want to hash.
|
|
63
|
+
* @param outputBits The length of output.
|
|
64
|
+
*/
|
|
65
|
+
(message: Message, outputBits: number): string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Create a hash object.
|
|
69
|
+
*
|
|
70
|
+
* @param outputBits The length of output.
|
|
71
|
+
*/
|
|
72
|
+
create(outputBits: number): Hasher;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Create a hash object and hash message.
|
|
76
|
+
*
|
|
77
|
+
* @param message The message you want to hash.
|
|
78
|
+
* @param outputBits The length of output.
|
|
79
|
+
*/
|
|
80
|
+
update(message: Message, outputBits: number): Hasher;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export var sha3_512: Hash;
|
|
84
|
+
export var sha3_384: Hash;
|
|
85
|
+
export var sha3_256: Hash;
|
|
86
|
+
export var sha3_224: Hash;
|
|
87
|
+
export var keccak_512: Hash;
|
|
88
|
+
export var keccak_384: Hash;
|
|
89
|
+
export var keccak_256: Hash;
|
|
90
|
+
export var keccak_224: Hash;
|
|
91
|
+
export var shake_128: ShakeHash;
|
|
92
|
+
export var shake_256: ShakeHash;
|
package/package.json
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "js-sha3",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
|
|
5
|
-
"main": "src/sha3.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "js-sha3",
|
|
3
|
+
"version": "0.5.7",
|
|
4
|
+
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
|
|
5
|
+
"main": "src/sha3.js",
|
|
6
|
+
"typings": "index",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"expect.js": "~0.3.1",
|
|
10
|
+
"jscoverage": "~0.5.9",
|
|
11
|
+
"mocha": "~2.3.2",
|
|
12
|
+
"uglifyjs": "~2.4.10"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "mocha tests/node-test.js -r jscoverage",
|
|
16
|
+
"report": "mocha tests/node-test.js -r jscoverage --covout=html",
|
|
17
|
+
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls",
|
|
18
|
+
"build": "uglifyjs src/sha3.js --compress --mangle --comments --output build/sha3.min.js"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/emn178/js-sha3.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"sha3",
|
|
26
|
+
"keccak",
|
|
27
|
+
"shake",
|
|
28
|
+
"hash",
|
|
29
|
+
"encryption",
|
|
30
|
+
"cryptography",
|
|
31
|
+
"HMAC"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"author": "Chen, Yi-Cyuan <emn178@gmail.com>",
|
|
35
|
+
"homepage": "https://github.com/emn178/js-sha3",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/emn178/js-sha3/issues"
|
|
38
|
+
}
|
|
39
|
+
}
|