js-sha3 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/build/sha3.min.js +2 -2
- package/package.json +1 -1
- package/src/sha3.js +48 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## v0.9.3 / 2023-12-16
|
|
4
|
+
### Fixed
|
|
5
|
+
- Fix error in arrayBuffer when there are extra bytes #37
|
|
6
|
+
- fixed output if finalized.
|
|
7
|
+
|
|
8
|
+
## v0.9.2 / 2023-09-16
|
|
9
|
+
### Fixed
|
|
10
|
+
- don't modify global Array and ArrayBuffer prototypes. #33
|
|
11
|
+
- refactor: simplify formatMessage internal logic. #34
|
|
12
|
+
|
|
3
13
|
## v0.9.1 / 2023-08-31
|
|
4
14
|
### Fixed
|
|
5
15
|
- cSHAKE empty Array bug. #24
|
package/build/sha3.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
3
|
*
|
|
4
|
-
* @version 0.9.
|
|
4
|
+
* @version 0.9.3
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
6
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
7
7
|
* @license MIT
|
|
8
8
|
*/
|
|
9
|
-
!function(){"use strict";function t(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function e(e,r,n){t.call(this,e,r,n)}var r="input is invalid type",n="object"==typeof window,i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&"object"==typeof self;!i.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?i=global:o&&(i=self);var a=!i.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,u=!i.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),c=[4,1024,262144,67108864],h=[0,8,16,24],p=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],d=[224,256,384,512],l=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],b={128:168,256:136}
|
|
9
|
+
!function(){"use strict";function t(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function e(e,r,n){t.call(this,e,r,n)}var r="input is invalid type",n="object"==typeof window,i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&"object"==typeof self;!i.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?i=global:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,s="function"==typeof define&&define.amd,u=!i.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,f="0123456789abcdef".split(""),c=[4,1024,262144,67108864],h=[0,8,16,24],p=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],d=[224,256,384,512],l=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],b={128:168,256:136},v=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,A=!u||!i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},g=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(r);if(u&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!v(t)&&!A(t))throw new Error(r);return[t,!1]},B=function(t){return 0===g(t)[0].length},_=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},k=function(e,r,n){return function(i){return new t(e,r,e).update(i)[n]()}},w=function(e,r,n){return function(i,o){return new t(e,r,o).update(i)[n]()}},S=function(t,e,r){return function(e,n,i,o){return z["cshake"+t].update(e,n,i,o)[r]()}},C=function(t,e,r){return function(e,n,i,o){return z["kmac"+t].update(e,n,i,o)[r]()}},x=function(t,e,r,n){for(var i=0;i<y.length;++i){var o=y[i];t[o]=e(r,n,o)}return t},m=function(e,r){var n=k(e,r,"hex");return n.create=function(){return new t(e,r,e)},n.update=function(t){return n.create().update(t)},x(n,k,e,r)},O=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:m},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:m},{name:"shake",padding:[31,7936,2031616,520093696],bits:l,createMethod:function(e,r){var n=w(e,r,"hex");return n.create=function(n){return new t(e,r,n)},n.update=function(t,e){return n.create(e).update(t)},x(n,w,e,r)}},{name:"cshake",padding:c,bits:l,createMethod:function(e,r){var n=b[e],i=S(e,0,"hex");return i.create=function(i,o,a){return B(o)&&B(a)?z["shake"+e].create(i):new t(e,r,i).bytepad([o,a],n)},i.update=function(t,e,r,n){return i.create(e,r,n).update(t)},x(i,S,e,r)}},{name:"kmac",padding:c,bits:l,createMethod:function(t,r){var n=b[t],i=C(t,0,"hex");return i.create=function(i,o,a){return new e(t,r,o).bytepad(["KMAC",a],n).bytepad([i],n)},i.update=function(t,e,r,n){return i.create(t,r,n).update(e)},x(i,C,t,r)}}],z={},N=[],J=0;J<O.length;++J)for(var M=O[J],j=M.bits,E=0;E<j.length;++E){var H=M.name+"_"+j[E];if(N.push(H),z[H]=M.createMethod(j[E],M.padding),"sha3"!==M.name){var I=M.name+j[E];N.push(I),z[I]=z[H]}}t.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=g(t);t=e[0];for(var r,n,i=e[1],o=this.blocks,a=this.byteCount,s=t.length,u=this.blockCount,f=0,c=this.s;f<s;){if(this.reset)for(this.reset=!1,o[0]=this.block,r=1;r<u+1;++r)o[r]=0;if(i)for(r=this.start;f<s&&r<a;++f)(n=t.charCodeAt(f))<128?o[r>>2]|=n<<h[3&r++]:n<2048?(o[r>>2]|=(192|n>>6)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]):n<55296||n>=57344?(o[r>>2]|=(224|n>>12)<<h[3&r++],o[r>>2]|=(128|n>>6&63)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++f)),o[r>>2]|=(240|n>>18)<<h[3&r++],o[r>>2]|=(128|n>>12&63)<<h[3&r++],o[r>>2]|=(128|n>>6&63)<<h[3&r++],o[r>>2]|=(128|63&n)<<h[3&r++]);else for(r=this.start;f<s&&r<a;++f)o[r>>2]|=t[f]<<h[3&r++];if(this.lastByteIndex=r,r>=a){for(this.start=r-a,this.block=o[u],r=0;r<u;++r)c[r]^=o[r];R(c),this.reset=!0}else this.start=r}return this},t.prototype.encode=function(t,e){var r=255&t,n=1,i=[r];for(r=255&(t>>=8);r>0;)i.unshift(r),r=255&(t>>=8),++n;return e?i.push(n):i.unshift(n),this.update(i),i.length},t.prototype.encodeString=function(t){var e=g(t);t=e[0];var r=e[1],n=0,i=t.length;if(r)for(var o=0;o<t.length;++o){var a=t.charCodeAt(o);a<128?n+=1:a<2048?n+=2:a<55296||a>=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++o)),n+=4)}else n=i;return n+=this.encode(8*n),this.update(t),n},t.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var i=(e-r%e)%e,o=[];return o.length=i,this.update(o),this},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];R(n)}},t.prototype.toString=t.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,s="";a<n;){for(o=0;o<e&&a<n;++o,++a)t=r[o],s+=f[t>>4&15]+f[15&t]+f[t>>12&15]+f[t>>8&15]+f[t>>20&15]+f[t>>16&15]+f[t>>28&15]+f[t>>24&15];a%e==0&&(r=_(r),R(r),o=0)}return i&&(t=r[o],s+=f[t>>4&15]+f[15&t],i>1&&(s+=f[t>>12&15]+f[t>>8&15]),i>2&&(s+=f[t>>20&15]+f[t>>16&15])),s},t.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,a=0,s=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(s);for(var u=new Uint32Array(t);a<n;){for(o=0;o<e&&a<n;++o,++a)u[a]=r[o];a%e==0&&(r=_(r),R(r))}return i&&(u[a]=r[o],t=t.slice(0,s)),t},t.prototype.buffer=t.prototype.arrayBuffer,t.prototype.digest=t.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,i=this.outputBlocks,o=this.extraBytes,a=0,s=0,u=[];s<i;){for(a=0;a<r&&s<i;++a,++s)t=s<<2,e=n[a],u[t]=255&e,u[t+1]=e>>8&255,u[t+2]=e>>16&255,u[t+3]=e>>24&255;s%r==0&&(n=_(n),R(n))}return o&&(t=s<<2,e=n[a],u[t]=255&e,o>1&&(u[t+1]=e>>8&255),o>2&&(u[t+2]=e>>16&255)),u},(e.prototype=new t).finalize=function(){return this.encode(this.outputBits,!0),t.prototype.finalize.call(this)};var R=function(t){var e,r,n,i,o,a,s,u,f,c,h,d,l,y,b,v,A,g,B,_,k,w,S,C,x,m,O,z,N,J,M,j,E,H,I,R,F,U,D,V,W,Y,K,q,G,L,P,Q,T,X,Z,$,tt,et,rt,nt,it,ot,at,st,ut,ft,ct;for(n=0;n<48;n+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],o=t[1]^t[11]^t[21]^t[31]^t[41],a=t[2]^t[12]^t[22]^t[32]^t[42],s=t[3]^t[13]^t[23]^t[33]^t[43],u=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],h=t[7]^t[17]^t[27]^t[37]^t[47],e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(a<<1|s>>>31),r=(l=t[9]^t[19]^t[29]^t[39]^t[49])^(s<<1|a>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=i^(u<<1|f>>>31),r=o^(f<<1|u>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=a^(c<<1|h>>>31),r=s^(h<<1|c>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=u^(d<<1|l>>>31),r=f^(l<<1|d>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=c^(i<<1|o>>>31),r=h^(o<<1|i>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,y=t[0],b=t[1],L=t[11]<<4|t[10]>>>28,P=t[10]<<4|t[11]>>>28,z=t[20]<<3|t[21]>>>29,N=t[21]<<3|t[20]>>>29,st=t[31]<<9|t[30]>>>23,ut=t[30]<<9|t[31]>>>23,Y=t[40]<<18|t[41]>>>14,K=t[41]<<18|t[40]>>>14,H=t[2]<<1|t[3]>>>31,I=t[3]<<1|t[2]>>>31,v=t[13]<<12|t[12]>>>20,A=t[12]<<12|t[13]>>>20,Q=t[22]<<10|t[23]>>>22,T=t[23]<<10|t[22]>>>22,J=t[33]<<13|t[32]>>>19,M=t[32]<<13|t[33]>>>19,ft=t[42]<<2|t[43]>>>30,ct=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,R=t[14]<<6|t[15]>>>26,F=t[15]<<6|t[14]>>>26,g=t[25]<<11|t[24]>>>21,B=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Z=t[35]<<15|t[34]>>>17,j=t[45]<<29|t[44]>>>3,E=t[44]<<29|t[45]>>>3,C=t[6]<<28|t[7]>>>4,x=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,U=t[26]<<25|t[27]>>>7,D=t[27]<<25|t[26]>>>7,_=t[36]<<21|t[37]>>>11,k=t[37]<<21|t[36]>>>11,$=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,q=t[8]<<27|t[9]>>>5,G=t[9]<<27|t[8]>>>5,m=t[18]<<20|t[19]>>>12,O=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,at=t[28]<<7|t[29]>>>25,V=t[38]<<8|t[39]>>>24,W=t[39]<<8|t[38]>>>24,w=t[48]<<14|t[49]>>>18,S=t[49]<<14|t[48]>>>18,t[0]=y^~v&g,t[1]=b^~A&B,t[10]=C^~m&z,t[11]=x^~O&N,t[20]=H^~R&U,t[21]=I^~F&D,t[30]=q^~L&Q,t[31]=G^~P&T,t[40]=et^~nt&ot,t[41]=rt^~it&at,t[2]=v^~g&_,t[3]=A^~B&k,t[12]=m^~z&J,t[13]=O^~N&M,t[22]=R^~U&V,t[23]=F^~D&W,t[32]=L^~Q&X,t[33]=P^~T&Z,t[42]=nt^~ot&st,t[43]=it^~at&ut,t[4]=g^~_&w,t[5]=B^~k&S,t[14]=z^~J&j,t[15]=N^~M&E,t[24]=U^~V&Y,t[25]=D^~W&K,t[34]=Q^~X&$,t[35]=T^~Z&tt,t[44]=ot^~st&ft,t[45]=at^~ut&ct,t[6]=_^~w&y,t[7]=k^~S&b,t[16]=J^~j&C,t[17]=M^~E&x,t[26]=V^~Y&H,t[27]=W^~K&I,t[36]=X^~$&q,t[37]=Z^~tt&G,t[46]=st^~ft&et,t[47]=ut^~ct&rt,t[8]=w^~y&v,t[9]=S^~b&A,t[18]=j^~C&m,t[19]=E^~x&O,t[28]=Y^~H&R,t[29]=K^~I&F,t[38]=$^~q&L,t[39]=tt^~G&P,t[48]=ft^~et&nt,t[49]=ct^~rt&it,t[0]^=p[n],t[1]^=p[n+1]};if(a)module.exports=z;else{for(J=0;J<N.length;++J)i[N[J]]=z[N[J]];s&&define(function(){return z})}}();
|
package/package.json
CHANGED
package/src/sha3.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
3
|
*
|
|
4
|
-
* @version 0.9.
|
|
4
|
+
* @version 0.9.3
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
6
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
7
7
|
* @license MIT
|
|
@@ -46,43 +46,49 @@
|
|
|
46
46
|
'256': 136
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) {
|
|
50
|
-
Array.isArray = function (obj) {
|
|
51
|
-
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
49
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
var isArray = root.JS_SHA3_NO_NODE_JS || !Array.isArray
|
|
51
|
+
? function (obj) {
|
|
52
|
+
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
53
|
+
}
|
|
54
|
+
: Array.isArray;
|
|
60
55
|
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (type === 'object') {
|
|
65
|
-
if (message === null) {
|
|
66
|
-
throw new Error(INPUT_ERROR);
|
|
67
|
-
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
68
|
-
message = new Uint8Array(message);
|
|
69
|
-
} else if (!Array.isArray(message)) {
|
|
70
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
71
|
-
throw new Error(INPUT_ERROR);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
throw new Error(INPUT_ERROR);
|
|
56
|
+
var isView = (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView))
|
|
57
|
+
? function (obj) {
|
|
58
|
+
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
76
59
|
}
|
|
77
|
-
|
|
60
|
+
: ArrayBuffer.isView;
|
|
61
|
+
|
|
62
|
+
// [message: string, isString: bool]
|
|
63
|
+
var formatMessage = function (message) {
|
|
64
|
+
var type = typeof message;
|
|
65
|
+
if (type === 'string') {
|
|
66
|
+
return [message, true];
|
|
67
|
+
}
|
|
68
|
+
if (type !== 'object' || message === null) {
|
|
69
|
+
throw new Error(INPUT_ERROR);
|
|
78
70
|
}
|
|
79
|
-
|
|
71
|
+
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
72
|
+
return [new Uint8Array(message), false];
|
|
73
|
+
}
|
|
74
|
+
if (!isArray(message) && !isView(message)) {
|
|
75
|
+
throw new Error(INPUT_ERROR);
|
|
76
|
+
}
|
|
77
|
+
return [message, false];
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
var empty = function (message) {
|
|
83
81
|
return formatMessage(message)[0].length === 0;
|
|
84
82
|
};
|
|
85
83
|
|
|
84
|
+
var cloneArray = function (array) {
|
|
85
|
+
var newArray = [];
|
|
86
|
+
for (var i = 0; i < array.length; ++i) {
|
|
87
|
+
newArray[i] = array[i];
|
|
88
|
+
}
|
|
89
|
+
return newArray;
|
|
90
|
+
}
|
|
91
|
+
|
|
86
92
|
var createOutputMethod = function (bits, padding, outputType) {
|
|
87
93
|
return function (message) {
|
|
88
94
|
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
|
@@ -215,7 +221,7 @@
|
|
|
215
221
|
}
|
|
216
222
|
var result = formatMessage(message);
|
|
217
223
|
message = result[0];
|
|
218
|
-
var
|
|
224
|
+
var isString = result[1];
|
|
219
225
|
var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
|
|
220
226
|
blockCount = this.blockCount, index = 0, s = this.s, i, code;
|
|
221
227
|
|
|
@@ -227,11 +233,7 @@
|
|
|
227
233
|
blocks[i] = 0;
|
|
228
234
|
}
|
|
229
235
|
}
|
|
230
|
-
if (
|
|
231
|
-
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
232
|
-
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
233
|
-
}
|
|
234
|
-
} else {
|
|
236
|
+
if (isString) {
|
|
235
237
|
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
236
238
|
code = message.charCodeAt(index);
|
|
237
239
|
if (code < 0x80) {
|
|
@@ -251,6 +253,10 @@
|
|
|
251
253
|
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
252
254
|
}
|
|
253
255
|
}
|
|
256
|
+
} else {
|
|
257
|
+
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
258
|
+
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
259
|
+
}
|
|
254
260
|
}
|
|
255
261
|
this.lastByteIndex = i;
|
|
256
262
|
if (i >= byteCount) {
|
|
@@ -291,11 +297,9 @@
|
|
|
291
297
|
Keccak.prototype.encodeString = function (str) {
|
|
292
298
|
var result = formatMessage(str);
|
|
293
299
|
str = result[0];
|
|
294
|
-
var
|
|
300
|
+
var isString = result[1];
|
|
295
301
|
var bytes = 0, length = str.length;
|
|
296
|
-
if (
|
|
297
|
-
bytes = length;
|
|
298
|
-
} else {
|
|
302
|
+
if (isString) {
|
|
299
303
|
for (var i = 0; i < str.length; ++i) {
|
|
300
304
|
var code = str.charCodeAt(i);
|
|
301
305
|
if (code < 0x80) {
|
|
@@ -309,6 +313,8 @@
|
|
|
309
313
|
bytes += 4;
|
|
310
314
|
}
|
|
311
315
|
}
|
|
316
|
+
} else {
|
|
317
|
+
bytes = length;
|
|
312
318
|
}
|
|
313
319
|
bytes += this.encode(bytes * 8);
|
|
314
320
|
this.update(str);
|
|
@@ -362,6 +368,7 @@
|
|
|
362
368
|
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
|
363
369
|
}
|
|
364
370
|
if (j % blockCount === 0) {
|
|
371
|
+
s = cloneArray(s);
|
|
365
372
|
f(s);
|
|
366
373
|
i = 0;
|
|
367
374
|
}
|
|
@@ -397,11 +404,12 @@
|
|
|
397
404
|
array[j] = s[i];
|
|
398
405
|
}
|
|
399
406
|
if (j % blockCount === 0) {
|
|
407
|
+
s = cloneArray(s);
|
|
400
408
|
f(s);
|
|
401
409
|
}
|
|
402
410
|
}
|
|
403
411
|
if (extraBytes) {
|
|
404
|
-
array[
|
|
412
|
+
array[j] = s[i];
|
|
405
413
|
buffer = buffer.slice(0, bytes);
|
|
406
414
|
}
|
|
407
415
|
return buffer;
|
|
@@ -425,6 +433,7 @@
|
|
|
425
433
|
array[offset + 3] = (block >> 24) & 0xFF;
|
|
426
434
|
}
|
|
427
435
|
if (j % blockCount === 0) {
|
|
436
|
+
s = cloneArray(s);
|
|
428
437
|
f(s);
|
|
429
438
|
}
|
|
430
439
|
}
|