Compare commits

..

No commits in common. 'master' and 'v0.2.2' have entirely different histories.

@ -0,0 +1 @@
/tests/

4
.gitignore vendored

@ -1,3 +1 @@
/node_modules/ node_modules/
/coverage/
/.nyc_output/

@ -1,7 +0,0 @@
/node_modules/
/coverage/
/.nyc_output/
/tests/
.travis.yml
.npmignore
bower.json

@ -1,10 +1,13 @@
language: node_js language: node_js
node_js: node_js:
- "6.11.4" - "0.11"
- "8.6.0" - "0.10"
- "0.8"
before_install: before_install:
- npm install coveralls - npm install mocha -g
after_success: npm run coveralls - npm install coveralls -g
- npm install mocha-lcov-reporter -g
script: npm run-script coveralls
branches: branches:
only: only:
- master - master

@ -1,96 +1,34 @@
# Change Log # v0.2.2 / 2015-02-09
## v0.9.0 / 2024-01-24 * Improve performance.
### Fixed
- dependencies and security issues.
- don't modify global Array and ArrayBuffer prototypes.
- refactor: simplify formatMessage internal logic.
- Generates incorrect hash in some cases.
### Changed # v0.2.1 / 2015-02-08
- use unsigned right shift.
## v0.8.0 / 2018-08-05 * Remove ascii parameter.
### Added * Improve performance.
- TypeScript definitions. * Add test cases.
- clone method.
### Changed # v0.2.0 / 2015-02-02
- throw error if update after finalize
## v0.7.1 / 2017-12-21 * Add test cases.
### Fixed * Improve performance.
- incorrect result when first bit is 1 of bytes.
## v0.7.0 / 2017-11-19 # v0.1.3 / 2015-01-26
### Added
- support HMAC. #8
## v0.6.0 / 2017-10-31 * Add test cases.
### Fixed * Improve performance.
- incorrect result when file size >= 512M.
## v0.5.0 / 2017-10-07 # v0.1.2 / 2015-01-07
### Added
- support for web worker. #5
### Changed * Add bower package.
- throw error if input type is incorrect. * Fixed JSHint warnings.
* Add travis.
* Add coveralls.
## v0.4.0 / 2017-07-08 # v0.1.1 / 2014-07-27
### Added
- Streaming support(update).
- support for ArrayBuffer input/output.
- support for byte array input/output.
## v0.3.0 / 2017-01-23 Fixed accents bug
### Added
- AMD support.
### Fixed # v0.1.0 / 2014-01-05
- ArrayBuffer dosen't work in Webpack.
## v0.2.2 / 2015-02-09 Initial release
### Improved
- performance.
## v0.2.1 / 2015-02-08
### Added
- test cases.
### Removed
- ascii parameter.
### Improved
- performance.
## v0.2.0 / 2015-02-02
### Added
- test cases.
### Improved
- performance.
## v0.1.3 / 2015-01-26
### Added
- test cases.
### Improved
- performance.
## v0.1.2 / 2015-01-07
### Added
- bower package.
- travis.
- coveralls.
### Fixed
- JSHint warnings.
## v0.1.1 / 2014-07-27
### Fixed
- accents bug.
## v0.1.0 / 2014-01-05
### Added
- initial release.

@ -1,4 +1,4 @@
Copyright 2014-2024 Chen, Yi-Cyuan Copyright 2014-2015 emn178@gmail.com
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the

@ -1,13 +1,9 @@
# js-sha512 # js-sha512
[![Build Status](https://travis-ci.org/emn178/js-sha512.svg?branch=master)](https://travis-ci.org/emn178/js-sha512) [![Build Status](https://travis-ci.org/emn178/js-sha512.svg?branch=master)](https://travis-ci.org/emn178/js-sha512)
[![Coverage Status](https://coveralls.io/repos/emn178/js-sha512/badge.svg?branch=master)](https://coveralls.io/r/emn178/js-sha512?branch=master) [![Coverage Status](https://coveralls.io/repos/emn178/js-sha512/badge.svg?branch=master)](https://coveralls.io/r/emn178/js-sha512?branch=master)
[![CDNJS](https://img.shields.io/cdnjs/v/js-sha512.svg)](https://cdnjs.com/libraries/js-sha512/)
[![NPM](https://nodei.co/npm/js-sha512.png?stars&downloads)](https://nodei.co/npm/js-sha512/) [![NPM](https://nodei.co/npm/js-sha512.png?stars&downloads)](https://nodei.co/npm/js-sha512/)
A simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding. A simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.
## Notice
* v0.8.0+ will throw an error if try to update hash after finalize.
## Demo ## Demo
[SHA512 Online](http://emn178.github.io/online-tools/sha512.html) [SHA512 Online](http://emn178.github.io/online-tools/sha512.html)
[SHA384 Online](http://emn178.github.io/online-tools/sha384.html) [SHA384 Online](http://emn178.github.io/online-tools/sha384.html)
@ -28,113 +24,121 @@ For node.js, you can use this command to install:
npm install js-sha512 npm install js-sha512
## Usage ## Usage
### Node.js You could use like this:
```JavaScript
sha512('Message to hash');
sha384('Message to hash');
sha512_256('Message to hash');
sha512_224('Message to hash');
```
If you use node.js, you should require the module first: If you use node.js, you should require the module first:
```JavaScript ```JavaScript
const { sha512, sha384, sha512_256, sha512_224 } = require('js-sha512'); sha512 = require('js-sha512');
``` ```
or
### TypeScript ```JavaScript
If you use TypeScript, you can import like this: sha512 = require('js-sha512').sha512;
```TypeScript sha384 = require('js-sha512').sha384;
import { sha512, sha384, sha512_256, sha512_224 } from 'js-sha512'; sha512_256 = require('js-sha512').sha512_256;
sha512_224 = require('js-sha512').sha512_224;
``` ```
## Example
### RequireJS Code
It supports AMD:
```JavaScript ```JavaScript
require(['your/path/sha512.js'], function(jsSha512) { sha512('');
const { sha512, sha384, sha512_256, sha512_224 } = jsSha512; sha512('The quick brown fox jumps over the lazy dog');
}); sha512('The quick brown fox jumps over the lazy dog.');
sha384('');
sha384('The quick brown fox jumps over the lazy dog');
sha384('The quick brown fox jumps over the lazy dog.');
sha512_256('');
sha512_256('The quick brown fox jumps over the lazy dog');
sha512_256('The quick brown fox jumps over the lazy dog.');
sha512_224('');
sha512_224('The quick brown fox jumps over the lazy dog');
sha512_224('The quick brown fox jumps over the lazy dog.');
``` ```
Output
### Classic Browser
If you use browser script directly, functions will be global: cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6
91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed
38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1
ed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7
c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a
dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d
1546741840f8a492b959d9b8b2344b9b0eb51b004bba35c0aebaac86d45264c3
6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4
944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37
6d6a9279495ec4061769752e7ff9c68b6b0b3c5a281b7917ce0572de
It also supports UTF-8 encoding:
Code
```JavaScript ```JavaScript
sha512('Message to hash'); sha512('中文');
sha384('Message to hash'); sha384('中文');
sha512_256('Message to hash'); sha512_256('中文');
sha512_224('Message to hash'); sha512_224('中文');
``` ```
Output
## Example 8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a2755fbd05d8d8491cb2946febd5b0f124ffdfbaecf7e34946353c4f1b5ab29545895468
You could use like this: 93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c
```JavaScript b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72
sha512('Message to hash'); 0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed188
sha384('Message to hash');
sha512_256('Message to hash'); ## Benchmark
sha512_224('Message to hash'); [UTF8](http://jsperf.com/sha-512/10)
[ASCII](http://jsperf.com/sha-512/9)
// Support ArrayBuffer output ## Extensions
var arrayBuffer = sha512.arrayBuffer('Message to hash'); ### jQuery
If you prefer jQuery style, you can add following code to add a jQuery extension.
// Support Array output
var bytes = sha512.digest('Message to hash'); Code
var bytes = sha512.array('Message to hash'); ```JavaScript
jQuery.sha512 = sha512
// update hash jQuery.sha384 = sha384
var hash = sha512.update('Message to hash'); jQuery.sha512_256 = sha512_256
hash.update('Message2 to hash'); jQuery.sha512_224 = sha512_224
hash.hex(); ```
And then you could use like this:
// or to use create ```JavaScript
var hash = sha512.create(); $.sha512('message');
hash.update('Message to hash'); $.sha384('message');
hash.hex(); $.sha512_256('message');
$.sha512_224('message');
// clone
var hash = sha512.update('Message to hash');
var hash2 = hash.clone();
hash2.hex();
hash.update('Message2 to hash');
hash.hex();
// HMAC
sha512.hmac('key', 'Message to hash');
sha384.hmac('key', 'Message to hash');
var hash = sha512.hmac.create('key');
hash.update('Message to hash');
hash.hex();
var hash2 = sha512.hmac.update('key', 'Message to hash');
hash2.update('Message2 to hash');
hash2.array();
sha512(''); // cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
sha512('The quick brown fox jumps over the lazy dog'); // 07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6
sha512('The quick brown fox jumps over the lazy dog.'); // 91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed
sha384(''); // 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
sha384('The quick brown fox jumps over the lazy dog'); // ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1
sha384('The quick brown fox jumps over the lazy dog.'); // ed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7
sha512_256(''); // c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a
sha512_256('The quick brown fox jumps over the lazy dog'); // dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d
sha512_256('The quick brown fox jumps over the lazy dog.'); // 1546741840f8a492b959d9b8b2344b9b0eb51b004bba35c0aebaac86d45264c3
sha512_224(''); // 6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4
sha512_224('The quick brown fox jumps over the lazy dog'); // 944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37
sha512_224('The quick brown fox jumps over the lazy dog.'); // 6d6a9279495ec4061769752e7ff9c68b6b0b3c5a281b7917ce0572de
// It also supports UTF-8 encoding
sha512('中文'); // 8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a2755fbd05d8d8491cb2946febd5b0f124ffdfbaecf7e34946353c4f1b5ab29545895468
sha384('中文'); // 93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c
sha512_256('中文'); // b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72
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
// HMAC
sha512.hmac.hex('key', 'Message to hash');
sha512.hmac.array('key', 'Message to hash');
``` ```
### Prototype
If you prefer prototype style, you can add following code to add a prototype extension.
Code
```JavaScript
String.prototype.sha512 = function() {
return sha512(this);
};
String.prototype.sha384 = function() {
return sha384(this);
};
String.prototype.sha512_256 = function() {
return sha512_256(this);
};
String.prototype.sha512_224 = function() {
return sha512_224(this);
};
```
And then you could use like this:
```JavaScript
'message'.sha512();
'message'.sha384();
'message'.sha512_256();
'message'.sha512_224();
```
## License ## License
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT). The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
## Contact ## Contact
The project's website is located at https://github.com/emn178/js-sha512 The project's website is located at https://github.com/emn178/js-sha512
Author: Chen, Yi-Cyuan (emn178@gmail.com) Author: emn178@gmail.com

@ -1,7 +1,7 @@
{ {
"name": "js-sha512", "name": "js-sha512",
"version": "0.9.0", "version": "0.2.2",
"main": ["src/sha512.js"], "main": ["build/sha512.min.js"],
"ignore": [ "ignore": [
"samples", "samples",
"tests" "tests"

File diff suppressed because one or more lines are too long

151
index.d.ts vendored

@ -1,151 +0,0 @@
type Message = string | number[] | ArrayBuffer | Uint8Array;
interface Hasher {
/**
* Update hash
*
* @param message The message you want to hash.
*/
update(message: Message): Hasher;
/**
* Return hash in hex string.
*/
hex(): string;
/**
* Return hash in hex string.
*/
toString(): string;
/**
* Return hash in ArrayBuffer.
*/
arrayBuffer(): ArrayBuffer;
/**
* Return hash in integer array.
*/
digest(): number[];
/**
* Return hash in integer array.
*/
array(): number[];
}
interface Hmac {
/**
* Computes a Hash-based message authentication code (HMAC) using a secret key
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
(secretKey: string, message: Message): string;
/**
* Create a hash object using a secret key.
*
* @param secretKey The Secret Key
*/
create(secretKey: string): Hasher;
/**
* Create a hash object and hash message using a secret key
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
update(secretKey: string, message: Message): Hasher;
/**
* Return hash in hex string.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
hex(secretKey: string, message: Message): string;
/**
* Return hash in ArrayBuffer.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
arrayBuffer(secretKey: string, message: Message): ArrayBuffer;
/**
* Return hash in integer array.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
digest(secretKey: string, message: Message): number[];
/**
* Return hash in integer array.
*
* @param secretKey The Secret Key
* @param message The message you want to hash.
*/
array(secretKey: string, message: Message): number[];
}
interface Hash {
/**
* Hash and return hex string.
*
* @param message The message you want to hash.
*/
(message: Message): string;
/**
* Hash and return hex string.
*
* @param message The message you want to hash.
*/
hex(message: Message): string;
/**
* Hash and return ArrayBuffer.
*
* @param message The message you want to hash.
*/
arrayBuffer(message: Message): ArrayBuffer;
/**
* Hash and return integer array.
*
* @param message The message you want to hash.
*/
digest(message: Message): number[];
/**
* Hash and return integer array.
*
* @param message The message you want to hash.
*/
array(message: Message): number[];
/**
* Create a hash object.
*/
create(): Hasher;
/**
* Create a hash object and hash message.
*
* @param message The message you want to hash.
*/
update(message: Message): Hasher;
/**
* HMAC interface
*/
hmac: Hmac;
}
export var sha512: Hash;
export var sha384: Hash;
export var sha512_256: Hash;
export var sha512_224: Hash;

1979
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,21 +1,15 @@
{ {
"name": "js-sha512", "name": "js-sha512",
"version": "0.9.0", "version": "0.2.2",
"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": {
"expect.js": "~0.3.1", "expect.js": "~0.3.1",
"mocha": "~10.2.0", "jscoverage": "~0.5.9"
"nyc": "^15.1.0",
"requirejs": "^2.1.22",
"tiny-worker": "^2.3.0",
"uglify-js": "^3.1.9"
}, },
"scripts": { "scripts": {
"test": "nyc mocha tests/node-test.js", "test": "mocha tests/node-test.js -r jscoverage",
"report": "nyc --reporter=html --reporter=text mocha tests/node-test.js --exit", "coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls"
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"build": "uglifyjs src/sha512.js -c -m eval --comments -o build/sha512.min.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -34,14 +28,9 @@
"HMAC" "HMAC"
], ],
"license": "MIT", "license": "MIT",
"author": "Chen, Yi-Cyuan <emn178@gmail.com>", "author": "emn178 <emn178@gmail.com>",
"homepage": "https://github.com/emn178/js-sha512", "homepage": "https://github.com/emn178/js-sha512",
"bugs": { "bugs": {
"url": "https://github.com/emn178/js-sha512/issues" "url": "https://github.com/emn178/js-sha512/issues"
},
"nyc": {
"exclude": [
"tests"
]
} }
} }

@ -1,37 +1,23 @@
/* /*
* [js-sha512]{@link https://github.com/emn178/js-sha512} * js-sha512 v0.2.2
* https://github.com/emn178/js-sha512
* *
* @version 0.9.0 * Copyright 2014-2015, emn178@gmail.com
* @author Chen, Yi-Cyuan [emn178@gmail.com] *
* @copyright Chen, Yi-Cyuan 2014-2024 * Licensed under the MIT license:
* @license MIT * http://www.opensource.org/licenses/MIT
*/ */
/*jslint bitwise: true */ ;(function(root, undefined) {
(function () {
'use strict'; 'use strict';
var INPUT_ERROR = 'input is invalid type'; var NODE_JS = typeof(module) != 'undefined';
var FINALIZE_ERROR = 'finalize already called';
var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {};
if (root.JS_SHA512_NO_WINDOW) {
WINDOW = false;
}
var WEB_WORKER = !WINDOW && typeof self === 'object';
var NODE_JS = !root.JS_SHA512_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if(NODE_JS) { if(NODE_JS) {
root = global; root = global;
} else if (WEB_WORKER) {
root = self;
} }
var COMMON_JS = !root.JS_SHA512_NO_COMMON_JS && typeof module === 'object' && module.exports;
var AMD = typeof define === 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_SHA512_NO_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];
var K = [ var K =[0x428A2F98, 0xD728AE22, 0x71374491, 0x23EF65CD,
0x428A2F98, 0xD728AE22, 0x71374491, 0x23EF65CD,
0xB5C0FBCF, 0xEC4D3B2F, 0xE9B5DBA5, 0x8189DBBC, 0xB5C0FBCF, 0xEC4D3B2F, 0xE9B5DBA5, 0x8189DBBC,
0x3956C25B, 0xF348B538, 0x59F111F1, 0xB605D019, 0x3956C25B, 0xF348B538, 0x59F111F1, 0xB605D019,
0x923F82A4, 0xAF194F9B, 0xAB1C5ED5, 0xDA6D8118, 0x923F82A4, 0xAF194F9B, 0xAB1C5ED5, 0xDA6D8118,
@ -70,191 +56,104 @@
0x28DB77F5, 0x23047D84, 0x32CAAB7B, 0x40C72493, 0x28DB77F5, 0x23047D84, 0x32CAAB7B, 0x40C72493,
0x3C9EBE0A, 0x15C9BEBC, 0x431D67C4, 0x9C100D4C, 0x3C9EBE0A, 0x15C9BEBC, 0x431D67C4, 0x9C100D4C,
0x4CC5D4BE, 0xCB3E42B6, 0x597F299C, 0xFC657E2A, 0x4CC5D4BE, 0xCB3E42B6, 0x597F299C, 0xFC657E2A,
0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817 0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817];
];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
var blocks = []; var blocks = [];
var isArray = Array.isArray; var sha384 = function(message) {
if (root.JS_SHA512_NO_NODE_JS || !isArray) { return sha512(message, 384);
isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}; };
}
var isView = ArrayBuffer.isView; var sha512_256 = function(message) {
if (ARRAY_BUFFER && (root.JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW || !isView)) { return sha512(message, 256);
isView = function (obj) {
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
}; };
}
// [message: string, isString: bool]
var formatMessage = function (message) {
var type = typeof message;
if (type === 'string') {
return [message, true];
}
if (type !== 'object' || message === null) {
throw new Error(INPUT_ERROR);
}
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
return [new Uint8Array(message), false];
}
if (!isArray(message) && !isView(message)) {
throw new Error(INPUT_ERROR);
}
return [message, false];
}
var createOutputMethod = function (outputType, bits) { var sha512_224 = function(message) {
return function (message) { return sha512(message, 224);
return new Sha512(bits, true).update(message)[outputType]();
};
}; };
var createMethod = function (bits) { var sha512 = function(message, bits) {
var method = createOutputMethod('hex', bits); var h0h, h0l, h1h, h1l, h2h, h2l, h3h, h3l,
method.create = function () { h4h, h4l, h5h, h5l, h6h, h6l, h7h, h7l, block, code, end = false,
return new Sha512(bits); i, j, index = 0, start = 0, bytes = 0, length = message.length,
}; s0h, s0l, s1h, s1l, c1, c2, c3, c4,
method.update = function (message) { abh, abl, dah, dal, cdh, cdl, bch, bcl,
return method.create().update(message); majh, majl, t1h, t1l, t2h, t2l, chh, chl;
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createOutputMethod(type, bits);
}
return method;
};
var createHmacOutputMethod = function (outputType, bits) {
return function (key, message) {
return new HmacSha512(key, bits, true).update(message)[outputType]();
};
};
var createHmacMethod = function (bits) {
var method = createHmacOutputMethod('hex', bits);
method.create = function (key) {
return new HmacSha512(key, bits);
};
method.update = function (key, message) {
return method.create(key).update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createHmacOutputMethod(type, bits);
}
return method;
};
function Sha512(bits, sharedMemory) {
if (sharedMemory) {
blocks[0] = blocks[1] = blocks[2] = blocks[3] = blocks[4] =
blocks[5] = blocks[6] = blocks[7] = blocks[8] =
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;
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) {
this.h0h = 0xCBBB9D5D; h0h = 0xCBBB9D5D;
this.h0l = 0xC1059ED8; h0l = 0xC1059ED8;
this.h1h = 0x629A292A; h1h = 0x629A292A;
this.h1l = 0x367CD507; h1l = 0x367CD507;
this.h2h = 0x9159015A; h2h = 0x9159015A;
this.h2l = 0x3070DD17; h2l = 0x3070DD17;
this.h3h = 0x152FECD8; h3h = 0x152FECD8;
this.h3l = 0xF70E5939; h3l = 0xF70E5939;
this.h4h = 0x67332667; h4h = 0x67332667;
this.h4l = 0xFFC00B31; h4l = 0xFFC00B31;
this.h5h = 0x8EB44A87; h5h = 0x8EB44A87;
this.h5l = 0x68581511; h5l = 0x68581511;
this.h6h = 0xDB0C2E0D; h6h = 0xDB0C2E0D;
this.h6l = 0x64F98FA7; h6l = 0x64F98FA7;
this.h7h = 0x47B5481D; h7h = 0x47B5481D;
this.h7l = 0xBEFA4FA4; h7l = 0xBEFA4FA4;
} else if(bits == 256) { } else if(bits == 256) {
this.h0h = 0x22312194; h0h = 0x22312194;
this.h0l = 0xFC2BF72C; h0l = 0xFC2BF72C;
this.h1h = 0x9F555FA3; h1h = 0x9F555FA3;
this.h1l = 0xC84C64C2; h1l = 0xC84C64C2;
this.h2h = 0x2393B86B; h2h = 0x2393B86B;
this.h2l = 0x6F53B151; h2l = 0x6F53B151;
this.h3h = 0x96387719; h3h = 0x96387719;
this.h3l = 0x5940EABD; h3l = 0x5940EABD;
this.h4h = 0x96283EE2; h4h = 0x96283EE2;
this.h4l = 0xA88EFFE3; h4l = 0xA88EFFE3;
this.h5h = 0xBE5E1E25; h5h = 0xBE5E1E25;
this.h5l = 0x53863992; h5l = 0x53863992;
this.h6h = 0x2B0199FC; h6h = 0x2B0199FC;
this.h6l = 0x2C85B8AA; h6l = 0x2C85B8AA;
this.h7h = 0x0EB72DDC; h7h = 0x0EB72DDC;
this.h7l = 0x81C52CA2; h7l = 0x81C52CA2;
} else if(bits == 224) { } else if(bits == 224) {
this.h0h = 0x8C3D37C8; h0h = 0x8C3D37C8;
this.h0l = 0x19544DA2; h0l = 0x19544DA2;
this.h1h = 0x73E19966; h1h = 0x73E19966;
this.h1l = 0x89DCD4D6; h1l = 0x89DCD4D6;
this.h2h = 0x1DFAB7AE; h2h = 0x1DFAB7AE;
this.h2l = 0x32FF9C82; h2l = 0x32FF9C82;
this.h3h = 0x679DD514; h3h = 0x679DD514;
this.h3l = 0x582F9FCF; h3l = 0x582F9FCF;
this.h4h = 0x0F6D2B69; h4h = 0x0F6D2B69;
this.h4l = 0x7BD44DA8; h4l = 0x7BD44DA8;
this.h5h = 0x77E36F73; h5h = 0x77E36F73;
this.h5l = 0x04C48942; h5l = 0x04C48942;
this.h6h = 0x3F9D85A8; h6h = 0x3F9D85A8;
this.h6l = 0x6A1D36C8; h6l = 0x6A1D36C8;
this.h7h = 0x1112E6AD; h7h = 0x1112E6AD;
this.h7l = 0x91D692A1; h7l = 0x91D692A1;
} else { // 512 } else { // 512
this.h0h = 0x6A09E667; h0h = 0x6A09E667;
this.h0l = 0xF3BCC908; h0l = 0xF3BCC908;
this.h1h = 0xBB67AE85; h1h = 0xBB67AE85;
this.h1l = 0x84CAA73B; h1l = 0x84CAA73B;
this.h2h = 0x3C6EF372; h2h = 0x3C6EF372;
this.h2l = 0xFE94F82B; h2l = 0xFE94F82B;
this.h3h = 0xA54FF53A; h3h = 0xA54FF53A;
this.h3l = 0x5F1D36F1; h3l = 0x5F1D36F1;
this.h4h = 0x510E527F; h4h = 0x510E527F;
this.h4l = 0xADE682D1; h4l = 0xADE682D1;
this.h5h = 0x9B05688C; h5h = 0x9B05688C;
this.h5l = 0x2B3E6C1F; h5l = 0x2B3E6C1F;
this.h6h = 0x1F83D9AB; h6h = 0x1F83D9AB;
this.h6l = 0xFB41BD6B; h6l = 0xFB41BD6B;
this.h7h = 0x5BE0CD19; h7h = 0x5BE0CD19;
this.h7l = 0x137E2179; h7l = 0x137E2179;
} bits = 512;
this.bits = bits; }
block = 0;
this.block = this.start = this.bytes = this.hBytes = 0; do {
this.finalized = this.hashed = false; blocks[0] = block;
} blocks[1] = blocks[2] = blocks[3] = blocks[4] =
Sha512.prototype.update = function (message) {
if (this.finalized) {
throw new Error(FINALIZE_ERROR);
}
var result = formatMessage(message);
message = result[0];
var isString = result[1];
var code, index = 0, i, length = message.length, blocks = this.blocks;
while (index < length) {
if (this.hashed) {
this.hashed = false;
blocks[0] = this.block;
this.block = 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] =
blocks[13] = blocks[14] = blocks[15] = blocks[16] = blocks[13] = blocks[14] = blocks[15] = blocks[16] =
@ -262,88 +161,36 @@
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(isString) {
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];
} else if (code < 0x800) { } else if (code < 0x800) {
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else if (code < 0xd800 || code >= 0xe000) { } else if (code < 0xd800 || code >= 0xe000) {
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else { } else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
}
} else {
for (i = this.start; index < length && i < 128; ++index) {
blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
}
} }
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;
} }
bytes += i - start;
start = i - 128;
if(index == length) {
blocks[i >> 2] |= EXTRA[i & 3];
++index;
} }
if (this.bytes > 4294967295) { block = blocks[32];
this.hBytes += this.bytes / 4294967296 << 0; if(index > length && i < 112) {
this.bytes = this.bytes % 4294967296; blocks[31] = bytes << 3;
end = true;
} }
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];
this.block = blocks[32];
if (i >= 112) {
if (!this.hashed) {
this.hash();
}
blocks[0] = this.block;
blocks[1] = blocks[2] = blocks[3] = blocks[4] =
blocks[5] = blocks[6] = blocks[7] = blocks[8] =
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[30] = this.hBytes << 3 | this.bytes >>> 29;
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];
@ -584,334 +431,149 @@
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);
this.h0h = (c4 << 16) | (c3 & 0xFFFF); h0h = (c4 << 16) | (c3 & 0xFFFF);
this.h0l = (c2 << 16) | (c1 & 0xFFFF); 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);
this.h1h = (c4 << 16) | (c3 & 0xFFFF); h1h = (c4 << 16) | (c3 & 0xFFFF);
this.h1l = (c2 << 16) | (c1 & 0xFFFF); 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);
this.h2h = (c4 << 16) | (c3 & 0xFFFF); h2h = (c4 << 16) | (c3 & 0xFFFF);
this.h2l = (c2 << 16) | (c1 & 0xFFFF); 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);
this.h3h = (c4 << 16) | (c3 & 0xFFFF); h3h = (c4 << 16) | (c3 & 0xFFFF);
this.h3l = (c2 << 16) | (c1 & 0xFFFF); 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);
this.h4h = (c4 << 16) | (c3 & 0xFFFF); h4h = (c4 << 16) | (c3 & 0xFFFF);
this.h4l = (c2 << 16) | (c1 & 0xFFFF); 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);
this.h5h = (c4 << 16) | (c3 & 0xFFFF); h5h = (c4 << 16) | (c3 & 0xFFFF);
this.h5l = (c2 << 16) | (c1 & 0xFFFF); 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);
this.h6h = (c4 << 16) | (c3 & 0xFFFF); h6h = (c4 << 16) | (c3 & 0xFFFF);
this.h6l = (c2 << 16) | (c1 & 0xFFFF); 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);
this.h7h = (c4 << 16) | (c3 & 0xFFFF); h7h = (c4 << 16) | (c3 & 0xFFFF);
this.h7l = (c2 << 16) | (c1 & 0xFFFF); h7l = (c2 << 16) | (c1 & 0xFFFF);
}; } while(!end);
Sha512.prototype.hex = function () { var hex = HEX_CHARS[(h0h >> 28) & 0x0F] + HEX_CHARS[(h0h >> 24) & 0x0F] +
this.finalize(); HEX_CHARS[(h0h >> 20) & 0x0F] + HEX_CHARS[(h0h >> 16) & 0x0F] +
HEX_CHARS[(h0h >> 12) & 0x0F] + HEX_CHARS[(h0h >> 8) & 0x0F] +
var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l, HEX_CHARS[(h0h >> 4) & 0x0F] + HEX_CHARS[h0h & 0x0F] +
h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, HEX_CHARS[(h0l >> 28) & 0x0F] + HEX_CHARS[(h0l >> 24) & 0x0F] +
h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l, HEX_CHARS[(h0l >> 20) & 0x0F] + HEX_CHARS[(h0l >> 16) & 0x0F] +
h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l, HEX_CHARS[(h0l >> 12) & 0x0F] + HEX_CHARS[(h0l >> 8) & 0x0F] +
bits = this.bits; HEX_CHARS[(h0l >> 4) & 0x0F] + HEX_CHARS[h0l & 0x0F] +
HEX_CHARS[(h1h >> 28) & 0x0F] + HEX_CHARS[(h1h >> 24) & 0x0F] +
var hex = HEX_CHARS[(h0h >>> 28) & 0x0F] + HEX_CHARS[(h0h >>> 24) & 0x0F] + HEX_CHARS[(h1h >> 20) & 0x0F] + HEX_CHARS[(h1h >> 16) & 0x0F] +
HEX_CHARS[(h0h >>> 20) & 0x0F] + HEX_CHARS[(h0h >>> 16) & 0x0F] + HEX_CHARS[(h1h >> 12) & 0x0F] + HEX_CHARS[(h1h >> 8) & 0x0F] +
HEX_CHARS[(h0h >>> 12) & 0x0F] + HEX_CHARS[(h0h >>> 8) & 0x0F] + HEX_CHARS[(h1h >> 4) & 0x0F] + HEX_CHARS[h1h & 0x0F] +
HEX_CHARS[(h0h >>> 4) & 0x0F] + HEX_CHARS[h0h & 0x0F] + HEX_CHARS[(h1l >> 28) & 0x0F] + HEX_CHARS[(h1l >> 24) & 0x0F] +
HEX_CHARS[(h0l >>> 28) & 0x0F] + HEX_CHARS[(h0l >>> 24) & 0x0F] + HEX_CHARS[(h1l >> 20) & 0x0F] + HEX_CHARS[(h1l >> 16) & 0x0F] +
HEX_CHARS[(h0l >>> 20) & 0x0F] + HEX_CHARS[(h0l >>> 16) & 0x0F] + HEX_CHARS[(h1l >> 12) & 0x0F] + HEX_CHARS[(h1l >> 8) & 0x0F] +
HEX_CHARS[(h0l >>> 12) & 0x0F] + HEX_CHARS[(h0l >>> 8) & 0x0F] + HEX_CHARS[(h1l >> 4) & 0x0F] + HEX_CHARS[h1l & 0x0F] +
HEX_CHARS[(h0l >>> 4) & 0x0F] + HEX_CHARS[h0l & 0x0F] + HEX_CHARS[(h2h >> 28) & 0x0F] + HEX_CHARS[(h2h >> 24) & 0x0F] +
HEX_CHARS[(h1h >>> 28) & 0x0F] + HEX_CHARS[(h1h >>> 24) & 0x0F] + HEX_CHARS[(h2h >> 20) & 0x0F] + HEX_CHARS[(h2h >> 16) & 0x0F] +
HEX_CHARS[(h1h >>> 20) & 0x0F] + HEX_CHARS[(h1h >>> 16) & 0x0F] + HEX_CHARS[(h2h >> 12) & 0x0F] + HEX_CHARS[(h2h >> 8) & 0x0F] +
HEX_CHARS[(h1h >>> 12) & 0x0F] + HEX_CHARS[(h1h >>> 8) & 0x0F] + HEX_CHARS[(h2h >> 4) & 0x0F] + HEX_CHARS[h2h & 0x0F] +
HEX_CHARS[(h1h >>> 4) & 0x0F] + HEX_CHARS[h1h & 0x0F] + HEX_CHARS[(h2l >> 28) & 0x0F] + HEX_CHARS[(h2l >> 24) & 0x0F] +
HEX_CHARS[(h1l >>> 28) & 0x0F] + HEX_CHARS[(h1l >>> 24) & 0x0F] + HEX_CHARS[(h2l >> 20) & 0x0F] + HEX_CHARS[(h2l >> 16) & 0x0F] +
HEX_CHARS[(h1l >>> 20) & 0x0F] + HEX_CHARS[(h1l >>> 16) & 0x0F] + HEX_CHARS[(h2l >> 12) & 0x0F] + HEX_CHARS[(h2l >> 8) & 0x0F] +
HEX_CHARS[(h1l >>> 12) & 0x0F] + HEX_CHARS[(h1l >>> 8) & 0x0F] + HEX_CHARS[(h2l >> 4) & 0x0F] + HEX_CHARS[h2l & 0x0F] +
HEX_CHARS[(h1l >>> 4) & 0x0F] + HEX_CHARS[h1l & 0x0F] + HEX_CHARS[(h3h >> 28) & 0x0F] + HEX_CHARS[(h3h >> 24) & 0x0F] +
HEX_CHARS[(h2h >>> 28) & 0x0F] + HEX_CHARS[(h2h >>> 24) & 0x0F] + HEX_CHARS[(h3h >> 20) & 0x0F] + HEX_CHARS[(h3h >> 16) & 0x0F] +
HEX_CHARS[(h2h >>> 20) & 0x0F] + HEX_CHARS[(h2h >>> 16) & 0x0F] + HEX_CHARS[(h3h >> 12) & 0x0F] + HEX_CHARS[(h3h >> 8) & 0x0F] +
HEX_CHARS[(h2h >>> 12) & 0x0F] + HEX_CHARS[(h2h >>> 8) & 0x0F] + HEX_CHARS[(h3h >> 4) & 0x0F] + HEX_CHARS[h3h & 0x0F];
HEX_CHARS[(h2h >>> 4) & 0x0F] + HEX_CHARS[h2h & 0x0F] +
HEX_CHARS[(h2l >>> 28) & 0x0F] + HEX_CHARS[(h2l >>> 24) & 0x0F] +
HEX_CHARS[(h2l >>> 20) & 0x0F] + HEX_CHARS[(h2l >>> 16) & 0x0F] +
HEX_CHARS[(h2l >>> 12) & 0x0F] + HEX_CHARS[(h2l >>> 8) & 0x0F] +
HEX_CHARS[(h2l >>> 4) & 0x0F] + HEX_CHARS[h2l & 0x0F] +
HEX_CHARS[(h3h >>> 28) & 0x0F] + HEX_CHARS[(h3h >>> 24) & 0x0F] +
HEX_CHARS[(h3h >>> 20) & 0x0F] + HEX_CHARS[(h3h >>> 16) & 0x0F] +
HEX_CHARS[(h3h >>> 12) & 0x0F] + HEX_CHARS[(h3h >>> 8) & 0x0F] +
HEX_CHARS[(h3h >>> 4) & 0x0F] + HEX_CHARS[h3h & 0x0F];
if(bits >= 256) { if(bits >= 256) {
hex += HEX_CHARS[(h3l >>> 28) & 0x0F] + HEX_CHARS[(h3l >>> 24) & 0x0F] + hex += HEX_CHARS[(h3l >> 28) & 0x0F] + HEX_CHARS[(h3l >> 24) & 0x0F] +
HEX_CHARS[(h3l >>> 20) & 0x0F] + HEX_CHARS[(h3l >>> 16) & 0x0F] + HEX_CHARS[(h3l >> 20) & 0x0F] + HEX_CHARS[(h3l >> 16) & 0x0F] +
HEX_CHARS[(h3l >>> 12) & 0x0F] + HEX_CHARS[(h3l >>> 8) & 0x0F] + HEX_CHARS[(h3l >> 12) & 0x0F] + HEX_CHARS[(h3l >> 8) & 0x0F] +
HEX_CHARS[(h3l >>> 4) & 0x0F] + HEX_CHARS[h3l & 0x0F]; HEX_CHARS[(h3l >> 4) & 0x0F] + HEX_CHARS[h3l & 0x0F];
} }
if(bits >= 384) { if(bits >= 384) {
hex += HEX_CHARS[(h4h >>> 28) & 0x0F] + HEX_CHARS[(h4h >>> 24) & 0x0F] + hex += HEX_CHARS[(h4h >> 28) & 0x0F] + HEX_CHARS[(h4h >> 24) & 0x0F] +
HEX_CHARS[(h4h >>> 20) & 0x0F] + HEX_CHARS[(h4h >>> 16) & 0x0F] + HEX_CHARS[(h4h >> 20) & 0x0F] + HEX_CHARS[(h4h >> 16) & 0x0F] +
HEX_CHARS[(h4h >>> 12) & 0x0F] + HEX_CHARS[(h4h >>> 8) & 0x0F] + HEX_CHARS[(h4h >> 12) & 0x0F] + HEX_CHARS[(h4h >> 8) & 0x0F] +
HEX_CHARS[(h4h >>> 4) & 0x0F] + HEX_CHARS[h4h & 0x0F] + HEX_CHARS[(h4h >> 4) & 0x0F] + HEX_CHARS[h4h & 0x0F] +
HEX_CHARS[(h4l >>> 28) & 0x0F] + HEX_CHARS[(h4l >>> 24) & 0x0F] + HEX_CHARS[(h4l >> 28) & 0x0F] + HEX_CHARS[(h4l >> 24) & 0x0F] +
HEX_CHARS[(h4l >>> 20) & 0x0F] + HEX_CHARS[(h4l >>> 16) & 0x0F] + HEX_CHARS[(h4l >> 20) & 0x0F] + HEX_CHARS[(h4l >> 16) & 0x0F] +
HEX_CHARS[(h4l >>> 12) & 0x0F] + HEX_CHARS[(h4l >>> 8) & 0x0F] + HEX_CHARS[(h4l >> 12) & 0x0F] + HEX_CHARS[(h4l >> 8) & 0x0F] +
HEX_CHARS[(h4l >>> 4) & 0x0F] + HEX_CHARS[h4l & 0x0F] + HEX_CHARS[(h4l >> 4) & 0x0F] + HEX_CHARS[h4l & 0x0F] +
HEX_CHARS[(h5h >>> 28) & 0x0F] + HEX_CHARS[(h5h >>> 24) & 0x0F] + HEX_CHARS[(h5h >> 28) & 0x0F] + HEX_CHARS[(h5h >> 24) & 0x0F] +
HEX_CHARS[(h5h >>> 20) & 0x0F] + HEX_CHARS[(h5h >>> 16) & 0x0F] + HEX_CHARS[(h5h >> 20) & 0x0F] + HEX_CHARS[(h5h >> 16) & 0x0F] +
HEX_CHARS[(h5h >>> 12) & 0x0F] + HEX_CHARS[(h5h >>> 8) & 0x0F] + HEX_CHARS[(h5h >> 12) & 0x0F] + HEX_CHARS[(h5h >> 8) & 0x0F] +
HEX_CHARS[(h5h >>> 4) & 0x0F] + HEX_CHARS[h5h & 0x0F] + HEX_CHARS[(h5h >> 4) & 0x0F] + HEX_CHARS[h5h & 0x0F] +
HEX_CHARS[(h5l >>> 28) & 0x0F] + HEX_CHARS[(h5l >>> 24) & 0x0F] + HEX_CHARS[(h5l >> 28) & 0x0F] + HEX_CHARS[(h5l >> 24) & 0x0F] +
HEX_CHARS[(h5l >>> 20) & 0x0F] + HEX_CHARS[(h5l >>> 16) & 0x0F] + HEX_CHARS[(h5l >> 20) & 0x0F] + HEX_CHARS[(h5l >> 16) & 0x0F] +
HEX_CHARS[(h5l >>> 12) & 0x0F] + HEX_CHARS[(h5l >>> 8) & 0x0F] + HEX_CHARS[(h5l >> 12) & 0x0F] + HEX_CHARS[(h5l >> 8) & 0x0F] +
HEX_CHARS[(h5l >>> 4) & 0x0F] + HEX_CHARS[h5l & 0x0F]; HEX_CHARS[(h5l >> 4) & 0x0F] + HEX_CHARS[h5l & 0x0F];
} }
if(bits == 512) { if(bits == 512) {
hex += HEX_CHARS[(h6h >>> 28) & 0x0F] + HEX_CHARS[(h6h >>> 24) & 0x0F] + hex += HEX_CHARS[(h6h >> 28) & 0x0F] + HEX_CHARS[(h6h >> 24) & 0x0F] +
HEX_CHARS[(h6h >>> 20) & 0x0F] + HEX_CHARS[(h6h >>> 16) & 0x0F] + HEX_CHARS[(h6h >> 20) & 0x0F] + HEX_CHARS[(h6h >> 16) & 0x0F] +
HEX_CHARS[(h6h >>> 12) & 0x0F] + HEX_CHARS[(h6h >>> 8) & 0x0F] + HEX_CHARS[(h6h >> 12) & 0x0F] + HEX_CHARS[(h6h >> 8) & 0x0F] +
HEX_CHARS[(h6h >>> 4) & 0x0F] + HEX_CHARS[h6h & 0x0F] + HEX_CHARS[(h6h >> 4) & 0x0F] + HEX_CHARS[h6h & 0x0F] +
HEX_CHARS[(h6l >>> 28) & 0x0F] + HEX_CHARS[(h6l >>> 24) & 0x0F] + HEX_CHARS[(h6l >> 28) & 0x0F] + HEX_CHARS[(h6l >> 24) & 0x0F] +
HEX_CHARS[(h6l >>> 20) & 0x0F] + HEX_CHARS[(h6l >>> 16) & 0x0F] + HEX_CHARS[(h6l >> 20) & 0x0F] + HEX_CHARS[(h6l >> 16) & 0x0F] +
HEX_CHARS[(h6l >>> 12) & 0x0F] + HEX_CHARS[(h6l >>> 8) & 0x0F] + HEX_CHARS[(h6l >> 12) & 0x0F] + HEX_CHARS[(h6l >> 8) & 0x0F] +
HEX_CHARS[(h6l >>> 4) & 0x0F] + HEX_CHARS[h6l & 0x0F] + HEX_CHARS[(h6l >> 4) & 0x0F] + HEX_CHARS[h6l & 0x0F] +
HEX_CHARS[(h7h >>> 28) & 0x0F] + HEX_CHARS[(h7h >>> 24) & 0x0F] + HEX_CHARS[(h7h >> 28) & 0x0F] + HEX_CHARS[(h7h >> 24) & 0x0F] +
HEX_CHARS[(h7h >>> 20) & 0x0F] + HEX_CHARS[(h7h >>> 16) & 0x0F] + HEX_CHARS[(h7h >> 20) & 0x0F] + HEX_CHARS[(h7h >> 16) & 0x0F] +
HEX_CHARS[(h7h >>> 12) & 0x0F] + HEX_CHARS[(h7h >>> 8) & 0x0F] + HEX_CHARS[(h7h >> 12) & 0x0F] + HEX_CHARS[(h7h >> 8) & 0x0F] +
HEX_CHARS[(h7h >>> 4) & 0x0F] + HEX_CHARS[h7h & 0x0F] + HEX_CHARS[(h7h >> 4) & 0x0F] + HEX_CHARS[h7h & 0x0F] +
HEX_CHARS[(h7l >>> 28) & 0x0F] + HEX_CHARS[(h7l >>> 24) & 0x0F] + HEX_CHARS[(h7l >> 28) & 0x0F] + HEX_CHARS[(h7l >> 24) & 0x0F] +
HEX_CHARS[(h7l >>> 20) & 0x0F] + HEX_CHARS[(h7l >>> 16) & 0x0F] + HEX_CHARS[(h7l >> 20) & 0x0F] + HEX_CHARS[(h7l >> 16) & 0x0F] +
HEX_CHARS[(h7l >>> 12) & 0x0F] + HEX_CHARS[(h7l >>> 8) & 0x0F] + HEX_CHARS[(h7l >> 12) & 0x0F] + HEX_CHARS[(h7l >> 8) & 0x0F] +
HEX_CHARS[(h7l >>> 4) & 0x0F] + HEX_CHARS[h7l & 0x0F]; HEX_CHARS[(h7l >> 4) & 0x0F] + HEX_CHARS[h7l & 0x0F];
} }
return hex; return hex;
}; };
Sha512.prototype.toString = Sha512.prototype.hex; if(!root.JS_SHA512_TEST && NODE_JS) {
sha512.sha512 = sha512;
Sha512.prototype.digest = function () { sha512.sha384 = sha384;
this.finalize(); sha512.sha512_256 = sha512_256;
sha512.sha512_224 = sha512_224;
var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l, module.exports = sha512;
h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, } else if(root) {
h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l, root.sha512 = sha512;
h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l, root.sha384 = sha384;
bits = this.bits; root.sha512_256 = sha512_256;
root.sha512_224 = sha512_224;
var arr = [ }
(h0h >>> 24) & 0xFF, (h0h >>> 16) & 0xFF, (h0h >>> 8) & 0xFF, h0h & 0xFF, }(this));
(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;
};
Sha512.prototype.clone = function () {
var hash = new Sha512(this.bits, false);
this.copyTo(hash);
return hash;
};
Sha512.prototype.copyTo = function (hash) {
var i = 0, attrs = [
'h0h', 'h0l', 'h1h', 'h1l', 'h2h', 'h2l', 'h3h', 'h3l', 'h4h', 'h4l', 'h5h', 'h5l', 'h6h', 'h6l', 'h7h', 'h7l',
'start', 'bytes', 'hBytes', 'finalized', 'hashed', 'lastByteIndex'
];
for (i = 0; i < attrs.length; ++i) {
hash[attrs[i]] = this[attrs[i]];
}
for (i = 0; i < this.blocks.length; ++i) {
hash.blocks[i] = this.blocks[i];
}
};
function HmacSha512(key, bits, sharedMemory) {
var i, result = formatMessage(key);
key = result[0];
if (result[1]) {
var bytes = [], length = key.length, index = 0, code;
for (var i = 0; i < length; ++i) {
code = key.charCodeAt(i);
if (code < 0x80) {
bytes[index++] = code;
} else if (code < 0x800) {
bytes[index++] = (0xc0 | (code >>> 6));
bytes[index++] = (0x80 | (code & 0x3f));
} else if (code < 0xd800 || code >= 0xe000) {
bytes[index++] = (0xe0 | (code >>> 12));
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
bytes[index++] = (0x80 | (code & 0x3f));
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
bytes[index++] = (0xf0 | (code >>> 18));
bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
bytes[index++] = (0x80 | (code & 0x3f));
}
}
key = bytes;
}
if (key.length > 128) {
key = (new Sha512(bits, true)).update(key).array();
}
var oKeyPad = [], iKeyPad = [];
for (var i = 0; i < 128; ++i) {
var b = key[i] || 0;
oKeyPad[i] = 0x5c ^ b;
iKeyPad[i] = 0x36 ^ b;
}
Sha512.call(this, bits, sharedMemory);
this.update(iKeyPad);
this.oKeyPad = oKeyPad;
this.inner = true;
this.sharedMemory = sharedMemory;
}
HmacSha512.prototype = new Sha512();
HmacSha512.prototype.finalize = function () {
Sha512.prototype.finalize.call(this);
if (this.inner) {
this.inner = false;
var innerHash = this.array();
Sha512.call(this, this.bits, this.sharedMemory);
this.update(this.oKeyPad);
this.update(innerHash);
Sha512.prototype.finalize.call(this);
}
};
HmacSha512.prototype.clone = function () {
var hash = new HmacSha512([], this.bits, false);
this.copyTo(hash);
hash.inner = this.inner;
for (var i = 0; i < this.oKeyPad.length; ++i) {
hash.oKeyPad[i] = this.oKeyPad[i];
}
return hash;
};
var exports = createMethod(512);
exports.sha512 = exports;
exports.sha384 = createMethod(384);
exports.sha512_256 = createMethod(256);
exports.sha512_224 = createMethod(224);
exports.sha512.hmac = createHmacMethod(512);
exports.sha384.hmac = createHmacMethod(384);
exports.sha512_256.hmac = createHmacMethod(256);
exports.sha512_224.hmac = createHmacMethod(224);
if (COMMON_JS) {
module.exports = exports;
} else {
root.sha512 = exports.sha512;
root.sha384 = exports.sha384;
root.sha512_256 = exports.sha512_256;
root.sha512_224 = exports.sha512_224;
if (AMD) {
define(function () {
return exports;
});
}
}
})();

@ -1,290 +0,0 @@
(function (sha512, sha384, sha512_256, sha512_224) {
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
var array = new Uint8Array(this);
var hex = '';
for (var i = 0; i < array.length; ++i) {
var c = array[i].toString('16');
hex += c.length === 1 ? '0' + c : c;
}
return hex;
};
var testCases = {
sha512_hmac: {
'Test Vectors': {
'87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854': [
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
'Hi There'
],
'164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737': [
'Jefe',
'what do ya want for nothing?'
],
'fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
[0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd]
],
'b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd': [
[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19],
[0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd]
],
'80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
'Test Using Larger Than Block-Size Key - Hash Key First'
],
'e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
'This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.'
]
},
'UTF8': {
'8a2f8205e690f84981727a6c49f8131d6a76030e39ba69e08adff7ab344c58ae1c20c22532b61d1f0410d3174e2b3f3dd08e9d1d82e86c960683eddf279a8239': ['中文', '中文'],
'bb31bfef7be475a69f612741728c72237106053752a2804618c0b2d68cfe78cec6df18f4ae1fc0830f1153c1c497d817315c0129d84329b7f8c1d818306111d2': ['aécio', 'aécio'],
'cba25df64cf81b67d2476bb812be931263561f219f423f723aa7be2e5c3cd3566a8adbc77663b6b6a69742f8f866f8afbff9b52769e2a53baae6d6a77d010c8a': ['𠜎', '𠜎']
}
},
sha384_hmac: {
'Test Vectors': {
'afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6': [
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
'Hi There'
],
'af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649': [
'Jefe',
'what do ya want for nothing?'
],
'88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e55966144b2a5ab39dc13814b94e3ab6e101a34f27': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
[0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd]
],
'3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e1f573b4e6801dd23c4a7d679ccf8a386c674cffb': [
[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19],
[0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd]
],
'4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05033ac4c60c2ef6ab4030fe8296248df163f44952': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
'Test Using Larger Than Block-Size Key - Hash Key First'
],
'6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82461e99c5a678cc31e799176d3860e6110c46523e': [
[0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
'This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.'
]
},
'UTF8': {
'dd85fd0f7ae32037040ef2cfc344430addacf80f46f52c2ee066ab89ce6dedabb7d0a08cdb8765a7cfa616c7f4ddd377': ['中文', '中文'],
'9f7abdeda88240304f987ecf11ceea9bd6571de782a2c73505f9dcaf9a58ec08cf69d078fc80d13ceb18e366f9537b0d': ['aécio', 'aécio'],
'371f68d3377c583a29a38157348e4cc76d09aad3d86a5f4fdac661b2feefd7533338ffaf987267ac0ce3bb85e7787fce': ['𠜎', '𠜎']
}
},
sha512_256_hmac: {
'Test Vectors': {
'9f9126c3d9c3c330d760425ca8a217e31feae31bfe70196ff81642b868402eab': [
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
'Hi There'
],
'6df7b24630d5ccb2ee335407081a87188c221489768fa2020513b2d593359456': [
'Jefe',
'what do ya want for nothing?'
]
}
},
sha512_224_hmac: {
'Test Vectors': {
'b244ba01307c0e7a8ccaad13b1067a4cf6b961fe0c6a20bda3d92039': [
[0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b],
'Hi There'
],
'4a530b31a79ebcce36916546317c45f247d83241dfb818fd37254bde': [
'Jefe',
'what do ya want for nothing?'
]
}
}
};
if (!(typeof JS_SHA512_NO_ARRAY_BUFFER === 'boolean' && JS_SHA512_NO_ARRAY_BUFFER)) {
testCases.sha512_hmac['ArrayBuffer'] = {
'f7688a104326d36c1940f6d28d746c0661d383e0d14fe8a04649444777610f5dd9565a36846ab9e9e734cf380d3a070d8ef021b5f3a50c481710a464968e3419': [
new ArrayBuffer(0),
'Hi There'
]
};
testCases.sha512_hmac['Uint8Array'] = {
'f7688a104326d36c1940f6d28d746c0661d383e0d14fe8a04649444777610f5dd9565a36846ab9e9e734cf380d3a070d8ef021b5f3a50c481710a464968e3419': [
new Uint8Array(0),
'Hi There'
]
};
testCases.sha384_hmac['ArrayBuffer'] = {
'da5393cef424a670d6db42c6ed6e7920779dfa4cbb98bf1c2e9c12ae10d10905d0c9e9d576c2a613be54b8daea246d4b': [
new ArrayBuffer(0),
'Hi There'
]
};
testCases.sha384_hmac['Uint8Array'] = {
'da5393cef424a670d6db42c6ed6e7920779dfa4cbb98bf1c2e9c12ae10d10905d0c9e9d576c2a613be54b8daea246d4b': [
new Uint8Array(0),
'Hi There'
]
};
}
var errorTestCases = [null, undefined, { length: 0 }, 0, 1, false, true, NaN, Infinity, function () {}];
function runTestCases(name, algorithm) {
var methods = [
{
name: name,
call: algorithm,
},
{
name: name + '.hex',
call: algorithm.hex
},
{
name: name + '.array',
call: function (key, message) {
return algorithm.array(key, message).toHexString();
}
},
{
name: name + '.digest',
call: function (key, message) {
return algorithm.digest(key, message).toHexString();
}
},
{
name: name + '.arrayBuffer',
call: function (key, message) {
return algorithm.arrayBuffer(key, message).toHexString();
}
}
];
var classMethods = [
{
name: 'create',
call: function (key, message) {
return algorithm.create(key).update(message).toString();
}
},
{
name: 'update',
call: function (key, message) {
return algorithm.update(key, message).toString();
}
},
{
name: 'hex',
call: function (key, message) {
return algorithm.update(key, message).hex();
}
},
{
name: 'array',
call: function (key, message) {
return algorithm.update(key, message).array().toHexString();
}
},
{
name: 'digest',
call: function (key, message) {
return algorithm.update(key, message).digest().toHexString();
}
},
{
name: 'arrayBuffer',
call: function (key, message) {
return algorithm.update(key, message).arrayBuffer().toHexString();
}
},
{
name: 'finalize',
call: function (key, message) {
var hash = algorithm.update(key, message);
hash.hex();
hash.finalize();
return hash.hex();
}
},
{
name: 'clone',
call: function (key, message) {
var hash = algorithm.update(key, message);
var hash2 = hash.clone();
hash.update('any');
return hash2.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[0], message[1])).to.be(hash);
});
})(testCase[hash], hash);
}
});
})(testCaseName);
}
});
});
classMethods.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[0], message[1])).to.be(hash);
});
})(testCase[hash], hash);
}
});
})(testCaseName);
}
});
});
context('when update after finalize', function () {
it('should throw error', function () {
expect(function () {
var hash = algorithm.update('key', 'any');
hash.hex();
hash.update('any');
}).to.throwError(/finalize already called/);
});
});
describe('#' + name, function () {
errorTestCases.forEach(function (testCase) {
context('when ' + testCase, function () {
it('should throw error', function () {
expect(function () {
algorithm(testCase, '');
}).to.throwError(/input is invalid type/);
});
});
});
});
});
}
runTestCases('sha512_hmac', sha512.hmac);
runTestCases('sha384_hmac', sha384.hmac);
runTestCases('sha512_256_hmac', sha512_256.hmac);
runTestCases('sha512_224_hmac', sha512_224.hmac);
})(sha512, sha384, sha512_256, sha512_224);

@ -3,9 +3,9 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>SHA512</title> <title>SHA512</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.css">
<script src="../node_modules/mocha/mocha.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js"></script>
<script src="../node_modules/expect.js/index.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/expect.js/0.2.0/expect.min.js"></script>
<script src="../src/sha512.js"></script> <script src="../src/sha512.js"></script>
</head> </head>
<body> <body>
@ -14,7 +14,6 @@
mocha.setup('bdd'); mocha.setup('bdd');
</script> </script>
<script src="test.js"></script> <script src="test.js"></script>
<script src="hmac-test.js"></script>
<script> <script>
mocha.checkLeaks(); mocha.checkLeaks();
mocha.run(); mocha.run();

@ -1,119 +1,17 @@
sha512 = require('../src/sha512.js').sha512;
sha384 = require('../src/sha512.js').sha384;
sha512_256 = require('../src/sha512.js').sha512_256;
sha512_224 = require('../src/sha512.js').sha512_224;
expect = require('expect.js'); expect = require('expect.js');
Worker = require("tiny-worker"); require('./test.js');
function unset() { delete require.cache[require.resolve('../src/sha512.js')]
delete require.cache[require.resolve('../src/sha512.js')]; delete require.cache[require.resolve('./test.js')]
delete require.cache[require.resolve('./test.js')];
delete require.cache[require.resolve('./hmac-test.js')];
sha512 = null; sha512 = null;
sha384 = null; sha384 = null;
sha512_256 = null; sha512_256 = null;
sha512_224 = null; sha512_224 = null;
BUFFER = undefined;
JS_SHA512_NO_WINDOW = undefined;
JS_SHA512_NO_NODE_JS = undefined;
JS_SHA512_NO_COMMON_JS = undefined;
JS_SHA512_NO_ARRAY_BUFFER = undefined;
JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = undefined;
window = undefined;
}
function requireToGlobal() { JS_SHA512_TEST = true;
sha512 = require('../src/sha512.js').sha512;
sha384 = require('../src/sha512.js').sha384;
sha512_256 = require('../src/sha512.js').sha512_256;
sha512_224 = require('../src/sha512.js').sha512_224;
}
function runCommonJsTest() {
requireToGlobal();
require('./test.js');
require('./hmac-test.js');
unset();
}
function runWindowTest() {
window = global;
require('../src/sha512.js'); require('../src/sha512.js');
require('./test.js'); require('./test.js');
require('./hmac-test.js');
unset();
}
// Node.js env
BUFFER = true;
runCommonJsTest();
// Webpack browser env
JS_SHA512_NO_NODE_JS = true;
window = global;
runCommonJsTest();
// browser env
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
runWindowTest();
// browser env and no array buffer
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
JS_SHA512_NO_ARRAY_BUFFER = true;
runWindowTest();
// browser env and no isView
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = true;
runWindowTest();
// browser AMD
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW = false;
window = global;
define = function (func) {
sha512 = func();
sha384 = sha512.sha384;
sha512_256 = sha512.sha512_256;
sha512_224 = sha512.sha512_224;
require('./test.js');
require('./hmac-test.js');
};
define.amd = true;
require('../src/sha512.js');
unset();
// webworker
WORKER = 'tests/worker.js';
SOURCE = 'src/sha512.js';
require('./worker-test.js');
delete require.cache[require.resolve('./worker-test.js')];
// cover webworker
JS_SHA512_NO_WINDOW = true;
JS_SHA512_NO_NODE_JS = true;
WORKER = './worker.js';
SOURCE = '../src/sha512.js';
window = global;
self = global;
Worker = function (file) {
require(file);
currentWorker = this;
this.postMessage = function (data) {
onmessage({data: data});
};
}
postMessage = function (data) {
currentWorker.onmessage({data: data});
}
importScripts = function () {};
requireToGlobal();
require('./worker-test.js');

@ -1,27 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SHA512</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/expect.js/index.js"></script>
<script src="../node_modules/requirejs/require.js"></script>
</head>
<body>
<div id="mocha"></div>
<script>
mocha.setup('bdd');
require(['../src/sha512.js'], function (sha512) {
window.sha512 = sha512;
window.sha384 = sha512.sha384;
window.sha512_256 = sha512.sha512_256;
window.sha512_224 = sha512.sha512_224;
require(['test.js'], function () {
mocha.checkLeaks();
mocha.run();
});
});
</script>
</body>
</html>

@ -1,353 +1,177 @@
(function(sha512, sha384, sha512_256, sha512_224) { (function(sha512, sha384, sha512_256, sha512_224) {
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () { describe('sha512', function() {
var array = new Uint8Array(this); describe('ascii', function() {
var hex = ''; describe('less than 128 bytes', function() {
for (var i = 0; i < array.length; ++i) { it('should be successful', function() {
var c = array[i].toString('16'); expect(sha512('')).to.be('cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e');
hex += c.length === 1 ? '0' + c : c; expect(sha512('The quick brown fox jumps over the lazy dog')).to.be('07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6');
} expect(sha512('The quick brown fox jumps over the lazy dog.')).to.be('91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed');
return hex; });
}; });
var testCases = { describe('more than 128 bytes', function() {
sha512: { it('should be successful', function() {
'ascii': { 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');
'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': '𠜎',
'2665b06c3aa040d34e3ebeb8eb462a23e9789be9aa44c5242213f33c9bf18d391325de84cd91e1cb8b586739a9037acbf606eb8139a64e0244cdc4779faf62f7': 'Tehtäväsi on muotoilla teksti, jossa käyttäjälle suositellaan hänen henkilökohtaisiin tietoihinsa perustuen avioehdon tekemistä. Suosittelemme nimenomaan tätä tuotetta käyttäjän henkilökohtaisista tiedoista johtuen. Tuottamasi tekstin tulee olla lyhyt, persoonallinen, ymmärrettävä ja todenmukainen. Suositus perustuu seuraaviin seikkoihin:\n\nSeikka 0: Avioehdon tekeminen on verohyötyjen vuoksi suositeltavaa, koska olet ilmaissut että haluat kuoleman tapauksessa turvata ensisijaisesti aviopuolisosi asemaa (ennemmin kuin lasten asemaa). Avioehdolla voit määrätä, että puolet kuolleen puolison omaisuudesta siirtyy verovapaasti leskelle.\n\nVoit halutessasi hyödyntää seuraavia tietoja tekstin muotoilussa persoonallisemmaksi: Käyttäjällä on kumppani nimeltä PARTNER_NAME. Käyttäjällä on suurperhe. Käyttäjällä on lapsiperhe.\n\nPuhuttele käyttäjää siihen sävyyn että tiedät jo mitä käyttäjä haluaa, koska hän on kertonut toiveistaan, ja niiden perusteella tehty suositus on ilmiselvä. Joten älä käytä epävarmoja ilmaisuja kuten "halutessasi", vaan kirjoita itsevarmoilla ilmaisuilla kuten "koska haluat". Älä tee oletuksia käyttäjän sukupuolesta, emme tiedä onko hän mies vai nainen. Älä käytä sanaa jälkikasvu, puhu ennemmin lapsesta tai lapsista riippuen onko lapsia yksi vai useampia. Älä puhuttele käyttäjää ensimmäisessä persoonassa, käytä ennemmin passiivimuotoa. Tekstin sävyn tulisi olla neutraalin asiallinen, ei melodramaattinen eikä leikkisä. Pysy totuudessa, älä keksi uusia seikkoja yllä listattujen lisäksi. Viittaa ihmisiin nimillä silloin kun se on mahdollista. Tekstin tulisi olla vain muutaman lauseen mittainen. Älä siis kirjoita pitkiä selityksiä äläkä kirjoita listoja. Tiivistä oleellinen tieto lyhyeksi ja persoonalliseksi tekstiksi. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
},
'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]
}
},
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]
}
},
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]
}
},
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]
}
}
};
if (!(typeof JS_SHA512_NO_ARRAY_BUFFER === 'boolean' && JS_SHA512_NO_ARRAY_BUFFER)) { describe('UTF8', function() {
testCases.sha512['Uint8Array'] = { describe('less than 128 bytes', function() {
'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]) it('should be successful', function() {
}; expect(sha512('中文')).to.be('8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a2755fbd05d8d8491cb2946febd5b0f124ffdfbaecf7e34946353c4f1b5ab29545895468');
testCases.sha512['Int8Array'] = { expect(sha512('aécio')).to.be('e1c6925243db76985abacaf9fa85e22697f549e67f65a36c88e4046a2260990ff9eefc3402396ea8dcbe8c592d8d5671bea612156eda38d3708d394bbd17d493');
'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]) expect(sha512('𠜎')).to.be('f3e7ee9cdf7dbb52f7edd59ce3d49868c64f2b3aceceab060b8eaaebdf9de0dae5866d660e3319c5aad426a2176cb1703efc73eb24d1a90458ceda1b7f4e3940');
}; });
testCases.sha512['ArrayBuffer'] = { });
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': new ArrayBuffer(0),
'b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee': new ArrayBuffer(1)
};
testCases.sha384['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])
};
testCases.sha384['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])
};
testCases.sha384['ArrayBuffer'] = {
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b': new ArrayBuffer(0),
'bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933ec2b413465966817a9c208a11717': new ArrayBuffer(1)
};
testCases.sha512_256['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])
};
testCases.sha512_256['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])
};
testCases.sha512_256['ArrayBuffer'] = {
'c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a': new ArrayBuffer(0),
'10baad1713566ac2333467bddb0597dec9066120dd72ac2dcb8394221dcbe43d': new ArrayBuffer(1)
};
testCases.sha512_224['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])
};
testCases.sha512_224['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])
};
testCases.sha512_224['ArrayBuffer'] = {
'6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4': new ArrayBuffer(0),
'283bb59af7081ed08197227d8f65b9591ffe1155be43e9550e57f941': new ArrayBuffer(1)
};
}
if (typeof BUFFER === 'boolean' && BUFFER) { describe('more than 128 bytes', function() {
testCases.sha512['Buffer'] = { it('should be successful', function() {
'07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': new Buffer(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])) expect(sha512('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('6cb7f6d3381a187edadb43c7cdcfbbed4d2c213a7dce8ea08fe42b9882b64e643202b4974a6db94f94650ab9173d97c58bd59f6d19d27e01aab76d8d08855c65');
}; expect(sha512('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一又譯雜湊演算法、摘要演算法等主流程式語言普遍已有MD5的實作。')).to.be('d24af1901aaf1458f089a6eddf784ce61c3012aee0df98bdb67ad2dc6b41a3b4051d40caac524373930ae396a2dde99a9204871b40892eea3e5f3c8d46da0c3c');
testCases.sha384['Buffer'] = { });
'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1': new Buffer(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])) });
}; });
testCases.sha512_256['Buffer'] = {
'dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d': new Buffer(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]))
};
testCases.sha512_224['Buffer'] = {
'944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37': new Buffer(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]))
};
}
var errorTestCases = [null, undefined, { length: 0 }, 0, 1, false, true, NaN, Infinity, function () {}]; 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');
});
});
});
function runTestCases(name, algorithm) { describe('sha384', function() {
var methods = [ describe('ascii', function() {
{ describe('less than 128 bytes', function() {
name: name, it('should be successful', function() {
call: algorithm, 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');
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 = [ describe('more than 128 bytes', function() {
{ it('should be successful', function() {
name: 'create', 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');
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.finalize();
return hash.hex();
}
},
{
name: 'clone',
call: function (message) {
var hash = algorithm.update(message);
var hash2 = hash.clone();
hash.update('any');
return hash2.hex();
}
}
];
var subTestCases = testCases[name]; 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(name, function () { describe('more than 128 bytes', function() {
methods.forEach(function (method) { it('should be successful', function() {
describe('#' + method.name, function () { expect(sha384('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('143f4bb1a89e576ea05bd8433a3903352c199bf6ef35bfa30afa1505d6fcef77476d1b1824105da160a5164b7c792328');
for (var testCaseName in subTestCases) { expect(sha384('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一又譯雜湊演算法、摘要演算法等主流程式語言普遍已有MD5的實作。')).to.be('432a8d25efb1a8d463acc7bbbed57365cddc72de3cc19d42e1d260b1479770ecea9dd403fead2949d4fabb36939f263a');
(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('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');
}); });
}); });
classMethods.forEach(function (method) { describe('more than 128 bytes', function() {
describe('#' + method.name, function () { it('should be successful', function() {
for (var testCaseName in subTestCases) { 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');
(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() {
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');
}); });
}); });
errorTestCases.forEach(function (testCase) { describe('more than 128 bytes', function() {
context('when ' + testCase, function () { it('should be successful', function() {
it('should throw error', function () { expect(sha512_256('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('d32a41d9858e45b68402f77cf9f3c3f992c36a4bffd230f78d666c87f97eaf7e');
expect(function () { expect(sha512_256('訊息摘要演算法第五版英語Message-Digest Algorithm 5縮寫為MD5是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一又譯雜湊演算法、摘要演算法等主流程式語言普遍已有MD5的實作。')).to.be('bd1abad59e6b8ad69bc17b6e05aa13f0cb725467fbeb45b83d3e4094332d1367');
algorithm(testCase);
}).to.throwError(/input is invalid type/);
}); });
}); });
}); });
context('when update after finalize', function () { describe('special length', function() {
it('should throw error', function () { it('should be successful', function() {
expect(function () { expect(sha512_256('012345678012345678012345678012345678012345678012345678012345012345678012345678012345678012345678012345678012345')).to.be('b8bd1d6cae9992f8619904683d54cbed560ec3ef2a33d8bc225175ec27dc09a4');
var hash = algorithm.update('any'); expect(sha512_256('0123456780123456780123456780123456780123456780123456780123450123456780123456780123456780123456780123456780123456')).to.be('4edb8bb93b959f482ce2e434585f3e164f53b00c42c4c46797445b39d225cfe3');
hash.hex(); expect(sha512_256('123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567')).to.be('44da7ca023996ec4b4ded88410e4acc209ca26c34dc0f26550d28503974fe2d1');
hash.update('any'); expect(sha512_256('1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678')).to.be('465859c0edc706a2a9c39d3175a715fdf6b764ccc43d45b5668c56f6d8aa9b9e');
}).to.throwError(/finalize already called/); });
}); });
}); });
context('when large size', function () { describe('sha512/224', function() {
var hash = algorithm.create(); describe('ascii', function() {
hash.bytes = 4294967295; describe('less than 128 bytes', function() {
hash.update('any'); it('should be successful', function() {
expect(hash.hBytes).to.be(1); 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');
});
}); });
}); });
}
runTestCases('sha512', sha512); describe('UTF8', function() {
runTestCases('sha384', sha384); describe('less than 128 bytes', function() {
runTestCases('sha512_256', sha512_256); it('should be successful', function() {
runTestCases('sha512_224', sha512_224); 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);

@ -1,24 +0,0 @@
(function (Worker, WORKER, SOURCE) {
var cases = {
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e': '',
'07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6': 'The quick brown fox jumps over the lazy dog',
'91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed': 'The quick brown fox jumps over the lazy dog.'
};
describe('#sha512', function () {
Object.keys(cases).forEach(function (hash) {
it('should be equal', function (done) {
var worker = new Worker(WORKER);
worker.onmessage = function(event) {
expect(event.data).to.be(hash);
if (worker.terminate) {
worker.terminate();
}
done();
};
worker.postMessage(SOURCE);
worker.postMessage(cases[hash]);
});
});
});
})(Worker, WORKER, SOURCE);

@ -1,26 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SHA512</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/expect.js/index.js"></script>
<script src="../src/sha512.js"></script>
</head>
<body>
<div id="mocha"></div>
<script>
WORKER = 'worker.js';
SOURCE = '../src/sha512.js';
mocha.setup('bdd');
</script>
<script src="worker-test.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
<script>
</script>
</body>
</html>

@ -1,12 +0,0 @@
var imported = false;
onmessage = function(e) {
if (imported) {
postMessage(sha512(e.data));
if (typeof exports !== 'undefined') {
imported = false;
}
} else {
imported = true;
importScripts(e.data);
}
}
Loading…
Cancel
Save