Added some files to npm package.

pull/10/head v0.5.3
Chen, Yi-Cyuan 9 years ago
parent 06a3fa8f52
commit f0ff77ca47

@ -1,4 +1,2 @@
my_test my_test
covreporter covreporter
build
tests

@ -1,10 +1,8 @@
language: node_js language: node_js
node_js: node_js:
- "4.1" - "0.12.15"
- "4.0" - "4.5"
- "0.12" - "6.5.0"
- "0.11"
- "0.10"
before_install: before_install:
- npm install coveralls - npm install coveralls
- npm install mocha-lcov-reporter - npm install mocha-lcov-reporter

@ -1,3 +1,7 @@
# v0.5.3 / 2016-09-08
* Added some files to npm package.
# v0.5.2 / 2016-06-06 # v0.5.2 / 2016-06-06
* Fixed shake output incorrect in the special length. * Fixed shake output incorrect in the special length.

@ -209,73 +209,6 @@ sha3_512(new Uint8Array([]));
[UTF8](http://jsperf.com/sha3/5) [UTF8](http://jsperf.com/sha3/5)
[ASCII](http://jsperf.com/sha3/4) [ASCII](http://jsperf.com/sha3/4)
## Extensions
### jQuery
If you prefer jQuery style, you can add following code to add a jQuery extension.
Code
```JavaScript
jQuery.sha3_512 = sha3_512;
jQuery.sha3_384 = sha3_384;
jQuery.sha3_256 = sha3_256;
jQuery.sha3_224 = sha3_224;
jQuery.keccak_512 = keccak_512;
jQuery.keccak_384 = keccak_384;
jQuery.keccak_256 = keccak_256;
jQuery.keccak_224 = keccak_224;
```
And then you could use like this:
```JavaScript
$.sha3_512('message');
$.sha3_384('message');
$.sha3_256('message');
$.sha3_224('message');
$.keccak_512('message');
$.keccak_384('message');
$.keccak_256('message');
$.keccak_224('message');
```
### Prototype
If you prefer prototype style, you can add following code to add a prototype extension.
Code
```JavaScript
String.prototype.sha3_512 = function() {
return sha3_512(this);
};
String.prototype.sha3_384 = function() {
return sha3_384(this);
};
String.prototype.sha3_256 = function() {
return sha3_256(this);
};
String.prototype.sha3_224 = function() {
return sha3_224(this);
};
String.prototype.keccak_512 = function() {
return keccak_512(this);
};
String.prototype.keccak_384 = function() {
return keccak_384(this);
};
String.prototype.keccak_256 = function() {
return keccak_256(this);
};
String.prototype.keccak_224 = function() {
return keccak_224(this);
};
```
And then you could use like this:
```JavaScript
'message'.sha3_512();
'message'.sha3_384();
'message'.sha3_256();
'message'.sha3_224();
'message'.keccak_512();
'message'.keccak_384();
'message'.keccak_256();
'message'.keccak_224();
```
## License ## License
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT). The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).

@ -1,6 +1,6 @@
{ {
"name": "js-sha3", "name": "js-sha3",
"version": "0.5.2", "version": "0.5.3",
"main": ["src/sha3.js"], "main": ["src/sha3.js"],
"ignore": [ "ignore": [
"samples", "samples",

16
build/sha3.min.js vendored

@ -1,18 +1,18 @@
/** /**
* [js-sha3]{@link https://github.com/emn178/js-sha3} * [js-sha3]{@link https://github.com/emn178/js-sha3}
* *
* @version 0.5.2 * @version 0.5.3
* @author Chen, Yi-Cyuan [emn178@gmail.com] * @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2016 * @copyright Chen, Yi-Cyuan 2015-2016
* @license MIT * @license MIT
*/ */
(function(r){function n(a,b,c){this.blocks=[];this.s=[];this.padding=b;this.outputBits=c;this.reset=!0;this.start=this.block=0;this.blockCount=1600-(a<<1)>>5;this.byteCount=this.blockCount<<2;this.outputBlocks=c>>5;this.extraBytes=(c&31)>>3;for(a=0;50>a;++a)this.s[a]=0}var ga="undefined"!=typeof module;ga&&(r=global);for(var l="0123456789abcdef".split(""),p=[0,8,16,24],ha=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425, (function(r){function n(a,b,c){this.blocks=[];this.s=[];this.padding=b;this.outputBits=c;this.reset=!0;this.start=this.block=0;this.blockCount=1600-(a<<1)>>5;this.byteCount=this.blockCount<<2;this.outputBlocks=c>>5;this.extraBytes=(c&31)>>3;for(a=0;50>a;++a)this.s[a]=0}var ga="object"==typeof process&&process.versions&&process.versions.node;ga&&(r=global);for(var l="0123456789abcdef".split(""),p=[0,8,16,24],ha=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,
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,b,a)};c.update= 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,
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=w[e];c[g]=ja(a, 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=
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]<<p[d++&3];else for(d= 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]<<
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=function(){var a= 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=
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>>24&15];0==k%a&& 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>>
(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(); 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();
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]^ 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]^
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, 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,
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]<< 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]<<

@ -1,6 +1,6 @@
{ {
"name": "js-sha3", "name": "js-sha3",
"version": "0.5.2", "version": "0.5.3",
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.", "description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
"main": "src/sha3.js", "main": "src/sha3.js",
"devDependencies": { "devDependencies": {

@ -1,7 +1,7 @@
/** /**
* [js-sha3]{@link https://github.com/emn178/js-sha3} * [js-sha3]{@link https://github.com/emn178/js-sha3}
* *
* @version 0.5.2 * @version 0.5.3
* @author Chen, Yi-Cyuan [emn178@gmail.com] * @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2016 * @copyright Chen, Yi-Cyuan 2015-2016
* @license MIT * @license MIT
@ -9,7 +9,7 @@
(function (root) { (function (root) {
'use strict'; 'use strict';
var NODE_JS = typeof(module) != 'undefined'; var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
if (NODE_JS) { if (NODE_JS) {
root = global; root = global;
} }
@ -106,7 +106,7 @@
}; };
Keccak.prototype.update = function (message) { Keccak.prototype.update = function (message) {
var notString = typeof(message) != 'string'; var notString = typeof message != 'string';
if (notString && message.constructor == root.ArrayBuffer) { if (notString && message.constructor == root.ArrayBuffer) {
message = new Uint8Array(message); message = new Uint8Array(message);
} }
@ -122,11 +122,11 @@
} }
} }
if (notString) { if (notString) {
for (i = this.start;index < length && i < byteCount; ++index) { for (i = this.start;index < length && i < byteCount;++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
} }
} else { } else {
for (i = this.start;index < length && i < byteCount; ++index) { for (i = this.start;index < length && i < byteCount;++index) {
code = message.charCodeAt(index); code = message.charCodeAt(index);
if (code < 0x80) { if (code < 0x80) {
blocks[i >> 2] |= code << SHIFT[i++ & 3]; blocks[i >> 2] |= code << SHIFT[i++ & 3];
@ -280,7 +280,7 @@
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49; b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
for (n = 0; n < 48; n += 2) { for (n = 0;n < 48;n += 2) {
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]; c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]; c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]; c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];

Loading…
Cancel
Save