1. Added AMD support.

2. Fixed ArrayBuffer dosen't work in Webpack.
pull/5/head v0.3.0
Chen, Yi-Cyuan 9 years ago
parent 99a8069715
commit 8f0ff971cd

@ -1 +1,2 @@
/node_modules/
/tests/

3
.gitignore vendored

@ -1 +1,2 @@
node_modules/
/node_modules/
/covreporter/

@ -1,12 +1,11 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
- "0.12.15"
- "4.5"
- "6.5.0"
before_install:
- npm install mocha -g
- npm install coveralls -g
- npm install mocha-lcov-reporter -g
- npm install coveralls
- npm install mocha-lcov-reporter
script: npm run-script coveralls
branches:
only:

@ -1,34 +1,47 @@
# v0.2.2 / 2015-02-09
* Improve performance.
# v0.2.1 / 2015-02-08
* Remove ascii parameter.
* Improve performance.
* Add test cases.
# v0.2.0 / 2015-02-02
* Add test cases.
* Improve performance.
# v0.1.3 / 2015-01-26
* Add test cases.
* Improve performance.
# v0.1.2 / 2015-01-07
* Add bower package.
* Fixed JSHint warnings.
* Add travis.
* Add coveralls.
# v0.1.1 / 2014-07-27
Fixed accents bug
# v0.1.0 / 2014-01-05
Initial release
# Change Log
## v0.3.0 / 2017-01-23
### Added
- AMD support.
### Fixed
- ArrayBuffer dosen't work in Webpack.
## v0.2.2 / 2015-02-09
### 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-2015 emn178@gmail.com
Copyright 2014-2017 Chen, Yi-Cyuan
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

@ -34,112 +34,46 @@ sha512_224('Message to hash');
```
If you use node.js, you should require the module first:
```JavaScript
sha512 = require('js-sha512');
var sha512 = require('js-sha512');
```
or
```JavaScript
sha512 = require('js-sha512').sha512;
sha384 = require('js-sha512').sha384;
sha512_256 = require('js-sha512').sha512_256;
sha512_224 = require('js-sha512').sha512_224;
var sha512 = require('js-sha512').sha512;
var sha384 = require('js-sha512').sha384;
var sha512_256 = require('js-sha512').sha512_256;
var sha512_224 = require('js-sha512').sha512_224;
```
## Example
Code
It supports AMD:
```JavaScript
sha512('');
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.');
require(['your/path/sha512.js'], function(sha512) {
// ...
});
```
Output
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6
91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed
38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1
ed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7
c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a
dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d
1546741840f8a492b959d9b8b2344b9b0eb51b004bba35c0aebaac86d45264c3
6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4
944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37
6d6a9279495ec4061769752e7ff9c68b6b0b3c5a281b7917ce0572de
It also supports UTF-8 encoding:
Code
```JavaScript
sha512('中文');
sha384('中文');
sha512_256('中文');
sha512_224('中文');
```
Output
8b88efc2ebbcbdad5ac2d65af05bec57bda25e71fd5fb25bbd892057a2755fbd05d8d8491cb2946febd5b0f124ffdfbaecf7e34946353c4f1b5ab29545895468
93422ceb8291a69b22f02dc1114c39a287493ad525dcebc77e4019a44eaee2633a85d0f29cd298ee6799048c33a4be0c
b6dab29c16ec35ab34a5d92ff135b58de96741dda78b1009a2181cf8b45d2f72
0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed188
## Benchmark
[UTF8](http://jsperf.com/sha-512/10)
[ASCII](http://jsperf.com/sha-512/9)
## Extensions
### jQuery
If you prefer jQuery style, you can add following code to add a jQuery extension.
Code
```JavaScript
jQuery.sha512 = sha512
jQuery.sha384 = sha384
jQuery.sha512_256 = sha512_256
jQuery.sha512_224 = sha512_224
```
And then you could use like this:
## Example
```JavaScript
$.sha512('message');
$.sha384('message');
$.sha512_256('message');
$.sha512_224('message');
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
```
### 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
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
## Contact
The project's website is located at https://github.com/emn178/js-sha512
Author: emn178@gmail.com
Author: Chen, Yi-Cyuan (emn178@gmail.com)

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

File diff suppressed because one or more lines are too long

@ -1,15 +1,19 @@
{
"name": "js-sha512",
"version": "0.2.2",
"version": "0.3.0",
"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",
"devDependencies": {
"expect.js": "~0.3.1",
"jscoverage": "~0.5.9"
"jscoverage": "~0.5.9",
"mocha": "~2.3.4",
"uglifyjs": "~2.4.10"
},
"scripts": {
"test": "mocha tests/node-test.js -r jscoverage",
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls"
"report": "mocha tests/node-test.js -r jscoverage --covout=html",
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls",
"build": "uglifyjs src/sha512.js --compress --mangle --comments --output build/sha512.min.js"
},
"repository": {
"type": "git",
@ -28,7 +32,7 @@
"HMAC"
],
"license": "MIT",
"author": "emn178 <emn178@gmail.com>",
"author": "Chen, Yi-Cyuan <emn178@gmail.com>",
"homepage": "https://github.com/emn178/js-sha512",
"bugs": {
"url": "https://github.com/emn178/js-sha512/issues"

@ -1,23 +1,27 @@
/*
* js-sha512 v0.2.2
* https://github.com/emn178/js-sha512
* [js-sha512]{@link https://github.com/emn178/js-sha512}
*
* Copyright 2014-2015, emn178@gmail.com
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
* @version 0.3.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
*/
;(function(root, undefined) {
/*jslint bitwise: true */
(function () {
'use strict';
var NODE_JS = typeof(module) != 'undefined';
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_SHA512_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_SHA512_NO_COMMON_JS && typeof module === 'object' && module.exports;
var AMD = typeof define === 'function' && define.amd;
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [-2147483648, 8388608, 32768, 128];
var SHIFT = [24, 16, 8, 0];
var K =[0x428A2F98, 0xD728AE22, 0x71374491, 0x23EF65CD,
var K =[
0x428A2F98, 0xD728AE22, 0x71374491, 0x23EF65CD,
0xB5C0FBCF, 0xEC4D3B2F, 0xE9B5DBA5, 0x8189DBBC,
0x3956C25B, 0xF348B538, 0x59F111F1, 0xB605D019,
0x923F82A4, 0xAF194F9B, 0xAB1C5ED5, 0xDA6D8118,
@ -56,7 +60,8 @@
0x28DB77F5, 0x23047D84, 0x32CAAB7B, 0x40C72493,
0x3C9EBE0A, 0x15C9BEBC, 0x431D67C4, 0x9C100D4C,
0x4CC5D4BE, 0xCB3E42B6, 0x597F299C, 0xFC657E2A,
0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817];
0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817
];
var blocks = [];
@ -564,16 +569,23 @@
return hex;
};
if(!root.JS_SHA512_TEST && NODE_JS) {
sha512.sha512 = sha512;
sha512.sha384 = sha384;
sha512.sha512_256 = sha512_256;
sha512.sha512_224 = sha512_224;
module.exports = sha512;
} else if(root) {
var exports = sha512;
exports.sha512 = sha512;
exports.sha384 = sha384;
exports.sha512_256 = sha512_256;
exports.sha512_224 = sha512_224;
if (COMMON_JS) {
module.exports = exports;
} else {
root.sha512 = sha512;
root.sha384 = sha384;
root.sha512_256 = sha512_256;
root.sha512_224 = sha512_224;
if (AMD) {
define(function () {
return exports;
});
}
}
}(this));
})();

@ -1,17 +1,59 @@
// Node.js env
expect = require('expect.js');
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;
require('./test.js');
delete require.cache[require.resolve('../src/sha512.js')];
delete require.cache[require.resolve('./test.js')];
sha512 = null;
sha384 = null;
sha512_256 = null;
sha512_224 = null;
// Webpack browser env
JS_SHA512_NO_NODE_JS = true;
window = global;
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');
require('./test.js');
delete require.cache[require.resolve('../src/sha512.js')]
delete require.cache[require.resolve('./test.js')]
delete require.cache[require.resolve('../src/sha512.js')];
delete require.cache[require.resolve('./test.js')];
sha512 = null;
sha384 = null;
sha512_256 = null;
sha512_224 = null;
JS_SHA512_TEST = true;
// browser env
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
window = global;
require('../src/sha512.js');
require('./test.js');
delete require.cache[require.resolve('../src/sha512.js')];
delete require.cache[require.resolve('./test.js')];
sha512 = null;
sha384 = null;
sha512_256 = null;
sha512_224 = null;
// browser AMD
JS_SHA512_NO_NODE_JS = true;
JS_SHA512_NO_COMMON_JS = true;
window = global;
define = function (func) {
sha512 = func();
sha384 = sha512.sha384;
sha512_256 = sha512.sha512_256;
sha512_224 = sha512.sha512_224;
require('./test.js');
};
define.amd = true;
require('../src/sha512.js');

Loading…
Cancel
Save