From 0f3bc529d45a5b9580462506f4bdd5d3eb84942e Mon Sep 17 00:00:00 2001 From: Yi-Cyuan Chen Date: Wed, 18 Nov 2026 13:30:47 +0800 Subject: [PATCH] ### Fixed - Incorrect hash for `DataView` input, and for `Int8Array` with negative values in browsers. ### Changed - Multi-byte typed arrays such as `Uint16Array`, `Uint32Array` and `Float32Array` are now hashed by their underlying bytes, the same as Node.js `crypto` and Web Crypto. Previously each element was treated as one byte. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 +++++++ README.md | 2 +- bower.json | 2 +- build/sha256.cjs | 5 +++-- build/sha256.js | 5 +++-- build/sha256.min.js | 4 ++-- build/sha256.min.mjs | 4 ++-- build/sha256.node.cjs | 5 +++-- index.d.ts | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/shared.mjs | 3 ++- tests/test.js | 10 ++++++++++ 13 files changed, 38 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d396043..29af999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## v1.1.0 / 2026-11-18 +### Fixed +- Incorrect hash for `DataView` input, and for `Int8Array` with negative values in browsers. + +### Changed +- Multi-byte typed arrays such as `Uint16Array`, `Uint32Array` and `Float32Array` are now hashed by their underlying bytes, the same as Node.js `crypto` and Web Crypto. Previously each element was treated as one byte. + ## v1.0.1 / 2026-11-17 ### Fixed - Unpaired UTF-16 surrogates in string input (including HMAC keys) produced wrong digests and consumed the following code unit in the browser/core implementation. They are now encoded as U+FFFD, matching `TextEncoder` and the Node.js implementation. diff --git a/README.md b/README.md index 4953ddf..bc60bf0 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ sha224('The quick brown fox jumps over the lazy dog.'); // 619cba8e8e05826e9b8c5 sha256('中文'); // 72726d8818f693066ceb69afa364218b692e62ea92b385782363780f47529c21 sha224('中文'); // dfbab71afdf54388af4d55f8bd3de8c9b15e0eb916bf9125f4a959d4 -// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input +// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` and other `ArrayBuffer` views (their underlying bytes are hashed) sha256([]); // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 sha256(new Uint8Array([211, 212])); // 182889f925ae4e5cc37118ded6ed87f7bdc7cab5ec5e78faef2e50048999473f diff --git a/bower.json b/bower.json index a17df47..7e8d406 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "js-sha256", - "version": "1.0.1", + "version": "1.1.0", "main": ["build/sha256.js"], "ignore": [ "samples", diff --git a/build/sha256.cjs b/build/sha256.cjs index 3eac954..3214ec3 100644 --- a/build/sha256.cjs +++ b/build/sha256.cjs @@ -1,7 +1,7 @@ /** * [js-sha256]{@link https://github.com/emn178/js-sha256} * - * @version 1.0.1 + * @version 1.1.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2026 * @license MIT @@ -25,7 +25,8 @@ var formatMessage = function (message) { if (message.constructor === ArrayBuffer) { return [new Uint8Array(message), false]; } else if (ArrayBuffer.isView(message)) { - return [message, false]; + // read the underlying bytes of any view (Int8Array, DataView, Uint16Array, ...) + return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false]; } } throw new Error(INPUT_ERROR); diff --git a/build/sha256.js b/build/sha256.js index 75f5b0f..80ed6a0 100644 --- a/build/sha256.js +++ b/build/sha256.js @@ -1,7 +1,7 @@ /** * [js-sha256]{@link https://github.com/emn178/js-sha256} * - * @version 1.0.1 + * @version 1.1.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2026 * @license MIT @@ -29,7 +29,8 @@ if (message.constructor === ArrayBuffer) { return [new Uint8Array(message), false]; } else if (ArrayBuffer.isView(message)) { - return [message, false]; + // read the underlying bytes of any view (Int8Array, DataView, Uint16Array, ...) + return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false]; } } throw new Error(INPUT_ERROR); diff --git a/build/sha256.min.js b/build/sha256.min.js index 40699fb..31523b9 100644 --- a/build/sha256.min.js +++ b/build/sha256.min.js @@ -1,9 +1,9 @@ /** * [js-sha256]{@link https://github.com/emn178/js-sha256} * - * @version 1.0.1 + * @version 1.1.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2026 * @license MIT */ -!function(t,h){"object"==typeof exports&&"undefined"!=typeof module?module.exports=h():"function"==typeof define&&define.amd?define(h):(t="undefined"!=typeof globalThis?globalThis:t||self).sha256=h()}(this,function(){"use strict";var t="undefined"!=typeof ArrayBuffer,h=function(h){if("string"===typeof h)return[h,!0];if(Array.isArray(h))return[h,!1];if(t&&h){if(h.constructor===ArrayBuffer)return[new Uint8Array(h),!1];if(ArrayBuffer.isView(h))return[h,!1]}throw new Error("input is invalid type")},i="0123456789abcdef".split(""),s=[-2147483648,8388608,32768,128],e=[24,16,8,0],r=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=["hex","array","digest","arrayBuffer"],o=[],a=function(t,h){return function(i){return new c(h,!0).update(i)[t]()}},f=function(t){var h=a("hex",t);h.create=function(){return new c(t)},h.update=function(t){return h.create().update(t)};for(var i=0;i>>6,a[u++]=128|63&n):n<55296||n>=57344?(a[u++]=224|n>>>12,a[u++]=128|n>>>6&63,a[u++]=128|63&n):n<56320&&(o=t.charCodeAt(e+1))>=56320&&o<57344?(++e,n=65536+((1023&n)<<10|1023&o),a[u++]=240|n>>>18,a[u++]=128|n>>>12&63,a[u++]=128|n>>>6&63,a[u++]=128|63&n):(a[u++]=239,a[u++]=191,a[u++]=189);t=a}t.length>64&&(t=new c(i,!0).update(t).array());var l=[],y=[];for(e=0;e<64;++e){var p=t[e]||0;l[e]=92^p,y[e]=54^p}c.call(this,i,s),this.update(y),this.oKeyPad=l,this.inner=!0,this.sharedMemory=s}c.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var i=h(t);t=i[0];for(var s,r,n,o=i[1],a=0,f=t.length,u=this.blocks;a>>2]|=s<>>2]|=(192|s>>>6)<>>2]|=(128|63&s)<=57344?(u[n>>>2]|=(224|s>>>12)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<=56320&&r<57344?(++a,s=65536+((1023&s)<<10|1023&r),u[n>>>2]|=(240|s>>>18)<>>2]|=(128|s>>>12&63)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<>>2]|=239<>>2]|=191<>>2]|=189<>>2]|=t[a]<=64?(this.block=u[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},c.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,h=this.lastByteIndex;t[16]=this.block,t[h>>>2]|=s[3&h],this.block=t[16],h>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},c.prototype.hash=function(){var t,h,i,s,e,n,o,a,f,u=this.h0,l=this.h1,c=this.h2,y=this.h3,p=this.h4,d=this.h5,b=this.h6,v=this.h7,w=this.blocks;for(t=16;t<64;++t)h=((e=w[t-15])>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,i=((e=w[t-2])>>>17|e<<15)^(e>>>19|e<<13)^e>>>10,w[t]=w[t-16]+h+w[t-7]+i|0;for(f=l&c,t=0;t<64;t+=4)this.first?(this.is224?(n=300032,v=(e=w[0]-1413257819)-150054599|0,y=e+24177077|0):(n=704751109,v=(e=w[0]-210244248)-1521486534|0,y=e+143694565|0),this.first=!1):(h=(u>>>2|u<<30)^(u>>>13|u<<19)^(u>>>22|u<<10),s=(n=u&l)^u&c^f,v=y+(e=v+(i=(p>>>6|p<<26)^(p>>>11|p<<21)^(p>>>25|p<<7))+(p&d^~p&b)+r[t]+w[t])|0,y=e+(h+s)|0),h=(y>>>2|y<<30)^(y>>>13|y<<19)^(y>>>22|y<<10),s=(o=y&u)^y&l^n,b=c+(e=b+(i=(v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7))+(v&p^~v&d)+r[t+1]+w[t+1])|0,h=((c=e+(h+s)|0)>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),s=(a=c&y)^c&u^o,d=l+(e=d+(i=(b>>>6|b<<26)^(b>>>11|b<<21)^(b>>>25|b<<7))+(b&v^~b&p)+r[t+2]+w[t+2])|0,h=((l=e+(h+s)|0)>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),s=(f=l&c)^l&y^a,p=u+(e=p+(i=(d>>>6|d<<26)^(d>>>11|d<<21)^(d>>>25|d<<7))+(d&b^~d&v)+r[t+3]+w[t+3])|0,u=e+(h+s)|0,this.chromeBugWorkAround=!0;this.h0=this.h0+u|0,this.h1=this.h1+l|0,this.h2=this.h2+c|0,this.h3=this.h3+y|0,this.h4=this.h4+p|0,this.h5=this.h5+d|0,this.h6=this.h6+b|0,this.h7=this.h7+v|0},c.prototype.hex=function(){this.finalize();var t=this.h0,h=this.h1,s=this.h2,e=this.h3,r=this.h4,n=this.h5,o=this.h6,a=this.h7,f=i[t>>>28&15]+i[t>>>24&15]+i[t>>>20&15]+i[t>>>16&15]+i[t>>>12&15]+i[t>>>8&15]+i[t>>>4&15]+i[15&t]+i[h>>>28&15]+i[h>>>24&15]+i[h>>>20&15]+i[h>>>16&15]+i[h>>>12&15]+i[h>>>8&15]+i[h>>>4&15]+i[15&h]+i[s>>>28&15]+i[s>>>24&15]+i[s>>>20&15]+i[s>>>16&15]+i[s>>>12&15]+i[s>>>8&15]+i[s>>>4&15]+i[15&s]+i[e>>>28&15]+i[e>>>24&15]+i[e>>>20&15]+i[e>>>16&15]+i[e>>>12&15]+i[e>>>8&15]+i[e>>>4&15]+i[15&e]+i[r>>>28&15]+i[r>>>24&15]+i[r>>>20&15]+i[r>>>16&15]+i[r>>>12&15]+i[r>>>8&15]+i[r>>>4&15]+i[15&r]+i[n>>>28&15]+i[n>>>24&15]+i[n>>>20&15]+i[n>>>16&15]+i[n>>>12&15]+i[n>>>8&15]+i[n>>>4&15]+i[15&n]+i[o>>>28&15]+i[o>>>24&15]+i[o>>>20&15]+i[o>>>16&15]+i[o>>>12&15]+i[o>>>8&15]+i[o>>>4&15]+i[15&o];return this.is224||(f+=i[a>>>28&15]+i[a>>>24&15]+i[a>>>20&15]+i[a>>>16&15]+i[a>>>12&15]+i[a>>>8&15]+i[a>>>4&15]+i[15&a]),f},c.prototype.toString=c.prototype.hex,c.prototype.digest=function(){this.finalize();var t=this.h0,h=this.h1,i=this.h2,s=this.h3,e=this.h4,r=this.h5,n=this.h6,o=this.h7,a=[t>>>24&255,t>>>16&255,t>>>8&255,255&t,h>>>24&255,h>>>16&255,h>>>8&255,255&h,i>>>24&255,i>>>16&255,i>>>8&255,255&i,s>>>24&255,s>>>16&255,s>>>8&255,255&s,e>>>24&255,e>>>16&255,e>>>8&255,255&e,r>>>24&255,r>>>16&255,r>>>8&255,255&r,n>>>24&255,n>>>16&255,n>>>8&255,255&n];return this.is224||a.push(o>>>24&255,o>>>16&255,o>>>8&255,255&o),a},c.prototype.array=c.prototype.digest,c.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(this.is224?28:32),h=new DataView(t);return h.setUint32(0,this.h0),h.setUint32(4,this.h1),h.setUint32(8,this.h2),h.setUint32(12,this.h3),h.setUint32(16,this.h4),h.setUint32(20,this.h5),h.setUint32(24,this.h6),this.is224||h.setUint32(28,this.h7),t},y.prototype=new c,y.prototype.finalize=function(){if(c.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();c.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(t),c.prototype.finalize.call(this)}};var p=f(),d=f(!0);p.sha256=p,p.sha224=d,p.hmac=l(),d.hmac=l(!0);const b="object"==typeof globalThis?globalThis:"object"==typeof self?self:"object"==typeof window?window:"object"==typeof global?global:void 0;return b&&(b.sha224=d),p}); +!function(t,h){"object"==typeof exports&&"undefined"!=typeof module?module.exports=h():"function"==typeof define&&define.amd?define(h):(t="undefined"!=typeof globalThis?globalThis:t||self).sha256=h()}(this,function(){"use strict";var t="undefined"!=typeof ArrayBuffer,h=function(h){if("string"===typeof h)return[h,!0];if(Array.isArray(h))return[h,!1];if(t&&h){if(h.constructor===ArrayBuffer)return[new Uint8Array(h),!1];if(ArrayBuffer.isView(h))return[new Uint8Array(h.buffer,h.byteOffset,h.byteLength),!1]}throw new Error("input is invalid type")},i="0123456789abcdef".split(""),s=[-2147483648,8388608,32768,128],e=[24,16,8,0],r=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=["hex","array","digest","arrayBuffer"],o=[],a=function(t,h){return function(i){return new c(h,!0).update(i)[t]()}},f=function(t){var h=a("hex",t);h.create=function(){return new c(t)},h.update=function(t){return h.create().update(t)};for(var i=0;i>>6,a[u++]=128|63&n):n<55296||n>=57344?(a[u++]=224|n>>>12,a[u++]=128|n>>>6&63,a[u++]=128|63&n):n<56320&&(o=t.charCodeAt(e+1))>=56320&&o<57344?(++e,n=65536+((1023&n)<<10|1023&o),a[u++]=240|n>>>18,a[u++]=128|n>>>12&63,a[u++]=128|n>>>6&63,a[u++]=128|63&n):(a[u++]=239,a[u++]=191,a[u++]=189);t=a}t.length>64&&(t=new c(i,!0).update(t).array());var l=[],y=[];for(e=0;e<64;++e){var p=t[e]||0;l[e]=92^p,y[e]=54^p}c.call(this,i,s),this.update(y),this.oKeyPad=l,this.inner=!0,this.sharedMemory=s}c.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var i=h(t);t=i[0];for(var s,r,n,o=i[1],a=0,f=t.length,u=this.blocks;a>>2]|=s<>>2]|=(192|s>>>6)<>>2]|=(128|63&s)<=57344?(u[n>>>2]|=(224|s>>>12)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<=56320&&r<57344?(++a,s=65536+((1023&s)<<10|1023&r),u[n>>>2]|=(240|s>>>18)<>>2]|=(128|s>>>12&63)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<>>2]|=239<>>2]|=191<>>2]|=189<>>2]|=t[a]<=64?(this.block=u[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},c.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,h=this.lastByteIndex;t[16]=this.block,t[h>>>2]|=s[3&h],this.block=t[16],h>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},c.prototype.hash=function(){var t,h,i,s,e,n,o,a,f,u=this.h0,l=this.h1,c=this.h2,y=this.h3,p=this.h4,d=this.h5,b=this.h6,v=this.h7,w=this.blocks;for(t=16;t<64;++t)h=((e=w[t-15])>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,i=((e=w[t-2])>>>17|e<<15)^(e>>>19|e<<13)^e>>>10,w[t]=w[t-16]+h+w[t-7]+i|0;for(f=l&c,t=0;t<64;t+=4)this.first?(this.is224?(n=300032,v=(e=w[0]-1413257819)-150054599|0,y=e+24177077|0):(n=704751109,v=(e=w[0]-210244248)-1521486534|0,y=e+143694565|0),this.first=!1):(h=(u>>>2|u<<30)^(u>>>13|u<<19)^(u>>>22|u<<10),s=(n=u&l)^u&c^f,v=y+(e=v+(i=(p>>>6|p<<26)^(p>>>11|p<<21)^(p>>>25|p<<7))+(p&d^~p&b)+r[t]+w[t])|0,y=e+(h+s)|0),h=(y>>>2|y<<30)^(y>>>13|y<<19)^(y>>>22|y<<10),s=(o=y&u)^y&l^n,b=c+(e=b+(i=(v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7))+(v&p^~v&d)+r[t+1]+w[t+1])|0,h=((c=e+(h+s)|0)>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),s=(a=c&y)^c&u^o,d=l+(e=d+(i=(b>>>6|b<<26)^(b>>>11|b<<21)^(b>>>25|b<<7))+(b&v^~b&p)+r[t+2]+w[t+2])|0,h=((l=e+(h+s)|0)>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),s=(f=l&c)^l&y^a,p=u+(e=p+(i=(d>>>6|d<<26)^(d>>>11|d<<21)^(d>>>25|d<<7))+(d&b^~d&v)+r[t+3]+w[t+3])|0,u=e+(h+s)|0,this.chromeBugWorkAround=!0;this.h0=this.h0+u|0,this.h1=this.h1+l|0,this.h2=this.h2+c|0,this.h3=this.h3+y|0,this.h4=this.h4+p|0,this.h5=this.h5+d|0,this.h6=this.h6+b|0,this.h7=this.h7+v|0},c.prototype.hex=function(){this.finalize();var t=this.h0,h=this.h1,s=this.h2,e=this.h3,r=this.h4,n=this.h5,o=this.h6,a=this.h7,f=i[t>>>28&15]+i[t>>>24&15]+i[t>>>20&15]+i[t>>>16&15]+i[t>>>12&15]+i[t>>>8&15]+i[t>>>4&15]+i[15&t]+i[h>>>28&15]+i[h>>>24&15]+i[h>>>20&15]+i[h>>>16&15]+i[h>>>12&15]+i[h>>>8&15]+i[h>>>4&15]+i[15&h]+i[s>>>28&15]+i[s>>>24&15]+i[s>>>20&15]+i[s>>>16&15]+i[s>>>12&15]+i[s>>>8&15]+i[s>>>4&15]+i[15&s]+i[e>>>28&15]+i[e>>>24&15]+i[e>>>20&15]+i[e>>>16&15]+i[e>>>12&15]+i[e>>>8&15]+i[e>>>4&15]+i[15&e]+i[r>>>28&15]+i[r>>>24&15]+i[r>>>20&15]+i[r>>>16&15]+i[r>>>12&15]+i[r>>>8&15]+i[r>>>4&15]+i[15&r]+i[n>>>28&15]+i[n>>>24&15]+i[n>>>20&15]+i[n>>>16&15]+i[n>>>12&15]+i[n>>>8&15]+i[n>>>4&15]+i[15&n]+i[o>>>28&15]+i[o>>>24&15]+i[o>>>20&15]+i[o>>>16&15]+i[o>>>12&15]+i[o>>>8&15]+i[o>>>4&15]+i[15&o];return this.is224||(f+=i[a>>>28&15]+i[a>>>24&15]+i[a>>>20&15]+i[a>>>16&15]+i[a>>>12&15]+i[a>>>8&15]+i[a>>>4&15]+i[15&a]),f},c.prototype.toString=c.prototype.hex,c.prototype.digest=function(){this.finalize();var t=this.h0,h=this.h1,i=this.h2,s=this.h3,e=this.h4,r=this.h5,n=this.h6,o=this.h7,a=[t>>>24&255,t>>>16&255,t>>>8&255,255&t,h>>>24&255,h>>>16&255,h>>>8&255,255&h,i>>>24&255,i>>>16&255,i>>>8&255,255&i,s>>>24&255,s>>>16&255,s>>>8&255,255&s,e>>>24&255,e>>>16&255,e>>>8&255,255&e,r>>>24&255,r>>>16&255,r>>>8&255,255&r,n>>>24&255,n>>>16&255,n>>>8&255,255&n];return this.is224||a.push(o>>>24&255,o>>>16&255,o>>>8&255,255&o),a},c.prototype.array=c.prototype.digest,c.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(this.is224?28:32),h=new DataView(t);return h.setUint32(0,this.h0),h.setUint32(4,this.h1),h.setUint32(8,this.h2),h.setUint32(12,this.h3),h.setUint32(16,this.h4),h.setUint32(20,this.h5),h.setUint32(24,this.h6),this.is224||h.setUint32(28,this.h7),t},y.prototype=new c,y.prototype.finalize=function(){if(c.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();c.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(t),c.prototype.finalize.call(this)}};var p=f(),d=f(!0);p.sha256=p,p.sha224=d,p.hmac=l(),d.hmac=l(!0);const b="object"==typeof globalThis?globalThis:"object"==typeof self?self:"object"==typeof window?window:"object"==typeof global?global:void 0;return b&&(b.sha224=d),p}); diff --git a/build/sha256.min.mjs b/build/sha256.min.mjs index 9860f7a..1240964 100644 --- a/build/sha256.min.mjs +++ b/build/sha256.min.mjs @@ -1,9 +1,9 @@ /** * [js-sha256]{@link https://github.com/emn178/js-sha256} * - * @version 1.0.1 + * @version 1.1.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2026 * @license MIT */ -var t="undefined"!=typeof ArrayBuffer,h=function(h){if("string"===typeof h)return[h,!0];if(Array.isArray(h))return[h,!1];if(t&&h){if(h.constructor===ArrayBuffer)return[new Uint8Array(h),!1];if(ArrayBuffer.isView(h))return[h,!1]}throw new Error("input is invalid type")},i="0123456789abcdef".split(""),s=[-2147483648,8388608,32768,128],r=[24,16,8,0],e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=["hex","array","digest","arrayBuffer"],a=[],o=function(t,h){return function(i){return new y(h,!0).update(i)[t]()}},f=function(t){var h=o("hex",t);h.create=function(){return new y(t)},h.update=function(t){return h.create().update(t)};for(var i=0;i>>6,o[u++]=128|63&n):n<55296||n>=57344?(o[u++]=224|n>>>12,o[u++]=128|n>>>6&63,o[u++]=128|63&n):n<56320&&(a=t.charCodeAt(r+1))>=56320&&a<57344?(++r,n=65536+((1023&n)<<10|1023&a),o[u++]=240|n>>>18,o[u++]=128|n>>>12&63,o[u++]=128|n>>>6&63,o[u++]=128|63&n):(o[u++]=239,o[u++]=191,o[u++]=189);t=o}t.length>64&&(t=new y(i,!0).update(t).array());var c=[],l=[];for(r=0;r<64;++r){var p=t[r]||0;c[r]=92^p,l[r]=54^p}y.call(this,i,s),this.update(l),this.oKeyPad=c,this.inner=!0,this.sharedMemory=s}y.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var i=h(t);t=i[0];for(var s,e,n,a=i[1],o=0,f=t.length,u=this.blocks;o>>2]|=s<>>2]|=(192|s>>>6)<>>2]|=(128|63&s)<=57344?(u[n>>>2]|=(224|s>>>12)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<=56320&&e<57344?(++o,s=65536+((1023&s)<<10|1023&e),u[n>>>2]|=(240|s>>>18)<>>2]|=(128|s>>>12&63)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<>>2]|=239<>>2]|=191<>>2]|=189<>>2]|=t[o]<=64?(this.block=u[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},y.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,h=this.lastByteIndex;t[16]=this.block,t[h>>>2]|=s[3&h],this.block=t[16],h>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},y.prototype.hash=function(){var t,h,i,s,r,n,a,o,f,u=this.h0,c=this.h1,y=this.h2,l=this.h3,p=this.h4,d=this.h5,b=this.h6,v=this.h7,w=this.blocks;for(t=16;t<64;++t)h=((r=w[t-15])>>>7|r<<25)^(r>>>18|r<<14)^r>>>3,i=((r=w[t-2])>>>17|r<<15)^(r>>>19|r<<13)^r>>>10,w[t]=w[t-16]+h+w[t-7]+i|0;for(f=c&y,t=0;t<64;t+=4)this.first?(this.is224?(n=300032,v=(r=w[0]-1413257819)-150054599|0,l=r+24177077|0):(n=704751109,v=(r=w[0]-210244248)-1521486534|0,l=r+143694565|0),this.first=!1):(h=(u>>>2|u<<30)^(u>>>13|u<<19)^(u>>>22|u<<10),s=(n=u&c)^u&y^f,v=l+(r=v+(i=(p>>>6|p<<26)^(p>>>11|p<<21)^(p>>>25|p<<7))+(p&d^~p&b)+e[t]+w[t])|0,l=r+(h+s)|0),h=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),s=(a=l&u)^l&c^n,b=y+(r=b+(i=(v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7))+(v&p^~v&d)+e[t+1]+w[t+1])|0,h=((y=r+(h+s)|0)>>>2|y<<30)^(y>>>13|y<<19)^(y>>>22|y<<10),s=(o=y&l)^y&u^a,d=c+(r=d+(i=(b>>>6|b<<26)^(b>>>11|b<<21)^(b>>>25|b<<7))+(b&v^~b&p)+e[t+2]+w[t+2])|0,h=((c=r+(h+s)|0)>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),s=(f=c&y)^c&l^o,p=u+(r=p+(i=(d>>>6|d<<26)^(d>>>11|d<<21)^(d>>>25|d<<7))+(d&b^~d&v)+e[t+3]+w[t+3])|0,u=r+(h+s)|0,this.chromeBugWorkAround=!0;this.h0=this.h0+u|0,this.h1=this.h1+c|0,this.h2=this.h2+y|0,this.h3=this.h3+l|0,this.h4=this.h4+p|0,this.h5=this.h5+d|0,this.h6=this.h6+b|0,this.h7=this.h7+v|0},y.prototype.hex=function(){this.finalize();var t=this.h0,h=this.h1,s=this.h2,r=this.h3,e=this.h4,n=this.h5,a=this.h6,o=this.h7,f=i[t>>>28&15]+i[t>>>24&15]+i[t>>>20&15]+i[t>>>16&15]+i[t>>>12&15]+i[t>>>8&15]+i[t>>>4&15]+i[15&t]+i[h>>>28&15]+i[h>>>24&15]+i[h>>>20&15]+i[h>>>16&15]+i[h>>>12&15]+i[h>>>8&15]+i[h>>>4&15]+i[15&h]+i[s>>>28&15]+i[s>>>24&15]+i[s>>>20&15]+i[s>>>16&15]+i[s>>>12&15]+i[s>>>8&15]+i[s>>>4&15]+i[15&s]+i[r>>>28&15]+i[r>>>24&15]+i[r>>>20&15]+i[r>>>16&15]+i[r>>>12&15]+i[r>>>8&15]+i[r>>>4&15]+i[15&r]+i[e>>>28&15]+i[e>>>24&15]+i[e>>>20&15]+i[e>>>16&15]+i[e>>>12&15]+i[e>>>8&15]+i[e>>>4&15]+i[15&e]+i[n>>>28&15]+i[n>>>24&15]+i[n>>>20&15]+i[n>>>16&15]+i[n>>>12&15]+i[n>>>8&15]+i[n>>>4&15]+i[15&n]+i[a>>>28&15]+i[a>>>24&15]+i[a>>>20&15]+i[a>>>16&15]+i[a>>>12&15]+i[a>>>8&15]+i[a>>>4&15]+i[15&a];return this.is224||(f+=i[o>>>28&15]+i[o>>>24&15]+i[o>>>20&15]+i[o>>>16&15]+i[o>>>12&15]+i[o>>>8&15]+i[o>>>4&15]+i[15&o]),f},y.prototype.toString=y.prototype.hex,y.prototype.digest=function(){this.finalize();var t=this.h0,h=this.h1,i=this.h2,s=this.h3,r=this.h4,e=this.h5,n=this.h6,a=this.h7,o=[t>>>24&255,t>>>16&255,t>>>8&255,255&t,h>>>24&255,h>>>16&255,h>>>8&255,255&h,i>>>24&255,i>>>16&255,i>>>8&255,255&i,s>>>24&255,s>>>16&255,s>>>8&255,255&s,r>>>24&255,r>>>16&255,r>>>8&255,255&r,e>>>24&255,e>>>16&255,e>>>8&255,255&e,n>>>24&255,n>>>16&255,n>>>8&255,255&n];return this.is224||o.push(a>>>24&255,a>>>16&255,a>>>8&255,255&a),o},y.prototype.array=y.prototype.digest,y.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(this.is224?28:32),h=new DataView(t);return h.setUint32(0,this.h0),h.setUint32(4,this.h1),h.setUint32(8,this.h2),h.setUint32(12,this.h3),h.setUint32(16,this.h4),h.setUint32(20,this.h5),h.setUint32(24,this.h6),this.is224||h.setUint32(28,this.h7),t},l.prototype=new y,l.prototype.finalize=function(){if(y.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();y.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(t),y.prototype.finalize.call(this)}};var p=f(),d=f(!0);p.sha256=p,p.sha224=d,p.hmac=c(),d.hmac=c(!0);export{p as default,d as sha224,p as sha256}; +var t="undefined"!=typeof ArrayBuffer,h=function(h){if("string"===typeof h)return[h,!0];if(Array.isArray(h))return[h,!1];if(t&&h){if(h.constructor===ArrayBuffer)return[new Uint8Array(h),!1];if(ArrayBuffer.isView(h))return[new Uint8Array(h.buffer,h.byteOffset,h.byteLength),!1]}throw new Error("input is invalid type")},i="0123456789abcdef".split(""),s=[-2147483648,8388608,32768,128],e=[24,16,8,0],r=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=["hex","array","digest","arrayBuffer"],a=[],o=function(t,h){return function(i){return new y(h,!0).update(i)[t]()}},f=function(t){var h=o("hex",t);h.create=function(){return new y(t)},h.update=function(t){return h.create().update(t)};for(var i=0;i>>6,o[u++]=128|63&n):n<55296||n>=57344?(o[u++]=224|n>>>12,o[u++]=128|n>>>6&63,o[u++]=128|63&n):n<56320&&(a=t.charCodeAt(e+1))>=56320&&a<57344?(++e,n=65536+((1023&n)<<10|1023&a),o[u++]=240|n>>>18,o[u++]=128|n>>>12&63,o[u++]=128|n>>>6&63,o[u++]=128|63&n):(o[u++]=239,o[u++]=191,o[u++]=189);t=o}t.length>64&&(t=new y(i,!0).update(t).array());var c=[],l=[];for(e=0;e<64;++e){var p=t[e]||0;c[e]=92^p,l[e]=54^p}y.call(this,i,s),this.update(l),this.oKeyPad=c,this.inner=!0,this.sharedMemory=s}y.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var i=h(t);t=i[0];for(var s,r,n,a=i[1],o=0,f=t.length,u=this.blocks;o>>2]|=s<>>2]|=(192|s>>>6)<>>2]|=(128|63&s)<=57344?(u[n>>>2]|=(224|s>>>12)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<=56320&&r<57344?(++o,s=65536+((1023&s)<<10|1023&r),u[n>>>2]|=(240|s>>>18)<>>2]|=(128|s>>>12&63)<>>2]|=(128|s>>>6&63)<>>2]|=(128|63&s)<>>2]|=239<>>2]|=191<>>2]|=189<>>2]|=t[o]<=64?(this.block=u[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},y.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,h=this.lastByteIndex;t[16]=this.block,t[h>>>2]|=s[3&h],this.block=t[16],h>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},y.prototype.hash=function(){var t,h,i,s,e,n,a,o,f,u=this.h0,c=this.h1,y=this.h2,l=this.h3,p=this.h4,d=this.h5,b=this.h6,v=this.h7,w=this.blocks;for(t=16;t<64;++t)h=((e=w[t-15])>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,i=((e=w[t-2])>>>17|e<<15)^(e>>>19|e<<13)^e>>>10,w[t]=w[t-16]+h+w[t-7]+i|0;for(f=c&y,t=0;t<64;t+=4)this.first?(this.is224?(n=300032,v=(e=w[0]-1413257819)-150054599|0,l=e+24177077|0):(n=704751109,v=(e=w[0]-210244248)-1521486534|0,l=e+143694565|0),this.first=!1):(h=(u>>>2|u<<30)^(u>>>13|u<<19)^(u>>>22|u<<10),s=(n=u&c)^u&y^f,v=l+(e=v+(i=(p>>>6|p<<26)^(p>>>11|p<<21)^(p>>>25|p<<7))+(p&d^~p&b)+r[t]+w[t])|0,l=e+(h+s)|0),h=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),s=(a=l&u)^l&c^n,b=y+(e=b+(i=(v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7))+(v&p^~v&d)+r[t+1]+w[t+1])|0,h=((y=e+(h+s)|0)>>>2|y<<30)^(y>>>13|y<<19)^(y>>>22|y<<10),s=(o=y&l)^y&u^a,d=c+(e=d+(i=(b>>>6|b<<26)^(b>>>11|b<<21)^(b>>>25|b<<7))+(b&v^~b&p)+r[t+2]+w[t+2])|0,h=((c=e+(h+s)|0)>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),s=(f=c&y)^c&l^o,p=u+(e=p+(i=(d>>>6|d<<26)^(d>>>11|d<<21)^(d>>>25|d<<7))+(d&b^~d&v)+r[t+3]+w[t+3])|0,u=e+(h+s)|0,this.chromeBugWorkAround=!0;this.h0=this.h0+u|0,this.h1=this.h1+c|0,this.h2=this.h2+y|0,this.h3=this.h3+l|0,this.h4=this.h4+p|0,this.h5=this.h5+d|0,this.h6=this.h6+b|0,this.h7=this.h7+v|0},y.prototype.hex=function(){this.finalize();var t=this.h0,h=this.h1,s=this.h2,e=this.h3,r=this.h4,n=this.h5,a=this.h6,o=this.h7,f=i[t>>>28&15]+i[t>>>24&15]+i[t>>>20&15]+i[t>>>16&15]+i[t>>>12&15]+i[t>>>8&15]+i[t>>>4&15]+i[15&t]+i[h>>>28&15]+i[h>>>24&15]+i[h>>>20&15]+i[h>>>16&15]+i[h>>>12&15]+i[h>>>8&15]+i[h>>>4&15]+i[15&h]+i[s>>>28&15]+i[s>>>24&15]+i[s>>>20&15]+i[s>>>16&15]+i[s>>>12&15]+i[s>>>8&15]+i[s>>>4&15]+i[15&s]+i[e>>>28&15]+i[e>>>24&15]+i[e>>>20&15]+i[e>>>16&15]+i[e>>>12&15]+i[e>>>8&15]+i[e>>>4&15]+i[15&e]+i[r>>>28&15]+i[r>>>24&15]+i[r>>>20&15]+i[r>>>16&15]+i[r>>>12&15]+i[r>>>8&15]+i[r>>>4&15]+i[15&r]+i[n>>>28&15]+i[n>>>24&15]+i[n>>>20&15]+i[n>>>16&15]+i[n>>>12&15]+i[n>>>8&15]+i[n>>>4&15]+i[15&n]+i[a>>>28&15]+i[a>>>24&15]+i[a>>>20&15]+i[a>>>16&15]+i[a>>>12&15]+i[a>>>8&15]+i[a>>>4&15]+i[15&a];return this.is224||(f+=i[o>>>28&15]+i[o>>>24&15]+i[o>>>20&15]+i[o>>>16&15]+i[o>>>12&15]+i[o>>>8&15]+i[o>>>4&15]+i[15&o]),f},y.prototype.toString=y.prototype.hex,y.prototype.digest=function(){this.finalize();var t=this.h0,h=this.h1,i=this.h2,s=this.h3,e=this.h4,r=this.h5,n=this.h6,a=this.h7,o=[t>>>24&255,t>>>16&255,t>>>8&255,255&t,h>>>24&255,h>>>16&255,h>>>8&255,255&h,i>>>24&255,i>>>16&255,i>>>8&255,255&i,s>>>24&255,s>>>16&255,s>>>8&255,255&s,e>>>24&255,e>>>16&255,e>>>8&255,255&e,r>>>24&255,r>>>16&255,r>>>8&255,255&r,n>>>24&255,n>>>16&255,n>>>8&255,255&n];return this.is224||o.push(a>>>24&255,a>>>16&255,a>>>8&255,255&a),o},y.prototype.array=y.prototype.digest,y.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(this.is224?28:32),h=new DataView(t);return h.setUint32(0,this.h0),h.setUint32(4,this.h1),h.setUint32(8,this.h2),h.setUint32(12,this.h3),h.setUint32(16,this.h4),h.setUint32(20,this.h5),h.setUint32(24,this.h6),this.is224||h.setUint32(28,this.h7),t},l.prototype=new y,l.prototype.finalize=function(){if(y.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();y.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(t),y.prototype.finalize.call(this)}};var p=f(),d=f(!0);p.sha256=p,p.sha224=d,p.hmac=c(),d.hmac=c(!0);export{p as default,d as sha224,p as sha256}; diff --git a/build/sha256.node.cjs b/build/sha256.node.cjs index 5936401..dd1814a 100644 --- a/build/sha256.node.cjs +++ b/build/sha256.node.cjs @@ -1,7 +1,7 @@ /** * [js-sha256]{@link https://github.com/emn178/js-sha256} * - * @version 1.0.1 + * @version 1.1.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2026 * @license MIT @@ -27,7 +27,8 @@ var formatMessage = function (message) { if (message.constructor === ArrayBuffer) { return [new Uint8Array(message), false]; } else if (ArrayBuffer.isView(message)) { - return [message, false]; + // read the underlying bytes of any view (Int8Array, DataView, Uint16Array, ...) + return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false]; } } throw new Error(INPUT_ERROR); diff --git a/index.d.ts b/index.d.ts index 20a7e67..ce4dd1d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -type Message = string | number[] | ArrayBuffer | Uint8Array; +type Message = string | number[] | ArrayBuffer | ArrayBufferView; interface Hasher { /** diff --git a/package-lock.json b/package-lock.json index 835218f..80937be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "js-sha256", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "js-sha256", - "version": "1.0.1", + "version": "1.1.0", "license": "MIT", "devDependencies": { "@playwright/test": "^1.62.0", diff --git a/package.json b/package.json index 814b123..d95fcf4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-sha256", - "version": "1.0.1", + "version": "1.1.0", "description": "A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.", "main": "build/sha256.node.cjs", "module": "src/index.mjs", diff --git a/src/shared.mjs b/src/shared.mjs index 0b20caa..7c9652f 100644 --- a/src/shared.mjs +++ b/src/shared.mjs @@ -15,7 +15,8 @@ export var formatMessage = function (message) { if (message.constructor === ArrayBuffer) { return [new Uint8Array(message), false]; } else if (ArrayBuffer.isView(message)) { - return [message, false]; + // read the underlying bytes of any view (Int8Array, DataView, Uint16Array, ...) + return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false]; } } throw new Error(INPUT_ERROR); diff --git a/tests/test.js b/tests/test.js index ce36018..4e01cf5 100644 --- a/tests/test.js +++ b/tests/test.js @@ -100,6 +100,11 @@ 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855': new ArrayBuffer(0), '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d': new ArrayBuffer(1) }; + testCases.sha256['ArrayBuffer view'] = { + '8885cb2424931045cbc3f70dec12f60f965993ebeb8636ec49e5011335227349': new Int8Array([-1, -128, 65, 0, -2]), + '25dfd29c09617dcc9852281c030e5b3037a338a4712a42a21c907f259c6412a0': new Uint16Array(new Uint8Array([2, 1]).buffer), + '3733cd977ff8eb18b987357e22ced99f46097f31ecb239e878ae63760e83e4d5': new DataView(new Uint8Array([9, 72, 69, 76, 76, 79, 9]).buffer, 1, 5) + }; testCases.sha224.Uint8Array = { 'e17541396a3ecd1cd5a2b968b84e597e8eae3b0ea3127963bf48dd3b': new Uint8Array([211, 212]), '730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) @@ -112,6 +117,11 @@ 'fff9292b4201617bdc4d3053fce02734166a683d7d858a7f5f59b073': new ArrayBuffer(1), }; + testCases.sha224['ArrayBuffer view'] = { + 'd1cb7c6fa5082db7f0dd9748e3e5018e071e3ec6719ed5f58973b145': new Int8Array([-1, -128, 65, 0, -2]), + '0ad90774f63f37bfe02760a853cf4f1fe8d1911849f47c9afe479f7e': new Uint16Array(new Uint8Array([2, 1]).buffer), + 'ddb584a8a86bf5f4b700262bf5901f473d133869fac0ad86215ed2ec': new DataView(new Uint8Array([9, 72, 69, 76, 76, 79, 9]).buffer, 1, 5) + }; testCases.sha256.Buffer = { 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855': Buffer.from([]), 'd7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592': Buffer.from(new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]))