mirror of
https://github.com/emn178/js-sha512.git
synced 2026-08-12 20:31:34 +08:00
Added
- Streaming support(update). - support for ArrayBuffer input/output. - support for byte array input/output.
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## v0.4.0 / 2017-07-08
|
||||||
|
### Added
|
||||||
|
- Streaming support(update).
|
||||||
|
- support for ArrayBuffer input/output.
|
||||||
|
- support for byte array input/output.
|
||||||
|
|
||||||
## v0.3.0 / 2017-01-23
|
## v0.3.0 / 2017-01-23
|
||||||
### Added
|
### Added
|
||||||
- AMD support.
|
- AMD support.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- ArrayBuffer dosen't work in Webpack.
|
- ArrayBuffer dosen't work in Webpack.
|
||||||
|
|
||||||
@@ -13,20 +20,24 @@
|
|||||||
## v0.2.1 / 2015-02-08
|
## v0.2.1 / 2015-02-08
|
||||||
### Added
|
### Added
|
||||||
- test cases.
|
- test cases.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- ascii parameter.
|
- ascii parameter.
|
||||||
|
|
||||||
### Improved
|
### Improved
|
||||||
- performance.
|
- performance.
|
||||||
|
|
||||||
## v0.2.0 / 2015-02-02
|
## v0.2.0 / 2015-02-02
|
||||||
### Added
|
### Added
|
||||||
- test cases.
|
- test cases.
|
||||||
|
|
||||||
### Improved
|
### Improved
|
||||||
- performance.
|
- performance.
|
||||||
|
|
||||||
## v0.1.3 / 2015-01-26
|
## v0.1.3 / 2015-01-26
|
||||||
### Added
|
### Added
|
||||||
- test cases.
|
- test cases.
|
||||||
|
|
||||||
### Improved
|
### Improved
|
||||||
- performance.
|
- performance.
|
||||||
|
|
||||||
@@ -35,6 +46,7 @@
|
|||||||
- bower package.
|
- bower package.
|
||||||
- travis.
|
- travis.
|
||||||
- coveralls.
|
- coveralls.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- JSHint warnings.
|
- JSHint warnings.
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ sha512('Message to hash');
|
|||||||
sha384('Message to hash');
|
sha384('Message to hash');
|
||||||
sha512_256('Message to hash');
|
sha512_256('Message to hash');
|
||||||
sha512_224('Message to hash');
|
sha512_224('Message to hash');
|
||||||
|
|
||||||
|
var hash = sha512.create();
|
||||||
|
hash.update('Message to hash');
|
||||||
|
hash.hex();
|
||||||
|
|
||||||
|
var hash2 = sha512.update('Message to hash');
|
||||||
|
hash2.update('Message2 to hash');
|
||||||
|
hash2.array();
|
||||||
```
|
```
|
||||||
If you use node.js, you should require the module first:
|
If you use node.js, you should require the module first:
|
||||||
```JavaScript
|
```JavaScript
|
||||||
@@ -69,6 +77,13 @@ sha512('中文'); // 8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a27
|
|||||||
sha384('中文'); // 93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c
|
sha384('中文'); // 93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c
|
||||||
sha512_256('中文'); // b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72
|
sha512_256('中文'); // b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72
|
||||||
sha512_224('中文'); // 0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed188
|
sha512_224('中文'); // 0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed188
|
||||||
|
|
||||||
|
// Different output
|
||||||
|
sha512(''); // cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||||
|
sha512.hex(''); // cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||||
|
sha512.array(''); // [207, 131, 225, 53, 126, 239, 184, 189, 241, 84, 40, 80, 214, 109, 128, 7, 214, 32, 228, 5, 11, 87, 21, 220, 131, 244, 169, 33, 211, 108, 233, 206, 71, 208, 209, 60, 93, 133, 242, 176, 255, 131, 24, 210, 135, 126, 236, 47, 99, 185, 49, 189, 71, 65, 122, 129, 165, 56, 50, 122, 249, 39, 218, 62]
|
||||||
|
sha512.digest(''); // [207, 131, 225, 53, 126, 239, 184, 189, 241, 84, 40, 80, 214, 109, 128, 7, 214, 32, 228, 5, 11, 87, 21, 220, 131, 244, 169, 33, 211, 108, 233, 206, 71, 208, 209, 60, 93, 133, 242, 176, 255, 131, 24, 210, 135, 126, 236, 47, 99, 185, 49, 189, 71, 65, 122, 129, 165, 56, 50, 122, 249, 39, 218, 62]
|
||||||
|
sha512.arrayBuffer(''); // ArrayBuffer
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "js-sha512",
|
"name": "js-sha512",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"main": ["src/sha512.js"],
|
"main": ["src/sha512.js"],
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"samples",
|
"samples",
|
||||||
|
|||||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "js-sha512",
|
"name": "js-sha512",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"description": "This is a simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.",
|
"description": "This is a simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.",
|
||||||
"main": "src/sha512.js",
|
"main": "src/sha512.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
+287
-119
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* [js-sha512]{@link https://github.com/emn178/js-sha512}
|
* [js-sha512]{@link https://github.com/emn178/js-sha512}
|
||||||
*
|
*
|
||||||
* @version 0.3.0
|
* @version 0.4.0
|
||||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||||
* @copyright Chen, Yi-Cyuan 2014-2017
|
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||||
* @license MIT
|
* @license MIT
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
}
|
}
|
||||||
var COMMON_JS = !root.JS_SHA512_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
var COMMON_JS = !root.JS_SHA512_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
||||||
var AMD = typeof define === 'function' && define.amd;
|
var AMD = typeof define === 'function' && define.amd;
|
||||||
|
var ARRAY_BUFFER = typeof ArrayBuffer !== 'undefined';
|
||||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||||
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
||||||
var SHIFT = [24, 16, 8, 0];
|
var SHIFT = [24, 16, 8, 0];
|
||||||
@@ -63,101 +64,135 @@
|
|||||||
0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817
|
0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
|
||||||
|
|
||||||
var blocks = [];
|
var blocks = [];
|
||||||
|
|
||||||
var sha384 = function (message) {
|
var createOutputMethod = function (outputType, bits) {
|
||||||
return sha512(message, 384);
|
return function (message) {
|
||||||
|
return new Sha512(bits, true).update(message)[outputType]();
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var sha512_256 = function (message) {
|
var createMethod = function (bits) {
|
||||||
return sha512(message, 256);
|
var method = createOutputMethod('hex', bits);
|
||||||
|
method.create = function () {
|
||||||
|
return new Sha512(bits);
|
||||||
|
};
|
||||||
|
method.update = function (message) {
|
||||||
|
return method.create().update(message);
|
||||||
|
};
|
||||||
|
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
||||||
|
var type = OUTPUT_TYPES[i];
|
||||||
|
method[type] = createOutputMethod(type, bits);
|
||||||
|
}
|
||||||
|
return method;
|
||||||
};
|
};
|
||||||
|
|
||||||
var sha512_224 = function (message) {
|
function Sha512(bits, sharedMemory) {
|
||||||
return sha512(message, 224);
|
if (sharedMemory) {
|
||||||
};
|
blocks[0] = blocks[1] = blocks[2] = blocks[3] = blocks[4] =
|
||||||
|
blocks[5] = blocks[6] = blocks[7] = blocks[8] =
|
||||||
var sha512 = function (message, bits) {
|
blocks[9] = blocks[10] = blocks[11] = blocks[12] =
|
||||||
var h0h, h0l, h1h, h1l, h2h, h2l, h3h, h3l,
|
blocks[13] = blocks[14] = blocks[15] = blocks[16] =
|
||||||
h4h, h4l, h5h, h5l, h6h, h6l, h7h, h7l, block, code, end = false,
|
blocks[17] = blocks[18] = blocks[19] = blocks[20] =
|
||||||
i, j, index = 0, start = 0, bytes = 0, length = message.length,
|
blocks[21] = blocks[22] = blocks[23] = blocks[24] =
|
||||||
s0h, s0l, s1h, s1l, c1, c2, c3, c4,
|
blocks[25] = blocks[26] = blocks[27] = blocks[28] =
|
||||||
abh, abl, dah, dal, cdh, cdl, bch, bcl,
|
blocks[29] = blocks[30] = blocks[31] = blocks[32] = 0;
|
||||||
majh, majl, t1h, t1l, t2h, t2l, chh, chl;
|
this.blocks = blocks;
|
||||||
|
} else {
|
||||||
|
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
|
}
|
||||||
|
|
||||||
if (bits == 384) {
|
if (bits == 384) {
|
||||||
h0h = 0xCBBB9D5D;
|
this.h0h = 0xCBBB9D5D;
|
||||||
h0l = 0xC1059ED8;
|
this.h0l = 0xC1059ED8;
|
||||||
h1h = 0x629A292A;
|
this.h1h = 0x629A292A;
|
||||||
h1l = 0x367CD507;
|
this.h1l = 0x367CD507;
|
||||||
h2h = 0x9159015A;
|
this.h2h = 0x9159015A;
|
||||||
h2l = 0x3070DD17;
|
this.h2l = 0x3070DD17;
|
||||||
h3h = 0x152FECD8;
|
this.h3h = 0x152FECD8;
|
||||||
h3l = 0xF70E5939;
|
this.h3l = 0xF70E5939;
|
||||||
h4h = 0x67332667;
|
this.h4h = 0x67332667;
|
||||||
h4l = 0xFFC00B31;
|
this.h4l = 0xFFC00B31;
|
||||||
h5h = 0x8EB44A87;
|
this.h5h = 0x8EB44A87;
|
||||||
h5l = 0x68581511;
|
this.h5l = 0x68581511;
|
||||||
h6h = 0xDB0C2E0D;
|
this.h6h = 0xDB0C2E0D;
|
||||||
h6l = 0x64F98FA7;
|
this.h6l = 0x64F98FA7;
|
||||||
h7h = 0x47B5481D;
|
this.h7h = 0x47B5481D;
|
||||||
h7l = 0xBEFA4FA4;
|
this.h7l = 0xBEFA4FA4;
|
||||||
} else if (bits == 256) {
|
} else if (bits == 256) {
|
||||||
h0h = 0x22312194;
|
this.h0h = 0x22312194;
|
||||||
h0l = 0xFC2BF72C;
|
this.h0l = 0xFC2BF72C;
|
||||||
h1h = 0x9F555FA3;
|
this.h1h = 0x9F555FA3;
|
||||||
h1l = 0xC84C64C2;
|
this.h1l = 0xC84C64C2;
|
||||||
h2h = 0x2393B86B;
|
this.h2h = 0x2393B86B;
|
||||||
h2l = 0x6F53B151;
|
this.h2l = 0x6F53B151;
|
||||||
h3h = 0x96387719;
|
this.h3h = 0x96387719;
|
||||||
h3l = 0x5940EABD;
|
this.h3l = 0x5940EABD;
|
||||||
h4h = 0x96283EE2;
|
this.h4h = 0x96283EE2;
|
||||||
h4l = 0xA88EFFE3;
|
this.h4l = 0xA88EFFE3;
|
||||||
h5h = 0xBE5E1E25;
|
this.h5h = 0xBE5E1E25;
|
||||||
h5l = 0x53863992;
|
this.h5l = 0x53863992;
|
||||||
h6h = 0x2B0199FC;
|
this.h6h = 0x2B0199FC;
|
||||||
h6l = 0x2C85B8AA;
|
this.h6l = 0x2C85B8AA;
|
||||||
h7h = 0x0EB72DDC;
|
this.h7h = 0x0EB72DDC;
|
||||||
h7l = 0x81C52CA2;
|
this.h7l = 0x81C52CA2;
|
||||||
} else if (bits == 224) {
|
} else if (bits == 224) {
|
||||||
h0h = 0x8C3D37C8;
|
this.h0h = 0x8C3D37C8;
|
||||||
h0l = 0x19544DA2;
|
this.h0l = 0x19544DA2;
|
||||||
h1h = 0x73E19966;
|
this.h1h = 0x73E19966;
|
||||||
h1l = 0x89DCD4D6;
|
this.h1l = 0x89DCD4D6;
|
||||||
h2h = 0x1DFAB7AE;
|
this.h2h = 0x1DFAB7AE;
|
||||||
h2l = 0x32FF9C82;
|
this.h2l = 0x32FF9C82;
|
||||||
h3h = 0x679DD514;
|
this.h3h = 0x679DD514;
|
||||||
h3l = 0x582F9FCF;
|
this.h3l = 0x582F9FCF;
|
||||||
h4h = 0x0F6D2B69;
|
this.h4h = 0x0F6D2B69;
|
||||||
h4l = 0x7BD44DA8;
|
this.h4l = 0x7BD44DA8;
|
||||||
h5h = 0x77E36F73;
|
this.h5h = 0x77E36F73;
|
||||||
h5l = 0x04C48942;
|
this.h5l = 0x04C48942;
|
||||||
h6h = 0x3F9D85A8;
|
this.h6h = 0x3F9D85A8;
|
||||||
h6l = 0x6A1D36C8;
|
this.h6l = 0x6A1D36C8;
|
||||||
h7h = 0x1112E6AD;
|
this.h7h = 0x1112E6AD;
|
||||||
h7l = 0x91D692A1;
|
this.h7l = 0x91D692A1;
|
||||||
} else { // 512
|
} else { // 512
|
||||||
h0h = 0x6A09E667;
|
this.h0h = 0x6A09E667;
|
||||||
h0l = 0xF3BCC908;
|
this.h0l = 0xF3BCC908;
|
||||||
h1h = 0xBB67AE85;
|
this.h1h = 0xBB67AE85;
|
||||||
h1l = 0x84CAA73B;
|
this.h1l = 0x84CAA73B;
|
||||||
h2h = 0x3C6EF372;
|
this.h2h = 0x3C6EF372;
|
||||||
h2l = 0xFE94F82B;
|
this.h2l = 0xFE94F82B;
|
||||||
h3h = 0xA54FF53A;
|
this.h3h = 0xA54FF53A;
|
||||||
h3l = 0x5F1D36F1;
|
this.h3l = 0x5F1D36F1;
|
||||||
h4h = 0x510E527F;
|
this.h4h = 0x510E527F;
|
||||||
h4l = 0xADE682D1;
|
this.h4l = 0xADE682D1;
|
||||||
h5h = 0x9B05688C;
|
this.h5h = 0x9B05688C;
|
||||||
h5l = 0x2B3E6C1F;
|
this.h5l = 0x2B3E6C1F;
|
||||||
h6h = 0x1F83D9AB;
|
this.h6h = 0x1F83D9AB;
|
||||||
h6l = 0xFB41BD6B;
|
this.h6l = 0xFB41BD6B;
|
||||||
h7h = 0x5BE0CD19;
|
this.h7h = 0x5BE0CD19;
|
||||||
h7l = 0x137E2179;
|
this.h7l = 0x137E2179;
|
||||||
bits = 512;
|
|
||||||
}
|
}
|
||||||
block = 0;
|
this.bits = bits;
|
||||||
do {
|
|
||||||
blocks[0] = block;
|
this.block = this.start = this.bytes = 0;
|
||||||
|
this.finalized = this.hashed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sha512.prototype.update = function (message) {
|
||||||
|
if (this.finalized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var notString = typeof(message) !== 'string';
|
||||||
|
if (notString && ARRAY_BUFFER && message instanceof root.ArrayBuffer) {
|
||||||
|
message = new Uint8Array(message);
|
||||||
|
}
|
||||||
|
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
|
||||||
|
|
||||||
|
while (index < length) {
|
||||||
|
if (this.hashed) {
|
||||||
|
this.hashed = false;
|
||||||
|
blocks[0] = this.block;
|
||||||
blocks[1] = blocks[2] = blocks[3] = blocks[4] =
|
blocks[1] = blocks[2] = blocks[3] = blocks[4] =
|
||||||
blocks[5] = blocks[6] = blocks[7] = blocks[8] =
|
blocks[5] = blocks[6] = blocks[7] = blocks[8] =
|
||||||
blocks[9] = blocks[10] = blocks[11] = blocks[12] =
|
blocks[9] = blocks[10] = blocks[11] = blocks[12] =
|
||||||
@@ -166,7 +201,14 @@
|
|||||||
blocks[21] = blocks[22] = blocks[23] = blocks[24] =
|
blocks[21] = blocks[22] = blocks[23] = blocks[24] =
|
||||||
blocks[25] = blocks[26] = blocks[27] = blocks[28] =
|
blocks[25] = blocks[26] = blocks[27] = blocks[28] =
|
||||||
blocks[29] = blocks[30] = blocks[31] = blocks[32] = 0;
|
blocks[29] = blocks[30] = blocks[31] = blocks[32] = 0;
|
||||||
for (i = start; index < length && i < 128; ++index) {
|
}
|
||||||
|
|
||||||
|
if(notString) {
|
||||||
|
for (i = this.start; index < length && i < 128; ++index) {
|
||||||
|
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = this.start; index < length && i < 128; ++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];
|
||||||
@@ -185,17 +227,57 @@
|
|||||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes += i - start;
|
}
|
||||||
start = i - 128;
|
|
||||||
if (index == length) {
|
this.lastByteIndex = i;
|
||||||
|
this.bytes += i - this.start;
|
||||||
|
if (i >= 128) {
|
||||||
|
this.block = blocks[32];
|
||||||
|
this.start = i - 128;
|
||||||
|
this.hash();
|
||||||
|
this.hashed = true;
|
||||||
|
} else {
|
||||||
|
this.start = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
Sha512.prototype.finalize = function () {
|
||||||
|
if (this.finalized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.finalized = true;
|
||||||
|
var blocks = this.blocks, i = this.lastByteIndex;
|
||||||
|
blocks[32] = this.block;
|
||||||
blocks[i >> 2] |= EXTRA[i & 3];
|
blocks[i >> 2] |= EXTRA[i & 3];
|
||||||
++index;
|
this.block = blocks[32];
|
||||||
|
if (i >= 112) {
|
||||||
|
if (!this.hashed) {
|
||||||
|
this.hash();
|
||||||
}
|
}
|
||||||
block = blocks[32];
|
blocks[0] = this.block;
|
||||||
if (index > length && i < 112) {
|
blocks[1] = blocks[2] = blocks[3] = blocks[4] =
|
||||||
blocks[31] = bytes << 3;
|
blocks[5] = blocks[6] = blocks[7] = blocks[8] =
|
||||||
end = true;
|
blocks[9] = blocks[10] = blocks[11] = blocks[12] =
|
||||||
|
blocks[13] = blocks[14] = blocks[15] = blocks[16] =
|
||||||
|
blocks[17] = blocks[18] = blocks[19] = blocks[20] =
|
||||||
|
blocks[21] = blocks[22] = blocks[23] = blocks[24] =
|
||||||
|
blocks[25] = blocks[26] = blocks[27] = blocks[28] =
|
||||||
|
blocks[29] = blocks[30] = blocks[31] = blocks[32] = 0;
|
||||||
}
|
}
|
||||||
|
blocks[31] = this.bytes << 3;
|
||||||
|
this.hash();
|
||||||
|
};
|
||||||
|
|
||||||
|
Sha512.prototype.hash = function () {
|
||||||
|
var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l,
|
||||||
|
h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l,
|
||||||
|
h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l,
|
||||||
|
h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l,
|
||||||
|
blocks = this.blocks, j, s0h, s0l, s1h, s1l, c1, c2, c3, c4,
|
||||||
|
abh, abl, dah, dal, cdh, cdl, bch, bcl,
|
||||||
|
majh, majl, t1h, t1l, t2h, t2l, chh, chl;
|
||||||
|
|
||||||
for (j = 32; j < 160; j += 2) {
|
for (j = 32; j < 160; j += 2) {
|
||||||
t1h = blocks[j - 30];
|
t1h = blocks[j - 30];
|
||||||
@@ -436,65 +518,74 @@
|
|||||||
c3 = (h0h & 0xFFFF) + (ah & 0xFFFF) + (c2 >>> 16);
|
c3 = (h0h & 0xFFFF) + (ah & 0xFFFF) + (c2 >>> 16);
|
||||||
c4 = (h0h >>> 16) + (ah >>> 16) + (c3 >>> 16);
|
c4 = (h0h >>> 16) + (ah >>> 16) + (c3 >>> 16);
|
||||||
|
|
||||||
h0h = (c4 << 16) | (c3 & 0xFFFF);
|
this.h0h = (c4 << 16) | (c3 & 0xFFFF);
|
||||||
h0l = (c2 << 16) | (c1 & 0xFFFF);
|
this.h0l = (c2 << 16) | (c1 & 0xFFFF);
|
||||||
|
|
||||||
c1 = (h1l & 0xFFFF) + (bl & 0xFFFF);
|
c1 = (h1l & 0xFFFF) + (bl & 0xFFFF);
|
||||||
c2 = (h1l >>> 16) + (bl >>> 16) + (c1 >>> 16);
|
c2 = (h1l >>> 16) + (bl >>> 16) + (c1 >>> 16);
|
||||||
c3 = (h1h & 0xFFFF) + (bh & 0xFFFF) + (c2 >>> 16);
|
c3 = (h1h & 0xFFFF) + (bh & 0xFFFF) + (c2 >>> 16);
|
||||||
c4 = (h1h >>> 16) + (bh >>> 16) + (c3 >>> 16);
|
c4 = (h1h >>> 16) + (bh >>> 16) + (c3 >>> 16);
|
||||||
|
|
||||||
h1h = (c4 << 16) | (c3 & 0xFFFF);
|
this.h1h = (c4 << 16) | (c3 & 0xFFFF);
|
||||||
h1l = (c2 << 16) | (c1 & 0xFFFF);
|
this.h1l = (c2 << 16) | (c1 & 0xFFFF);
|
||||||
|
|
||||||
c1 = (h2l & 0xFFFF) + (cl & 0xFFFF);
|
c1 = (h2l & 0xFFFF) + (cl & 0xFFFF);
|
||||||
c2 = (h2l >>> 16) + (cl >>> 16) + (c1 >>> 16);
|
c2 = (h2l >>> 16) + (cl >>> 16) + (c1 >>> 16);
|
||||||
c3 = (h2h & 0xFFFF) + (ch & 0xFFFF) + (c2 >>> 16);
|
c3 = (h2h & 0xFFFF) + (ch & 0xFFFF) + (c2 >>> 16);
|
||||||
c4 = (h2h >>> 16) + (ch >>> 16) + (c3 >>> 16);
|
c4 = (h2h >>> 16) + (ch >>> 16) + (c3 >>> 16);
|
||||||
|
|
||||||
h2h = (c4 << 16) | (c3 & 0xFFFF);
|
this.h2h = (c4 << 16) | (c3 & 0xFFFF);
|
||||||
h2l = (c2 << 16) | (c1 & 0xFFFF);
|
this.h2l = (c2 << 16) | (c1 & 0xFFFF);
|
||||||
|
|
||||||
c1 = (h3l & 0xFFFF) + (dl & 0xFFFF);
|
c1 = (h3l & 0xFFFF) + (dl & 0xFFFF);
|
||||||
c2 = (h3l >>> 16) + (dl >>> 16) + (c1 >>> 16);
|
c2 = (h3l >>> 16) + (dl >>> 16) + (c1 >>> 16);
|
||||||
c3 = (h3h & 0xFFFF) + (dh & 0xFFFF) + (c2 >>> 16);
|
c3 = (h3h & 0xFFFF) + (dh & 0xFFFF) + (c2 >>> 16);
|
||||||
c4 = (h3h >>> 16) + (dh >>> 16) + (c3 >>> 16);
|
c4 = (h3h >>> 16) + (dh >>> 16) + (c3 >>> 16);
|
||||||
|
|
||||||
h3h = (c4 << 16) | (c3 & 0xFFFF);
|
this.h3h = (c4 << 16) | (c3 & 0xFFFF);
|
||||||
h3l = (c2 << 16) | (c1 & 0xFFFF);
|
this.h3l = (c2 << 16) | (c1 & 0xFFFF);
|
||||||
|
|
||||||
c1 = (h4l & 0xFFFF) + (el & 0xFFFF);
|
c1 = (h4l & 0xFFFF) + (el & 0xFFFF);
|
||||||
c2 = (h4l >>> 16) + (el >>> 16) + (c1 >>> 16);
|
c2 = (h4l >>> 16) + (el >>> 16) + (c1 >>> 16);
|
||||||
c3 = (h4h & 0xFFFF) + (eh & 0xFFFF) + (c2 >>> 16);
|
c3 = (h4h & 0xFFFF) + (eh & 0xFFFF) + (c2 >>> 16);
|
||||||
c4 = (h4h >>> 16) + (eh >>> 16) + (c3 >>> 16);
|
c4 = (h4h >>> 16) + (eh >>> 16) + (c3 >>> 16);
|
||||||
|
|
||||||
h4h = (c4 << 16) | (c3 & 0xFFFF);
|
this.h4h = (c4 << 16) | (c3 & 0xFFFF);
|
||||||
h4l = (c2 << 16) | (c1 & 0xFFFF);
|
this.h4l = (c2 << 16) | (c1 & 0xFFFF);
|
||||||
|
|
||||||
c1 = (h5l & 0xFFFF) + (fl & 0xFFFF);
|
c1 = (h5l & 0xFFFF) + (fl & 0xFFFF);
|
||||||
c2 = (h5l >>> 16) + (fl >>> 16) + (c1 >>> 16);
|
c2 = (h5l >>> 16) + (fl >>> 16) + (c1 >>> 16);
|
||||||
c3 = (h5h & 0xFFFF) + (fh & 0xFFFF) + (c2 >>> 16);
|
c3 = (h5h & 0xFFFF) + (fh & 0xFFFF) + (c2 >>> 16);
|
||||||
c4 = (h5h >>> 16) + (fh >>> 16) + (c3 >>> 16);
|
c4 = (h5h >>> 16) + (fh >>> 16) + (c3 >>> 16);
|
||||||
|
|
||||||
h5h = (c4 << 16) | (c3 & 0xFFFF);
|
this.h5h = (c4 << 16) | (c3 & 0xFFFF);
|
||||||
h5l = (c2 << 16) | (c1 & 0xFFFF);
|
this.h5l = (c2 << 16) | (c1 & 0xFFFF);
|
||||||
|
|
||||||
c1 = (h6l & 0xFFFF) + (gl & 0xFFFF);
|
c1 = (h6l & 0xFFFF) + (gl & 0xFFFF);
|
||||||
c2 = (h6l >>> 16) + (gl >>> 16) + (c1 >>> 16);
|
c2 = (h6l >>> 16) + (gl >>> 16) + (c1 >>> 16);
|
||||||
c3 = (h6h & 0xFFFF) + (gh & 0xFFFF) + (c2 >>> 16);
|
c3 = (h6h & 0xFFFF) + (gh & 0xFFFF) + (c2 >>> 16);
|
||||||
c4 = (h6h >>> 16) + (gh >>> 16) + (c3 >>> 16);
|
c4 = (h6h >>> 16) + (gh >>> 16) + (c3 >>> 16);
|
||||||
|
|
||||||
h6h = (c4 << 16) | (c3 & 0xFFFF);
|
this.h6h = (c4 << 16) | (c3 & 0xFFFF);
|
||||||
h6l = (c2 << 16) | (c1 & 0xFFFF);
|
this.h6l = (c2 << 16) | (c1 & 0xFFFF);
|
||||||
|
|
||||||
c1 = (h7l & 0xFFFF) + (hl & 0xFFFF);
|
c1 = (h7l & 0xFFFF) + (hl & 0xFFFF);
|
||||||
c2 = (h7l >>> 16) + (hl >>> 16) + (c1 >>> 16);
|
c2 = (h7l >>> 16) + (hl >>> 16) + (c1 >>> 16);
|
||||||
c3 = (h7h & 0xFFFF) + (hh & 0xFFFF) + (c2 >>> 16);
|
c3 = (h7h & 0xFFFF) + (hh & 0xFFFF) + (c2 >>> 16);
|
||||||
c4 = (h7h >>> 16) + (hh >>> 16) + (c3 >>> 16);
|
c4 = (h7h >>> 16) + (hh >>> 16) + (c3 >>> 16);
|
||||||
|
|
||||||
h7h = (c4 << 16) | (c3 & 0xFFFF);
|
this.h7h = (c4 << 16) | (c3 & 0xFFFF);
|
||||||
h7l = (c2 << 16) | (c1 & 0xFFFF);
|
this.h7l = (c2 << 16) | (c1 & 0xFFFF);
|
||||||
} while (!end);
|
};
|
||||||
|
|
||||||
|
Sha512.prototype.hex = function () {
|
||||||
|
this.finalize();
|
||||||
|
|
||||||
|
var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l,
|
||||||
|
h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l,
|
||||||
|
h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l,
|
||||||
|
h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l,
|
||||||
|
bits = this.bits;
|
||||||
|
|
||||||
var hex = HEX_CHARS[(h0h >> 28) & 0x0F] + HEX_CHARS[(h0h >> 24) & 0x0F] +
|
var hex = HEX_CHARS[(h0h >> 28) & 0x0F] + HEX_CHARS[(h0h >> 24) & 0x0F] +
|
||||||
HEX_CHARS[(h0h >> 20) & 0x0F] + HEX_CHARS[(h0h >> 16) & 0x0F] +
|
HEX_CHARS[(h0h >> 20) & 0x0F] + HEX_CHARS[(h0h >> 16) & 0x0F] +
|
||||||
@@ -569,19 +660,96 @@
|
|||||||
return hex;
|
return hex;
|
||||||
};
|
};
|
||||||
|
|
||||||
var exports = sha512;
|
Sha512.prototype.toString = Sha512.prototype.hex;
|
||||||
exports.sha512 = sha512;
|
|
||||||
exports.sha384 = sha384;
|
Sha512.prototype.digest = function () {
|
||||||
exports.sha512_256 = sha512_256;
|
this.finalize();
|
||||||
exports.sha512_224 = sha512_224;
|
|
||||||
|
var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l,
|
||||||
|
h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l,
|
||||||
|
h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l,
|
||||||
|
h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l,
|
||||||
|
bits = this.bits;
|
||||||
|
|
||||||
|
var arr = [
|
||||||
|
(h0h >> 24) & 0xFF, (h0h >> 16) & 0xFF, (h0h >> 8) & 0xFF, h0h & 0xFF,
|
||||||
|
(h0l >> 24) & 0xFF, (h0l >> 16) & 0xFF, (h0l >> 8) & 0xFF, h0l & 0xFF,
|
||||||
|
(h1h >> 24) & 0xFF, (h1h >> 16) & 0xFF, (h1h >> 8) & 0xFF, h1h & 0xFF,
|
||||||
|
(h1l >> 24) & 0xFF, (h1l >> 16) & 0xFF, (h1l >> 8) & 0xFF, h1l & 0xFF,
|
||||||
|
(h2h >> 24) & 0xFF, (h2h >> 16) & 0xFF, (h2h >> 8) & 0xFF, h2h & 0xFF,
|
||||||
|
(h2l >> 24) & 0xFF, (h2l >> 16) & 0xFF, (h2l >> 8) & 0xFF, h2l & 0xFF,
|
||||||
|
(h3h >> 24) & 0xFF, (h3h >> 16) & 0xFF, (h3h >> 8) & 0xFF, h3h & 0xFF
|
||||||
|
];
|
||||||
|
|
||||||
|
if (bits >= 256) {
|
||||||
|
arr.push((h3l >> 24) & 0xFF, (h3l >> 16) & 0xFF, (h3l >> 8) & 0xFF, h3l & 0xFF);
|
||||||
|
}
|
||||||
|
if (bits >= 384) {
|
||||||
|
arr.push(
|
||||||
|
(h4h >> 24) & 0xFF, (h4h >> 16) & 0xFF, (h4h >> 8) & 0xFF, h4h & 0xFF,
|
||||||
|
(h4l >> 24) & 0xFF, (h4l >> 16) & 0xFF, (h4l >> 8) & 0xFF, h4l & 0xFF,
|
||||||
|
(h5h >> 24) & 0xFF, (h5h >> 16) & 0xFF, (h5h >> 8) & 0xFF, h5h & 0xFF,
|
||||||
|
(h5l >> 24) & 0xFF, (h5l >> 16) & 0xFF, (h5l >> 8) & 0xFF, h5l & 0xFF
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (bits == 512) {
|
||||||
|
arr.push(
|
||||||
|
(h6h >> 24) & 0xFF, (h6h >> 16) & 0xFF, (h6h >> 8) & 0xFF, h6h & 0xFF,
|
||||||
|
(h6l >> 24) & 0xFF, (h6l >> 16) & 0xFF, (h6l >> 8) & 0xFF, h6l & 0xFF,
|
||||||
|
(h7h >> 24) & 0xFF, (h7h >> 16) & 0xFF, (h7h >> 8) & 0xFF, h7h & 0xFF,
|
||||||
|
(h7l >> 24) & 0xFF, (h7l >> 16) & 0xFF, (h7l >> 8) & 0xFF, h7l & 0xFF
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
};
|
||||||
|
|
||||||
|
Sha512.prototype.array = Sha512.prototype.digest;
|
||||||
|
|
||||||
|
Sha512.prototype.arrayBuffer = function () {
|
||||||
|
this.finalize();
|
||||||
|
|
||||||
|
var bits = this.bits;
|
||||||
|
var buffer = new ArrayBuffer(bits / 8);
|
||||||
|
var dataView = new DataView(buffer);
|
||||||
|
dataView.setUint32(0, this.h0h);
|
||||||
|
dataView.setUint32(4, this.h0l);
|
||||||
|
dataView.setUint32(8, this.h1h);
|
||||||
|
dataView.setUint32(12, this.h1l);
|
||||||
|
dataView.setUint32(16, this.h2h);
|
||||||
|
dataView.setUint32(20, this.h2l);
|
||||||
|
dataView.setUint32(24, this.h3h);
|
||||||
|
|
||||||
|
if (bits >= 256) {
|
||||||
|
dataView.setUint32(28, this.h3l);
|
||||||
|
}
|
||||||
|
if (bits >= 384) {
|
||||||
|
dataView.setUint32(32, this.h4h);
|
||||||
|
dataView.setUint32(36, this.h4l);
|
||||||
|
dataView.setUint32(40, this.h5h);
|
||||||
|
dataView.setUint32(44, this.h5l);
|
||||||
|
}
|
||||||
|
if (bits == 512) {
|
||||||
|
dataView.setUint32(48, this.h6h);
|
||||||
|
dataView.setUint32(52, this.h6l);
|
||||||
|
dataView.setUint32(56, this.h7h);
|
||||||
|
dataView.setUint32(60, this.h7l);
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
var exports = createMethod(512);
|
||||||
|
exports.sha512 = exports;
|
||||||
|
exports.sha384 = createMethod(384);
|
||||||
|
exports.sha512_256 = createMethod(256);
|
||||||
|
exports.sha512_224 = createMethod(224);
|
||||||
|
|
||||||
if (COMMON_JS) {
|
if (COMMON_JS) {
|
||||||
module.exports = exports;
|
module.exports = exports;
|
||||||
} else {
|
} else {
|
||||||
root.sha512 = sha512;
|
root.sha512 = exports.sha512;
|
||||||
root.sha384 = sha384;
|
root.sha384 = exports.sha384;
|
||||||
root.sha512_256 = sha512_256;
|
root.sha512_256 = exports.sha512_256;
|
||||||
root.sha512_224 = sha512_224;
|
root.sha512_224 = exports.sha512_224;
|
||||||
if (AMD) {
|
if (AMD) {
|
||||||
define(function () {
|
define(function () {
|
||||||
return exports;
|
return exports;
|
||||||
|
|||||||
+299
-168
@@ -1,177 +1,308 @@
|
|||||||
(function (sha512, sha384, sha512_256, sha512_224) {
|
(function (sha512, sha384, sha512_256, sha512_224) {
|
||||||
describe('sha512', function () {
|
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
|
||||||
describe('ascii', function () {
|
var array = new Uint8Array(this);
|
||||||
describe('less than 128 bytes', function () {
|
var hex = '';
|
||||||
it('should be successful', function () {
|
for (var i = 0; i < array.length; ++i) {
|
||||||
expect(sha512('')).to.be('cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e');
|
var c = array[i].toString('16');
|
||||||
expect(sha512('The quick brown fox jumps over the lazy dog')).to.be('07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6');
|
hex += c.length === 1 ? '0' + c : c;
|
||||||
expect(sha512('The quick brown fox jumps over the lazy dog.')).to.be('91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed');
|
}
|
||||||
|
return hex;
|
||||||
|
};
|
||||||
|
|
||||||
|
var testCases = {
|
||||||
|
sha512: {
|
||||||
|
'ascii': {
|
||||||
|
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': '',
|
||||||
|
'07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': 'The quick brown fox jumps over the lazy dog',
|
||||||
|
'91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed': 'The quick brown fox jumps over the lazy dog.'
|
||||||
|
},
|
||||||
|
'ascii more than 64 bytes': {
|
||||||
|
'a8dedff31e3be9df6413ef5b4ecb93d62d3fbcb04297552eab5370e04afd45927854a4373037e81a50186e678d818c9ba824f4c850f3d0f02764af0252076979': 'The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.'
|
||||||
|
},
|
||||||
|
'UTF8': {
|
||||||
|
'8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a2755fbd05d8d8491cb2946febd5b0f124ffdfbaecf7e34946353c4f1b5ab29545895468': '中文',
|
||||||
|
'e1c6925243db76985abacaf9fa85e22697f549e67f65a36c88e4046a2260990ff9eefc3402396ea8dcbe8c592d8d5671bea612156eda38d3708d394bbd17d493': 'aécio',
|
||||||
|
'f3e7ee9cdf7dbb52f7edd59ce3d49868c64f2b3aceceab060b8eaaebdf9de0dae5866d660e3319c5aad426a2176cb1703efc73eb24d1a90458ceda1b7f4e3940': '𠜎'
|
||||||
|
},
|
||||||
|
'UTF8 more than 64 bytes': {
|
||||||
|
'6cb7f6d3381a187edadb43c7cdcfbbed4d2c213a7dce8ea08fe42b9882b64e643202b4974a6db94f94650ab9173d97c58bd59f6d19d27e01aab76d8d08855c65': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一',
|
||||||
|
'd24af1901aaf1458f089a6eddf784ce61c3012aee0df98bdb67ad2dc6b41a3b4051d40caac524373930ae396a2dde99a9204871b40892eea3e5f3c8d46da0c3c': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。'
|
||||||
|
},
|
||||||
|
'special length': {
|
||||||
|
'a58b6132677883b0ab565dfb4284a4441a35a0954738d90ad8c17800de5ee44f6482efd4c13e05a6e907fb830fc9d9039bd96f004e5e3e8d00802fb9448dec03': '012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345',
|
||||||
|
'34a93615cbf314a799857dc9c1804ed04be60b481229ea3a53e00316e62ac7924ea7e65435cbd9fc7d8e10e0e52e56bd99ac571c1c470cbf9252bdd70b3fd8a3': '0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456',
|
||||||
|
'4555ce42c2e19f9a09a34b3e40f85178c22cde939ac42de4d33ca0e08e3c6a2e531a3abd9265a72cc22a19d085eb2c468c20d6cfb022d8914b53d6a2b485b7c9': '123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567',
|
||||||
|
'8bfa769385fe4b7d4aabf304498522d5aefa5356e42e9ae5ac9fa6b00a483685586cc0fa44da3df335719cbb524b12433afda18361d70e4c584ea81a927c670c': '1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678'
|
||||||
|
},
|
||||||
|
'Array': {
|
||||||
|
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': [],
|
||||||
|
'07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': [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]
|
||||||
|
},
|
||||||
|
'Uint8Array': {
|
||||||
|
'07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': 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])
|
||||||
|
},
|
||||||
|
'Int8Array': {
|
||||||
|
'07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': new Int8Array([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])
|
||||||
|
},
|
||||||
|
'ArrayBuffer': {
|
||||||
|
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': new ArrayBuffer(0),
|
||||||
|
'b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee': new ArrayBuffer(1),
|
||||||
|
},
|
||||||
|
'Object': {
|
||||||
|
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': {what: 'ever'}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sha384: {
|
||||||
|
'ascii': {
|
||||||
|
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': '',
|
||||||
|
'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': 'The quick brown fox jumps over the lazy dog',
|
||||||
|
'ed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7': 'The quick brown fox jumps over the lazy dog.'
|
||||||
|
},
|
||||||
|
'ascii more than 64 bytes': {
|
||||||
|
'3ab853dee5785c19346e8578d9cdb3b7258a8212c15fdf25d3055b4fbbc892a529e552788992fdae68dfa34f13f0af4e': 'The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.'
|
||||||
|
},
|
||||||
|
'UTF8': {
|
||||||
|
'93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c': '中文',
|
||||||
|
'a2146805faafc45b0055b49386768811c803ef9fa8a85b648e114276c1bf49ef1092ec1bc2d3f7e036238a97eace2087': 'aécio',
|
||||||
|
'e929475cf9b4d73e2a2366146381ac779b17499c92ddf910e028eb9f30280878a2843643ed8a539af5dffed64143b93d': '𠜎'
|
||||||
|
},
|
||||||
|
'UTF8 more than 64 bytes': {
|
||||||
|
'143f4bb1a89e576ea05bd8433a3903352c199bf6ef35bfa30afa1505d6fcef77476d1b1824105da160a5164b7c792328': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一',
|
||||||
|
'432a8d25efb1a8d463acc7bbbed57365cddc72de3cc19d42e1d260b1479770ecea9dd403fead2949d4fabb36939f263a': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。'
|
||||||
|
},
|
||||||
|
'special length': {
|
||||||
|
'a0ecc55799e1db4e7b30c2e78d445ada5ea2939d47e8aab51d6ae86cdcf93d5048b2666aa25fbaede7ec59ee59f46e88': '012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345',
|
||||||
|
'484b51b9f03f453a08c823afea1a32434b6545fb682b0b91d94e1f4bf2812abc8a31387050a2e74909f862436b88c798': '0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456',
|
||||||
|
'e4c83d6e5e18b4391a0b2e5fab84234ce9fc1071d87a9dcf38ca050ca3635781ef1d65ad4f9a835df26d186384105eac': '123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567',
|
||||||
|
'd7f6874057808f9e2eaa4eddace032c7bd548fbe3989be6591910277a25dee5972e1297deced3ad7b4e3040de88855f6': '1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678'
|
||||||
|
},
|
||||||
|
'Array': {
|
||||||
|
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': [],
|
||||||
|
'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': [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]
|
||||||
|
},
|
||||||
|
'Uint8Array': {
|
||||||
|
'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': 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])
|
||||||
|
},
|
||||||
|
'Int8Array': {
|
||||||
|
'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': new Int8Array([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])
|
||||||
|
},
|
||||||
|
'ArrayBuffer': {
|
||||||
|
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': new ArrayBuffer(0),
|
||||||
|
'bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933ec2b413465966817a9c208a11717': new ArrayBuffer(1),
|
||||||
|
},
|
||||||
|
'Object': {
|
||||||
|
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': {what: 'ever'}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sha512_256: {
|
||||||
|
'ascii': {
|
||||||
|
'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': '',
|
||||||
|
'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': 'The quick brown fox jumps over the lazy dog',
|
||||||
|
'1546741840f8a492b959d9b8b2344b9b0eb51b004bba35c0aebaac86d45264c3': 'The quick brown fox jumps over the lazy dog.'
|
||||||
|
},
|
||||||
|
'ascii more than 64 bytes': {
|
||||||
|
'21e2e940930b23f1de6377086d07e22033c6bbf3fd9fbf4b62ec66e6c08c25be': 'The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.'
|
||||||
|
},
|
||||||
|
'UTF8': {
|
||||||
|
'b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72': '中文',
|
||||||
|
'122802ca08e39c2ef46f6a81379dc5683bd8aa074dfb54259f0add4d8b5504bc': 'aécio',
|
||||||
|
'1032308151c0f4f5f8d4e0d96956352eb8ff87da98df8878d8795a858a7e7c08': '𠜎'
|
||||||
|
},
|
||||||
|
'UTF8 more than 64 bytes': {
|
||||||
|
'd32a41d9858e45b68402f77cf9f3c3f992c36a4bffd230f78d666c87f97eaf7e': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一',
|
||||||
|
'bd1abad59e6b8ad69bc17b6e05aa13f0cb725467fbeb45b83d3e4094332d1367': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。'
|
||||||
|
},
|
||||||
|
'special length': {
|
||||||
|
'b8bd1d6cae9992f8619904683d54cbed560ec3ef2a33d8bc225175ec27dc09a4': '012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345',
|
||||||
|
'4edb8bb93b959f482ce2e434585f3e164f53b00c42c4c46797445b39d225cfe3': '0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456',
|
||||||
|
'44da7ca023996ec4b4ded88410e4acc209ca26c34dc0f26550d28503974fe2d1': '123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567',
|
||||||
|
'465859c0edc706a2a9c39d3175a715fdf6b764ccc43d45b5668c56f6d8aa9b9e': '1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678'
|
||||||
|
},
|
||||||
|
'Array': {
|
||||||
|
'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': [],
|
||||||
|
'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': [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]
|
||||||
|
},
|
||||||
|
'Uint8Array': {
|
||||||
|
'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': 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])
|
||||||
|
},
|
||||||
|
'Int8Array': {
|
||||||
|
'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': new Int8Array([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])
|
||||||
|
},
|
||||||
|
'ArrayBuffer': {
|
||||||
|
'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': new ArrayBuffer(0),
|
||||||
|
'10baad1713566ac2333467bddb0597dec9066120dd72ac2dcb8394221dcbe43d': new ArrayBuffer(1),
|
||||||
|
},
|
||||||
|
'Object': {
|
||||||
|
'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': {what: 'ever'}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sha512_224: {
|
||||||
|
'ascii': {
|
||||||
|
'6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': '',
|
||||||
|
'944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': 'The quick brown fox jumps over the lazy dog',
|
||||||
|
'6d6a9279495ec4061769752e7ff9c68b6b0b3c5a281b7917ce0572de': 'The quick brown fox jumps over the lazy dog.'
|
||||||
|
},
|
||||||
|
'ascii more than 64 bytes': {
|
||||||
|
'2e962464977b198ee758d615bbc92251ad2e3c0960068e279fd21d2f': 'The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.'
|
||||||
|
},
|
||||||
|
'UTF8': {
|
||||||
|
'0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed188': '中文',
|
||||||
|
'562f2e4ee7f7451d20dcc6a0ac1a1e1c4a75f09baaf1cf19af3e15f4': 'aécio',
|
||||||
|
'0533318c52b3d4ad355c2a6c7e727ae3d2efa749db480ac33560b059': '𠜎'
|
||||||
|
},
|
||||||
|
'UTF8 more than 64 bytes': {
|
||||||
|
'f67e191a5d4ee67a272ccaf6cf597f0c4d6a0c46bd631be7cadb0944': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一',
|
||||||
|
'009c3d1e3172d6df71344982eada855421592aea28acbf660ada7569': '訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。'
|
||||||
|
},
|
||||||
|
'special length': {
|
||||||
|
'36d6398ca22d885432e2fe3af53b9f83b2dc7a8e9284d65b81f7a879': '012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345',
|
||||||
|
'd930407a742d10f70747f05271181ad6c1c92f87482ce6a494cb566a': '0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456',
|
||||||
|
'1d60954ce7bee0bf5d235fe6bfc928c0f32c0f1c4992451dbc0f4dbf': '123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567',
|
||||||
|
'672aef84d579799cedf2fec090ce4ea0d72e0edd2788deaa8200fd67': '1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678'
|
||||||
|
},
|
||||||
|
'Array': {
|
||||||
|
'6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': [],
|
||||||
|
'944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': [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]
|
||||||
|
},
|
||||||
|
'Uint8Array': {
|
||||||
|
'944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': 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])
|
||||||
|
},
|
||||||
|
'Int8Array': {
|
||||||
|
'944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': new Int8Array([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])
|
||||||
|
},
|
||||||
|
'ArrayBuffer': {
|
||||||
|
'6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': new ArrayBuffer(0),
|
||||||
|
'283bb59af7081ed08197227d8f65b9591ffe1155be43e9550e57f941': new ArrayBuffer(1),
|
||||||
|
},
|
||||||
|
'Object': {
|
||||||
|
'6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': {what: 'ever'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function runTestCases(name, algorithm) {
|
||||||
|
var methods = [
|
||||||
|
{
|
||||||
|
name: name,
|
||||||
|
call: algorithm,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: name + '.hex',
|
||||||
|
call: algorithm.hex
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: name + '.array',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.array(message).toHexString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: name + '.digest',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.digest(message).toHexString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: name + '.arrayBuffer',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.arrayBuffer(message).toHexString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var classMethods = [
|
||||||
|
{
|
||||||
|
name: 'create',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.create().update(message).toString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'update',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.update(message).toString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'hex',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.update(message).hex();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'array',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.update(message).array().toHexString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'digest',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.update(message).digest().toHexString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'arrayBuffer',
|
||||||
|
call: function (message) {
|
||||||
|
return algorithm.update(message).arrayBuffer().toHexString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'finalize',
|
||||||
|
call: function (message) {
|
||||||
|
var hash = algorithm.update(message);
|
||||||
|
hash.hex();
|
||||||
|
hash.update(message);
|
||||||
|
return hash.hex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var subTestCases = testCases[name];
|
||||||
|
|
||||||
|
describe(name, function () {
|
||||||
|
methods.forEach(function (method) {
|
||||||
|
describe('#' + method.name, function () {
|
||||||
|
for (var testCaseName in subTestCases) {
|
||||||
|
(function (testCaseName) {
|
||||||
|
var testCase = subTestCases[testCaseName];
|
||||||
|
context('when ' + testCaseName, function () {
|
||||||
|
for (var hash in testCase) {
|
||||||
|
(function (message, hash) {
|
||||||
|
it('should be equal', function () {
|
||||||
|
expect(method.call(message)).to.be(hash);
|
||||||
|
});
|
||||||
|
})(testCase[hash], hash);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(testCaseName);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('more than 128 bytes', function () {
|
classMethods.forEach(function (method) {
|
||||||
it('should be successful', function () {
|
describe('#' + method.name, function () {
|
||||||
expect(sha512('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('a8dedff31e3be9df6413ef5b4ecb93d62d3fbcb04297552eab5370e04afd45927854a4373037e81a50186e678d818c9ba824f4c850f3d0f02764af0252076979');
|
for (var testCaseName in subTestCases) {
|
||||||
|
(function (testCaseName) {
|
||||||
|
var testCase = subTestCases[testCaseName];
|
||||||
|
context('when ' + testCaseName, function () {
|
||||||
|
for (var hash in testCase) {
|
||||||
|
(function (message, hash) {
|
||||||
|
it('should be equal', function () {
|
||||||
|
expect(method.call(message)).to.be(hash);
|
||||||
|
});
|
||||||
|
})(testCase[hash], hash);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(testCaseName);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe('UTF8', function () {
|
runTestCases('sha512', sha512);
|
||||||
describe('less than 128 bytes', function () {
|
runTestCases('sha384', sha384);
|
||||||
it('should be successful', function () {
|
runTestCases('sha512_256', sha512_256);
|
||||||
expect(sha512('中文')).to.be('8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a2755fbd05d8d8491cb2946febd5b0f124ffdfbaecf7e34946353c4f1b5ab29545895468');
|
runTestCases('sha512_224', sha512_224);
|
||||||
expect(sha512('aécio')).to.be('e1c6925243db76985abacaf9fa85e22697f549e67f65a36c88e4046a2260990ff9eefc3402396ea8dcbe8c592d8d5671bea612156eda38d3708d394bbd17d493');
|
|
||||||
expect(sha512('𠜎')).to.be('f3e7ee9cdf7dbb52f7edd59ce3d49868c64f2b3aceceab060b8eaaebdf9de0dae5866d660e3319c5aad426a2176cb1703efc73eb24d1a90458ceda1b7f4e3940');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('more than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('6cb7f6d3381a187edadb43c7cdcfbbed4d2c213a7dce8ea08fe42b9882b64e643202b4974a6db94f94650ab9173d97c58bd59f6d19d27e01aab76d8d08855c65');
|
|
||||||
expect(sha512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('d24af1901aaf1458f089a6eddf784ce61c3012aee0df98bdb67ad2dc6b41a3b4051d40caac524373930ae396a2dde99a9204871b40892eea3e5f3c8d46da0c3c');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('special length', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512('012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345')).to.be('a58b6132677883b0ab565dfb4284a4441a35a0954738d90ad8c17800de5ee44f6482efd4c13e05a6e907fb830fc9d9039bd96f004e5e3e8d00802fb9448dec03');
|
|
||||||
expect(sha512('0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456')).to.be('34a93615cbf314a799857dc9c1804ed04be60b481229ea3a53e00316e62ac7924ea7e65435cbd9fc7d8e10e0e52e56bd99ac571c1c470cbf9252bdd70b3fd8a3');
|
|
||||||
expect(sha512('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('4555ce42c2e19f9a09a34b3e40f85178c22cde939ac42de4d33ca0e08e3c6a2e531a3abd9265a72cc22a19d085eb2c468c20d6cfb022d8914b53d6a2b485b7c9');
|
|
||||||
expect(sha512('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('8bfa769385fe4b7d4aabf304498522d5aefa5356e42e9ae5ac9fa6b00a483685586cc0fa44da3df335719cbb524b12433afda18361d70e4c584ea81a927c670c');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('sha384', function () {
|
|
||||||
describe('ascii', function () {
|
|
||||||
describe('less than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha384('')).to.be('38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b');
|
|
||||||
expect(sha384('The quick brown fox jumps over the lazy dog')).to.be('ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1');
|
|
||||||
expect(sha384('The quick brown fox jumps over the lazy dog.')).to.be('ed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('more than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha384('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('3ab853dee5785c19346e8578d9cdb3b7258a8212c15fdf25d3055b4fbbc892a529e552788992fdae68dfa34f13f0af4e');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('UTF8', function () {
|
|
||||||
describe('less than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha384('中文')).to.be('93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c');
|
|
||||||
expect(sha384('aécio')).to.be('a2146805faafc45b0055b49386768811c803ef9fa8a85b648e114276c1bf49ef1092ec1bc2d3f7e036238a97eace2087');
|
|
||||||
expect(sha384('𠜎')).to.be('e929475cf9b4d73e2a2366146381ac779b17499c92ddf910e028eb9f30280878a2843643ed8a539af5dffed64143b93d');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('more than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('143f4bb1a89e576ea05bd8433a3903352c199bf6ef35bfa30afa1505d6fcef77476d1b1824105da160a5164b7c792328');
|
|
||||||
expect(sha384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('432a8d25efb1a8d463acc7bbbed57365cddc72de3cc19d42e1d260b1479770ecea9dd403fead2949d4fabb36939f263a');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('special length', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha384('012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345')).to.be('a0ecc55799e1db4e7b30c2e78d445ada5ea2939d47e8aab51d6ae86cdcf93d5048b2666aa25fbaede7ec59ee59f46e88');
|
|
||||||
expect(sha384('0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456')).to.be('484b51b9f03f453a08c823afea1a32434b6545fb682b0b91d94e1f4bf2812abc8a31387050a2e74909f862436b88c798');
|
|
||||||
expect(sha384('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('e4c83d6e5e18b4391a0b2e5fab84234ce9fc1071d87a9dcf38ca050ca3635781ef1d65ad4f9a835df26d186384105eac');
|
|
||||||
expect(sha384('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('d7f6874057808f9e2eaa4eddace032c7bd548fbe3989be6591910277a25dee5972e1297deced3ad7b4e3040de88855f6');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('sha512/256', function () {
|
|
||||||
describe('ascii', function () {
|
|
||||||
describe('less than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_256('')).to.be('c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a');
|
|
||||||
expect(sha512_256('The quick brown fox jumps over the lazy dog')).to.be('dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d');
|
|
||||||
expect(sha512_256('The quick brown fox jumps over the lazy dog.')).to.be('1546741840f8a492b959d9b8b2344b9b0eb51b004bba35c0aebaac86d45264c3');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('more than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_256('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('21e2e940930b23f1de6377086d07e22033c6bbf3fd9fbf4b62ec66e6c08c25be');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('UTF8', function () {
|
|
||||||
describe('less than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_256('中文')).to.be('b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72');
|
|
||||||
expect(sha512_256('aécio')).to.be('122802ca08e39c2ef46f6a81379dc5683bd8aa074dfb54259f0add4d8b5504bc');
|
|
||||||
expect(sha512_256('𠜎')).to.be('1032308151c0f4f5f8d4e0d96956352eb8ff87da98df8878d8795a858a7e7c08');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('more than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('d32a41d9858e45b68402f77cf9f3c3f992c36a4bffd230f78d666c87f97eaf7e');
|
|
||||||
expect(sha512_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('bd1abad59e6b8ad69bc17b6e05aa13f0cb725467fbeb45b83d3e4094332d1367');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('special length', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_256('012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345')).to.be('b8bd1d6cae9992f8619904683d54cbed560ec3ef2a33d8bc225175ec27dc09a4');
|
|
||||||
expect(sha512_256('0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456')).to.be('4edb8bb93b959f482ce2e434585f3e164f53b00c42c4c46797445b39d225cfe3');
|
|
||||||
expect(sha512_256('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('44da7ca023996ec4b4ded88410e4acc209ca26c34dc0f26550d28503974fe2d1');
|
|
||||||
expect(sha512_256('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('465859c0edc706a2a9c39d3175a715fdf6b764ccc43d45b5668c56f6d8aa9b9e');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('sha512/224', function () {
|
|
||||||
describe('ascii', function () {
|
|
||||||
describe('less than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_224('')).to.be('6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4');
|
|
||||||
expect(sha512_224('The quick brown fox jumps over the lazy dog')).to.be('944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37');
|
|
||||||
expect(sha512_224('The quick brown fox jumps over the lazy dog.')).to.be('6d6a9279495ec4061769752e7ff9c68b6b0b3c5a281b7917ce0572de');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('more than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_224('The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.')).to.be('2e962464977b198ee758d615bbc92251ad2e3c0960068e279fd21d2f');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('UTF8', function () {
|
|
||||||
describe('less than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_224('中文')).to.be('0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed188');
|
|
||||||
expect(sha512_224('aécio')).to.be('562f2e4ee7f7451d20dcc6a0ac1a1e1c4a75f09baaf1cf19af3e15f4');
|
|
||||||
expect(sha512_224('𠜎')).to.be('0533318c52b3d4ad355c2a6c7e727ae3d2efa749db480ac33560b059');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('more than 128 bytes', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('f67e191a5d4ee67a272ccaf6cf597f0c4d6a0c46bd631be7cadb0944');
|
|
||||||
expect(sha512_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('009c3d1e3172d6df71344982eada855421592aea28acbf660ada7569');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('special length', function () {
|
|
||||||
it('should be successful', function () {
|
|
||||||
expect(sha512_224('012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345')).to.be('36d6398ca22d885432e2fe3af53b9f83b2dc7a8e9284d65b81f7a879');
|
|
||||||
expect(sha512_224('0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456')).to.be('d930407a742d10f70747f05271181ad6c1c92f87482ce6a494cb566a');
|
|
||||||
expect(sha512_224('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('1d60954ce7bee0bf5d235fe6bfc928c0f32c0f1c4992451dbc0f4dbf');
|
|
||||||
expect(sha512_224('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('672aef84d579799cedf2fec090ce4ea0d72e0edd2788deaa8200fd67');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})(sha512, sha384, sha512_256, sha512_224);
|
})(sha512, sha384, sha512_256, sha512_224);
|
||||||
|
|||||||
Reference in New Issue
Block a user