mirror of
https://github.com/emn178/js-sha3.git
synced 2026-08-12 19:41:36 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09db28deed | ||
|
|
ca56f2ac21 | ||
|
|
99d724b22a | ||
|
|
63a860bdf9 | ||
|
|
7423f9ef37 | ||
|
|
61300d2d34 | ||
|
|
0d1753fd8d | ||
|
|
7851f7ad68 | ||
|
|
db3ab779a8 | ||
|
|
372541684a | ||
|
|
1fa1812d86 |
+2
-1
@@ -1 +1,2 @@
|
||||
/test/
|
||||
/tests/
|
||||
node_modules/
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
node_modules/
|
||||
covreporter
|
||||
my_test
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
my_test
|
||||
covreporter
|
||||
build
|
||||
tests
|
||||
+3
-4
@@ -1,12 +1,11 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "0.11"
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
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,3 +1,30 @@
|
||||
# v0.5.0 / 2015-09-23
|
||||
|
||||
* Support update interface.
|
||||
|
||||
# v0.4.1 / 2015-09-18
|
||||
|
||||
* Support to output Integer Array.
|
||||
* Fixed shake output incorrect when it's greater than 1088.
|
||||
|
||||
# v0.4.0 / 2015-09-17
|
||||
|
||||
* Support to output ArrayBuffer.
|
||||
* Add shake alogirthms.
|
||||
|
||||
# v0.3.1 / 2015-05-22
|
||||
|
||||
* Fixed bugs.
|
||||
|
||||
# v0.3.0 / 2015-05-21
|
||||
|
||||
* Support byte array and ArrayBuffer input.
|
||||
|
||||
# v0.2.0 / 2015-04-04
|
||||
|
||||
* Implement NIST's May 2014 SHA-3 version.
|
||||
* Rename original methods to keccak.
|
||||
|
||||
# v0.1.2 / 2015-02-27
|
||||
|
||||
* Improve performance.
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
Copyright 2015 emn178@gmail.com
|
||||
Copyright (c) 2015 Chen Yi-Cyuan
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
# js-sha3
|
||||
[](https://travis-ci.org/emn178/js-sha3)
|
||||
[](https://coveralls.io/r/emn178/js-sha3?branch=master)
|
||||
[](https://nodei.co/npm/js-sha3/)
|
||||
A simple SHA-3 / Keccak hash function for JavaScript supports UTF-8 encoding.
|
||||
A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.
|
||||
|
||||
## Notice
|
||||
Sha3 methods has been renamed to keccak since v0.2.0. It means that sha3 methods of v0.1.x are equal to keccak methods of v0.2.x and later.
|
||||
|
||||
## Demo
|
||||
[SHA3-512 Online](http://emn178.github.io/online-tools/sha3_512.html)
|
||||
[SHA3-384 Online](http://emn178.github.io/online-tools/sha3_384.html)
|
||||
[SHA3-256 Online](http://emn178.github.io/online-tools/sha3_256.html)
|
||||
[SHA3-224 Online](http://emn178.github.io/online-tools/sha3_224.html)
|
||||
[Keccak-512 Online](http://emn178.github.io/online-tools/keccak_512.html)
|
||||
[Keccak-384 Online](http://emn178.github.io/online-tools/keccak_384.html)
|
||||
[Keccak-256 Online](http://emn178.github.io/online-tools/keccak_256.html)
|
||||
[Keccak-224 Online](http://emn178.github.io/online-tools/keccak_224.html)
|
||||
|
||||
## Download
|
||||
[Compress](https://raw.github.com/emn178/js-sha3/master/build/sha3.min.js)
|
||||
@@ -30,6 +36,35 @@ sha3_512('Message to hash');
|
||||
sha3_384('Message to hash');
|
||||
sha3_256('Message to hash');
|
||||
sha3_224('Message to hash');
|
||||
keccak_512('Message to hash');
|
||||
keccak_384('Message to hash');
|
||||
keccak_256('Message to hash');
|
||||
keccak_224('Message to hash');
|
||||
shake_128('Message to hash', 256);
|
||||
shake_256('Message to hash', 512);
|
||||
|
||||
// Support ArrayBuffer output
|
||||
var buffer = keccak_224.buffer('Message to hash');
|
||||
|
||||
// Support Array output
|
||||
var buffer = keccak_224.array('Message to hash');
|
||||
|
||||
// update hash
|
||||
sha3_512.update('Message ').update('to ').update('hash').hex();
|
||||
// specify shake output bits at first update
|
||||
shake_128.update('Message ', 256).update('to ').update('hash').hex();
|
||||
|
||||
// or to use create
|
||||
var hash = sha3_512.create();
|
||||
hash.update('...');
|
||||
hash.update('...');
|
||||
hash.hex();
|
||||
|
||||
// specify shake output bits when creating
|
||||
var hash = shake_128.create(256);
|
||||
hash.update('...');
|
||||
hash.update('...');
|
||||
hash.hex();
|
||||
```
|
||||
If you use node.js, you should require the module first:
|
||||
```JavaScript
|
||||
@@ -37,58 +72,140 @@ sha3_512 = require('js-sha3').sha3_512;
|
||||
sha3_384 = require('js-sha3').sha3_384;
|
||||
sha3_256 = require('js-sha3').sha3_256;
|
||||
sha3_224 = require('js-sha3').sha3_224;
|
||||
keccak_512 = require('js-sha3').keccak_512;
|
||||
keccak_384 = require('js-sha3').keccak_384;
|
||||
keccak_256 = require('js-sha3').keccak_256;
|
||||
keccak_224 = require('js-sha3').keccak_224;
|
||||
shake_128 = require('js-sha3').shake_128;
|
||||
shake_256 = require('js-sha3').shake_256;
|
||||
```
|
||||
|
||||
## Example
|
||||
Code
|
||||
```JavaScript
|
||||
sha3_512('');
|
||||
// a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26
|
||||
|
||||
sha3_512('The quick brown fox jumps over the lazy dog');
|
||||
// 01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450
|
||||
|
||||
sha3_512('The quick brown fox jumps over the lazy dog.');
|
||||
// 18f4f4bd419603f95538837003d9d254c26c23765565162247483f65c50303597bc9ce4d289f21d1c2f1f458828e33dc442100331b35e7eb031b5d38ba6460f8
|
||||
|
||||
sha3_384('');
|
||||
// 0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004
|
||||
|
||||
sha3_384('The quick brown fox jumps over the lazy dog');
|
||||
// 7063465e08a93bce31cd89d2e3ca8f602498696e253592ed26f07bf7e703cf328581e1471a7ba7ab119b1a9ebdf8be41
|
||||
|
||||
sha3_384('The quick brown fox jumps over the lazy dog.');
|
||||
// 1a34d81695b622df178bc74df7124fe12fac0f64ba5250b78b99c1273d4b080168e10652894ecad5f1f4d5b965437fb9
|
||||
|
||||
sha3_256('');
|
||||
// a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a
|
||||
|
||||
sha3_256('The quick brown fox jumps over the lazy dog');
|
||||
// 69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04
|
||||
|
||||
sha3_256('The quick brown fox jumps over the lazy dog.');
|
||||
// a80f839cd4f83f6c3dafc87feae470045e4eb0d366397d5c6ce34ba1739f734d
|
||||
|
||||
sha3_224('');
|
||||
// 6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7
|
||||
|
||||
sha3_224('The quick brown fox jumps over the lazy dog');
|
||||
// d15dadceaa4d5d7bb3b48f446421d542e08ad8887305e28d58335795
|
||||
|
||||
sha3_224('The quick brown fox jumps over the lazy dog.');
|
||||
// 2d0708903833afabdd232a20201176e8b58c5be8a6fe74265ac54db0
|
||||
|
||||
keccak_512('');
|
||||
// 0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e
|
||||
|
||||
keccak_512('The quick brown fox jumps over the lazy dog');
|
||||
// d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609
|
||||
|
||||
keccak_512('The quick brown fox jumps over the lazy dog.');
|
||||
// ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760
|
||||
|
||||
keccak_384('');
|
||||
// 2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff
|
||||
|
||||
keccak_384('The quick brown fox jumps over the lazy dog');
|
||||
// 283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3
|
||||
|
||||
keccak_384('The quick brown fox jumps over the lazy dog.');
|
||||
// 9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b
|
||||
|
||||
keccak_256('');
|
||||
// c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
|
||||
|
||||
keccak_256('The quick brown fox jumps over the lazy dog');
|
||||
// 4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15
|
||||
|
||||
keccak_256('The quick brown fox jumps over the lazy dog.');
|
||||
// 578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d
|
||||
|
||||
keccak_224('');
|
||||
// f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd
|
||||
|
||||
keccak_224('The quick brown fox jumps over the lazy dog');
|
||||
// 310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe
|
||||
|
||||
keccak_224('The quick brown fox jumps over the lazy dog.');
|
||||
// c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab
|
||||
|
||||
shake_128('', 256);
|
||||
// 7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26
|
||||
|
||||
shake_256('', 512);
|
||||
// 46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be
|
||||
```
|
||||
Output
|
||||
|
||||
0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e
|
||||
d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609
|
||||
ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760
|
||||
2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff
|
||||
283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3
|
||||
9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b
|
||||
c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
|
||||
4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15
|
||||
578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d
|
||||
f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd
|
||||
310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe
|
||||
c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab
|
||||
|
||||
It also supports UTF-8 encoding:
|
||||
|
||||
Code
|
||||
```JavaScript
|
||||
sha3_512('中文');
|
||||
sha3_384('中文');
|
||||
sha3_256('中文');
|
||||
sha3_224('中文');
|
||||
```
|
||||
Output
|
||||
// 059bbe2efc50cc30e4d8ec5a96be697e2108fcbf9193e1296192eddabc13b143c0120d059399a13d0d42651efe23a6c1ce2d1efb576c5b207fa2516050505af7
|
||||
|
||||
2f6a1bd50562230229af34b0ccf46b8754b89d23ae2c5bf7840b4acfcef86f87395edc0a00b2bfef53bafebe3b79de2e3e01cbd8169ddbb08bde888dcc893524
|
||||
743f64bb7544c6ed923be4741b738dde18b7cee384a3a09c4e01acaaac9f19222cdee137702bd3aa05dc198373d87d6c
|
||||
70a2b6579047f0a977fcb5e9120a4e07067bea9abb6916fbc2d13ffb9a4e4eee
|
||||
f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd
|
||||
sha3_384('中文');
|
||||
// 9fb5b99e3c546f2738dcd50a14e9aef9c313800c1bf8cf76bc9b2c3a23307841364c5a2d0794702662c5796fb72f5432
|
||||
|
||||
sha3_256('中文');
|
||||
// ac5305da3d18be1aed44aa7c70ea548da243a59a5fd546f489348fd5718fb1a0
|
||||
|
||||
sha3_224('中文');
|
||||
// 106d169e10b61c2a2a05554d3e631ec94467f8316640f29545d163ee
|
||||
|
||||
keccak_512('中文');
|
||||
// 2f6a1bd50562230229af34b0ccf46b8754b89d23ae2c5bf7840b4acfcef86f87395edc0a00b2bfef53bafebe3b79de2e3e01cbd8169ddbb08bde888dcc893524
|
||||
|
||||
keccak_384('中文');
|
||||
// 743f64bb7544c6ed923be4741b738dde18b7cee384a3a09c4e01acaaac9f19222cdee137702bd3aa05dc198373d87d6c
|
||||
|
||||
keccak_256('中文');
|
||||
// 70a2b6579047f0a977fcb5e9120a4e07067bea9abb6916fbc2d13ffb9a4e4eee
|
||||
|
||||
keccak_224('中文');
|
||||
// f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd
|
||||
```
|
||||
|
||||
It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input:
|
||||
|
||||
Code
|
||||
```JavaScript
|
||||
sha3_512([]);
|
||||
// a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26
|
||||
|
||||
sha3_512(new Uint8Array([]));
|
||||
// a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
## Benchmark
|
||||
[UTF8](http://jsperf.com/sha3/3)
|
||||
[ASCII](http://jsperf.com/sha3/2)
|
||||
[UTF8](http://jsperf.com/sha3/5)
|
||||
[ASCII](http://jsperf.com/sha3/4)
|
||||
|
||||
## Extensions
|
||||
### jQuery
|
||||
@@ -100,6 +217,10 @@ jQuery.sha3_512 = sha3_512;
|
||||
jQuery.sha3_384 = sha3_384;
|
||||
jQuery.sha3_256 = sha3_256;
|
||||
jQuery.sha3_224 = sha3_224;
|
||||
jQuery.keccak_512 = keccak_512;
|
||||
jQuery.keccak_384 = keccak_384;
|
||||
jQuery.keccak_256 = keccak_256;
|
||||
jQuery.keccak_224 = keccak_224;
|
||||
```
|
||||
And then you could use like this:
|
||||
```JavaScript
|
||||
@@ -107,6 +228,10 @@ $.sha3_512('message');
|
||||
$.sha3_384('message');
|
||||
$.sha3_256('message');
|
||||
$.sha3_224('message');
|
||||
$.keccak_512('message');
|
||||
$.keccak_384('message');
|
||||
$.keccak_256('message');
|
||||
$.keccak_224('message');
|
||||
```
|
||||
### Prototype
|
||||
If you prefer prototype style, you can add following code to add a prototype extension.
|
||||
@@ -125,6 +250,18 @@ String.prototype.sha3_256 = function() {
|
||||
String.prototype.sha3_224 = function() {
|
||||
return sha3_224(this);
|
||||
};
|
||||
String.prototype.keccak_512 = function() {
|
||||
return keccak_512(this);
|
||||
};
|
||||
String.prototype.keccak_384 = function() {
|
||||
return keccak_384(this);
|
||||
};
|
||||
String.prototype.keccak_256 = function() {
|
||||
return keccak_256(this);
|
||||
};
|
||||
String.prototype.keccak_224 = function() {
|
||||
return keccak_224(this);
|
||||
};
|
||||
```
|
||||
And then you could use like this:
|
||||
```JavaScript
|
||||
@@ -132,6 +269,10 @@ And then you could use like this:
|
||||
'message'.sha3_384();
|
||||
'message'.sha3_256();
|
||||
'message'.sha3_224();
|
||||
'message'.keccak_512();
|
||||
'message'.keccak_384();
|
||||
'message'.keccak_256();
|
||||
'message'.keccak_224();
|
||||
```
|
||||
## License
|
||||
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "js-sha3",
|
||||
"version": "0.1.2",
|
||||
"main": ["build/sha3.min.js"],
|
||||
"version": "0.4.1",
|
||||
"main": ["src/sha3.js"],
|
||||
"ignore": [
|
||||
"samples",
|
||||
"test"
|
||||
"tests"
|
||||
]
|
||||
}
|
||||
|
||||
Vendored
+15
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* js-sha3 v0.1.2
|
||||
* js-sha3 v0.5.0
|
||||
* https://github.com/emn178/js-sha3
|
||||
*
|
||||
* Copyright 2015, emn178@gmail.com
|
||||
@@ -7,16 +7,17 @@
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/MIT
|
||||
*/
|
||||
(function(u,ua){var E="undefined"!=typeof module;E&&(u=global,u.JS_SHA3_TEST&&(u.navigator={userAgent:"Chrome"}));var va=(u.JS_SHA3_TEST||!E)&&-1!=navigator.userAgent.indexOf("Chrome"),b="0123456789abcdef".split(""),wa=[1,256,65536,16777216],B=[0,8,16,24],qa=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,
|
||||
32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],e=[],a=[],ra=function(a){return A(a,224)},sa=function(a){return A(a,256)},ta=function(a){return A(a,384)},A=function(u,C){C===ua&&(C=512);var A,f,v=!1,D=0,E=0,oa=u.length,c,d,g,h,k,l,m,n,p,q,r,t,w,x,y,z,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ba,ca,da,ea,fa,ga,ha,ia,ja,ka,la,ma,na,F=(1600-2*C)/32,pa=4*F;for(c=0;50>c;++c)a[c]=0;A=0;do{e[0]=A;for(c=1;c<F+1;++c)e[c]=0;for(c=E;D<oa&&c<pa;++D)f=
|
||||
u.charCodeAt(D),128>f?e[c>>2]|=f<<B[c++&3]:(2048>f?e[c>>2]|=(192|f>>6)<<B[c++&3]:(55296>f||57344<=f?e[c>>2]|=(224|f>>12)<<B[c++&3]:(f=65536+((f&1023)<<10|u.charCodeAt(++D)&1023),e[c>>2]|=(240|f>>18)<<B[c++&3],e[c>>2]|=(128|f>>12&63)<<B[c++&3]),e[c>>2]|=(128|f>>6&63)<<B[c++&3]),e[c>>2]|=(128|f&63)<<B[c++&3]);E=c-pa;D==oa&&(e[c>>2]|=wa[c&3],++D);A=e[F];D>oa&&c<pa&&(e[F-1]|=2147483648,v=!0);for(c=0;c<F;++c)a[c]^=e[c];for(f=0;48>f;f+=2)g=a[0]^a[10]^a[20]^a[30]^a[40],h=a[1]^a[11]^a[21]^a[31]^a[41],k=a[2]^
|
||||
a[12]^a[22]^a[32]^a[42],l=a[3]^a[13]^a[23]^a[33]^a[43],m=a[4]^a[14]^a[24]^a[34]^a[44],n=a[5]^a[15]^a[25]^a[35]^a[45],p=a[6]^a[16]^a[26]^a[36]^a[46],q=a[7]^a[17]^a[27]^a[37]^a[47],r=a[8]^a[18]^a[28]^a[38]^a[48],t=a[9]^a[19]^a[29]^a[39]^a[49],d=r^(k<<1|l>>>31),c=t^(l<<1|k>>>31),a[0]^=d,a[1]^=c,a[10]^=d,a[11]^=c,a[20]^=d,a[21]^=c,a[30]^=d,a[31]^=c,a[40]^=d,a[41]^=c,d=g^(m<<1|n>>>31),c=h^(n<<1|m>>>31),a[2]^=d,a[3]^=c,a[12]^=d,a[13]^=c,a[22]^=d,a[23]^=c,a[32]^=d,a[33]^=c,a[42]^=d,a[43]^=c,d=k^(p<<1|q>>>
|
||||
31),c=l^(q<<1|p>>>31),a[4]^=d,a[5]^=c,a[14]^=d,a[15]^=c,a[24]^=d,a[25]^=c,a[34]^=d,a[35]^=c,a[44]^=d,a[45]^=c,d=m^(r<<1|t>>>31),c=n^(t<<1|r>>>31),a[6]^=d,a[7]^=c,a[16]^=d,a[17]^=c,a[26]^=d,a[27]^=c,a[36]^=d,a[37]^=c,a[46]^=d,a[47]^=c,d=p^(g<<1|h>>>31),c=q^(h<<1|g>>>31),a[8]^=d,a[9]^=c,a[18]^=d,a[19]^=c,a[28]^=d,a[29]^=c,a[38]^=d,a[39]^=c,a[48]^=d,a[49]^=c,d=a[0],c=a[1],W=a[11]<<4|a[10]>>>28,X=a[10]<<4|a[11]>>>28,y=a[20]<<3|a[21]>>>29,z=a[21]<<3|a[20]>>>29,ka=a[31]<<9|a[30]>>>23,la=a[30]<<9|a[31]>>>
|
||||
23,S=a[40]<<18|a[41]>>>14,T=a[41]<<18|a[40]>>>14,K=a[2]<<1|a[3]>>>31,L=a[3]<<1|a[2]>>>31,g=a[13]<<12|a[12]>>>20,h=a[12]<<12|a[13]>>>20,Y=a[22]<<10|a[23]>>>22,Z=a[23]<<10|a[22]>>>22,G=a[33]<<13|a[32]>>>19,H=a[32]<<13|a[33]>>>19,ma=a[42]<<2|a[43]>>>30,na=a[43]<<2|a[42]>>>30,ea=a[5]<<30|a[4]>>>2,fa=a[4]<<30|a[5]>>>2,M=a[14]<<6|a[15]>>>26,N=a[15]<<6|a[14]>>>26,k=a[25]<<11|a[24]>>>21,l=a[24]<<11|a[25]>>>21,aa=a[34]<<15|a[35]>>>17,ba=a[35]<<15|a[34]>>>17,I=a[45]<<29|a[44]>>>3,J=a[44]<<29|a[45]>>>3,r=a[6]<<
|
||||
28|a[7]>>>4,t=a[7]<<28|a[6]>>>4,ga=a[17]<<23|a[16]>>>9,ha=a[16]<<23|a[17]>>>9,O=a[26]<<25|a[27]>>>7,P=a[27]<<25|a[26]>>>7,m=a[36]<<21|a[37]>>>11,n=a[37]<<21|a[36]>>>11,ca=a[47]<<24|a[46]>>>8,da=a[46]<<24|a[47]>>>8,U=a[8]<<27|a[9]>>>5,V=a[9]<<27|a[8]>>>5,w=a[18]<<20|a[19]>>>12,x=a[19]<<20|a[18]>>>12,ia=a[29]<<7|a[28]>>>25,ja=a[28]<<7|a[29]>>>25,Q=a[38]<<8|a[39]>>>24,R=a[39]<<8|a[38]>>>24,p=a[48]<<14|a[49]>>>18,q=a[49]<<14|a[48]>>>18,a[0]=d^~g&k,a[1]=c^~h&l,a[10]=r^~w&y,a[11]=t^~x&z,a[20]=K^~M&O,a[21]=
|
||||
L^~N&P,a[30]=U^~W&Y,a[31]=V^~X&Z,a[40]=ea^~ga&ia,a[41]=fa^~ha&ja,a[2]=g^~k&m,a[3]=h^~l&n,a[12]=w^~y&G,a[13]=x^~z&H,a[22]=M^~O&Q,a[23]=N^~P&R,a[32]=W^~Y&aa,a[33]=X^~Z&ba,a[42]=ga^~ia&ka,a[43]=ha^~ja&la,a[4]=k^~m&p,a[5]=l^~n&q,a[14]=y^~G&I,a[15]=z^~H&J,a[24]=O^~Q&S,a[25]=P^~R&T,a[34]=Y^~aa&ca,a[35]=Z^~ba&da,a[44]=ia^~ka&ma,a[45]=ja^~la&na,a[6]=m^~p&d,a[7]=n^~q&c,a[16]=G^~I&r,a[17]=H^~J&t,a[26]=Q^~S&K,a[27]=R^~T&L,a[36]=aa^~ca&U,a[37]=ba^~da&V,a[46]=ka^~ma&ea,a[47]=la^~na&fa,a[8]=p^~d&g,a[9]=q^~c&h,
|
||||
a[18]=I^~r&w,a[19]=J^~t&x,a[28]=S^~K&M,a[29]=T^~L&N,a[38]=ca^~U&W,a[39]=da^~V&X,a[48]=ma^~ea&ga,a[49]=na^~fa&ha,a[0]^=qa[f],a[1]^=qa[f+1]}while(!v);v="";if(va)d=a[0],c=a[1],g=a[2],h=a[3],k=a[4],l=a[5],m=a[6],n=a[7],p=a[8],q=a[9],r=a[10],t=a[11],w=a[12],x=a[13],y=a[14],z=a[15],v+=b[d>>4&15]+b[d&15]+b[d>>12&15]+b[d>>8&15]+b[d>>20&15]+b[d>>16&15]+b[d>>28&15]+b[d>>24&15]+b[c>>4&15]+b[c&15]+b[c>>12&15]+b[c>>8&15]+b[c>>20&15]+b[c>>16&15]+b[c>>28&15]+b[c>>24&15]+b[g>>4&15]+b[g&15]+b[g>>12&15]+b[g>>8&15]+
|
||||
b[g>>20&15]+b[g>>16&15]+b[g>>28&15]+b[g>>24&15]+b[h>>4&15]+b[h&15]+b[h>>12&15]+b[h>>8&15]+b[h>>20&15]+b[h>>16&15]+b[h>>28&15]+b[h>>24&15]+b[k>>4&15]+b[k&15]+b[k>>12&15]+b[k>>8&15]+b[k>>20&15]+b[k>>16&15]+b[k>>28&15]+b[k>>24&15]+b[l>>4&15]+b[l&15]+b[l>>12&15]+b[l>>8&15]+b[l>>20&15]+b[l>>16&15]+b[l>>28&15]+b[l>>24&15]+b[m>>4&15]+b[m&15]+b[m>>12&15]+b[m>>8&15]+b[m>>20&15]+b[m>>16&15]+b[m>>28&15]+b[m>>24&15],256<=C&&(v+=b[n>>4&15]+b[n&15]+b[n>>12&15]+b[n>>8&15]+b[n>>20&15]+b[n>>16&15]+b[n>>28&15]+b[n>>
|
||||
24&15]),384<=C&&(v+=b[p>>4&15]+b[p&15]+b[p>>12&15]+b[p>>8&15]+b[p>>20&15]+b[p>>16&15]+b[p>>28&15]+b[p>>24&15]+b[q>>4&15]+b[q&15]+b[q>>12&15]+b[q>>8&15]+b[q>>20&15]+b[q>>16&15]+b[q>>28&15]+b[q>>24&15]+b[r>>4&15]+b[r&15]+b[r>>12&15]+b[r>>8&15]+b[r>>20&15]+b[r>>16&15]+b[r>>28&15]+b[r>>24&15]+b[t>>4&15]+b[t&15]+b[t>>12&15]+b[t>>8&15]+b[t>>20&15]+b[t>>16&15]+b[t>>28&15]+b[t>>24&15]),512==C&&(v+=b[w>>4&15]+b[w&15]+b[w>>12&15]+b[w>>8&15]+b[w>>20&15]+b[w>>16&15]+b[w>>28&15]+b[w>>24&15]+b[x>>4&15]+b[x&15]+
|
||||
b[x>>12&15]+b[x>>8&15]+b[x>>20&15]+b[x>>16&15]+b[x>>28&15]+b[x>>24&15]+b[y>>4&15]+b[y&15]+b[y>>12&15]+b[y>>8&15]+b[y>>20&15]+b[y>>16&15]+b[y>>28&15]+b[y>>24&15]+b[z>>4&15]+b[z&15]+b[z>>12&15]+b[z>>8&15]+b[z>>20&15]+b[z>>16&15]+b[z>>28&15]+b[z>>24&15]);else for(c=0,f=C/32;c<f;++c)d=a[c],v+=b[d>>4&15]+b[d&15]+b[d>>12&15]+b[d>>8&15]+b[d>>20&15]+b[d>>16&15]+b[d>>28&15]+b[d>>24&15];return v};!u.JS_SHA3_TEST&&E?module.exports={sha3_512:A,sha3_384:ta,sha3_256:sa,sha3_224:ra}:u&&(u.sha3_512=A,u.sha3_384=
|
||||
ta,u.sha3_256=sa,u.sha3_224=ra)})(this);
|
||||
(function(r,la){function n(a,b,c){this.blocks=[];this.s=[];this.padding=b;this.outputBits=c;this.reset=!0;this.start=this.block=0;this.blockCount=1600-(a<<1)>>5;this.byteCount=this.blockCount<<2;this.outputBlocks=c>>5;this.extraBytes=(c&31)>>3;for(t=0;50>t;++t)this.s[t]=0}var fa="undefined"!=typeof module;fa&&(r=global,r.JS_SHA3_TEST&&(r.navigator={userAgent:"Chrome"}));for(var l="0123456789abcdef".split(""),p=[0,8,16,24],ga=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,
|
||||
2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],u=[224,256,384,512],x=["hex","buffer","array"],ha=function(a,b,c){return function(e){return(new n(a,b,a)).update(e)[c]()}},ia=function(a,b,c){return function(e,g){return(new n(a,b,g)).update(e)[c]()}},q=function(a,b){var c=ha(a,
|
||||
b,"hex");c.create=function(){return new n(a,b,a)};c.update=function(a){return c.create().update(a)};for(var e=0;e<x.length;++e){var g=x[e];c[g]=ha(a,b,g)}return c},u=[{name:"keccak",padding:[1,256,65536,16777216],bits:u,createMethod:q},{name:"sha3",padding:[6,1536,393216,100663296],bits:u,createMethod:q},{name:"shake",padding:[31,7936,2031616,520093696],bits:[128,256],createMethod:function(a,b){var c=ia(a,b,"hex");c.create=function(c){return new n(a,b,c)};c.update=function(a,b){return c.create(b).update(a)};
|
||||
for(var e=0;e<x.length;++e){var g=x[e];c[g]=ia(a,b,g)}return c}}],y={},t=0;t<u.length;++t)for(var v=u[t],ea=v.bits,q=v.createMethod,q=0;q<ea.length;++q){var ka=v.createMethod(ea[q],v.padding);y[v.name+"_"+ea[q]]=ka}n.prototype.update=function(a){var b="string"!=typeof a;b&&a.constructor==r.ArrayBuffer&&(a=new Uint8Array(a));for(var c=a.length,e=this.blocks,g=this.byteCount,k=this.blockCount,h=0,f=this.s,d,m;h<c;){if(this.reset)for(this.reset=!1,e[0]=this.block,d=1;d<k+1;++d)e[d]=0;if(b)for(d=this.start;h<
|
||||
c&&d<g;++h)e[d>>2]|=a[h]<<p[d++&3];else for(d=this.start;h<c&&d<g;++h)m=a.charCodeAt(h),128>m?e[d>>2]|=m<<p[d++&3]:(2048>m?e[d>>2]|=(192|m>>6)<<p[d++&3]:(55296>m||57344<=m?e[d>>2]|=(224|m>>12)<<p[d++&3]:(m=65536+((m&1023)<<10|a.charCodeAt(++h)&1023),e[d>>2]|=(240|m>>18)<<p[d++&3],e[d>>2]|=(128|m>>12&63)<<p[d++&3]),e[d>>2]|=(128|m>>6&63)<<p[d++&3]),e[d>>2]|=(128|m&63)<<p[d++&3]);this.lastByteIndex=d;if(d>=g){this.start=d-g;this.block=e[k];for(d=0;d<k;++d)f[d]^=e[d];w(f);this.reset=!0}else this.start=
|
||||
d}return this};n.prototype.finalize=function(){var a=this.blocks,b=this.lastByteIndex,c=this.blockCount,e=this.s;a[b>>2]|=this.padding[b&3];if(this.lastByteIndex==this.byteCount)for(a[0]=a[c],b=1;b<c+1;++b)a[b]=0;a[c-1]|=2147483648;for(b=0;b<c;++b)e[b]^=a[b];w(e)};n.prototype.toString=n.prototype.hex=function(){this.finalize();for(var a=this.blockCount,b=this.s,c=this.outputBlocks,e=this.extraBytes,g=0,k=0,h="",f;k<c;){for(g=0;g<a&&k<c;++g,++k)f=b[g],h+=l[f>>4&15]+l[f&15]+l[f>>12&15]+l[f>>8&15]+l[f>>
|
||||
20&15]+l[f>>16&15]+l[f>>28&15]+l[f>>24&15];0==k%a&&w(b)}e&&(f=b[g],0<e&&(h+=l[f>>4&15]+l[f&15]),1<e&&(h+=l[f>>12&15]+l[f>>8&15]),2<e&&(h+=l[f>>20&15]+l[f>>16&15]));return h};n.prototype.buffer=function(){this.finalize();var a=this.blockCount,b=this.s,c=this.outputBlocks,e=this.extraBytes,g=0,k=0,h=this.outputBits>>3,f;f=e?new ArrayBuffer(c+1<<2):new ArrayBuffer(h);for(var d=new Uint32Array(f);k<c;){for(g=0;g<a&&k<c;++g,++k)d[k]=b[g];0==k%a&&w(b)}e&&(d[g]=b[g],f=f.slice(0,h));return f};n.prototype.digest=
|
||||
n.prototype.array=function(){this.finalize();for(var a=this.blockCount,b=this.s,c=this.outputBlocks,e=this.extraBytes,g=0,k=0,h=[],f,d;k<c;){for(g=0;g<a&&k<c;++g,++k)f=k<<2,d=b[g],h[f]=d&255,h[f+1]=d>>8&255,h[f+2]=d>>16&255,h[f+3]=d>>24&255;0==k%a&&w(b)}e&&(f=k<<2,d=b[g],0<e&&(h[f]=d&255),1<e&&(h[f+1]=d>>8&255),2<e&&(h[f+2]=d>>16&255));return h};var w=function(a){var b,c,e,g,k,h,f,d,m,l,n,p,q,r,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ba,ca,da;for(e=0;48>e;e+=2)g=a[0]^
|
||||
a[10]^a[20]^a[30]^a[40],k=a[1]^a[11]^a[21]^a[31]^a[41],h=a[2]^a[12]^a[22]^a[32]^a[42],f=a[3]^a[13]^a[23]^a[33]^a[43],d=a[4]^a[14]^a[24]^a[34]^a[44],m=a[5]^a[15]^a[25]^a[35]^a[45],l=a[6]^a[16]^a[26]^a[36]^a[46],n=a[7]^a[17]^a[27]^a[37]^a[47],p=a[8]^a[18]^a[28]^a[38]^a[48],q=a[9]^a[19]^a[29]^a[39]^a[49],b=p^(h<<1|f>>>31),c=q^(f<<1|h>>>31),a[0]^=b,a[1]^=c,a[10]^=b,a[11]^=c,a[20]^=b,a[21]^=c,a[30]^=b,a[31]^=c,a[40]^=b,a[41]^=c,b=g^(d<<1|m>>>31),c=k^(m<<1|d>>>31),a[2]^=b,a[3]^=c,a[12]^=b,a[13]^=c,a[22]^=
|
||||
b,a[23]^=c,a[32]^=b,a[33]^=c,a[42]^=b,a[43]^=c,b=h^(l<<1|n>>>31),c=f^(n<<1|l>>>31),a[4]^=b,a[5]^=c,a[14]^=b,a[15]^=c,a[24]^=b,a[25]^=c,a[34]^=b,a[35]^=c,a[44]^=b,a[45]^=c,b=d^(p<<1|q>>>31),c=m^(q<<1|p>>>31),a[6]^=b,a[7]^=c,a[16]^=b,a[17]^=c,a[26]^=b,a[27]^=c,a[36]^=b,a[37]^=c,a[46]^=b,a[47]^=c,b=l^(g<<1|k>>>31),c=n^(k<<1|g>>>31),a[8]^=b,a[9]^=c,a[18]^=b,a[19]^=c,a[28]^=b,a[29]^=c,a[38]^=b,a[39]^=c,a[48]^=b,a[49]^=c,b=a[0],c=a[1],M=a[11]<<4|a[10]>>>28,N=a[10]<<4|a[11]>>>28,u=a[20]<<3|a[21]>>>29,v=
|
||||
a[21]<<3|a[20]>>>29,aa=a[31]<<9|a[30]>>>23,ba=a[30]<<9|a[31]>>>23,I=a[40]<<18|a[41]>>>14,J=a[41]<<18|a[40]>>>14,A=a[2]<<1|a[3]>>>31,B=a[3]<<1|a[2]>>>31,g=a[13]<<12|a[12]>>>20,k=a[12]<<12|a[13]>>>20,O=a[22]<<10|a[23]>>>22,P=a[23]<<10|a[22]>>>22,w=a[33]<<13|a[32]>>>19,x=a[32]<<13|a[33]>>>19,ca=a[42]<<2|a[43]>>>30,da=a[43]<<2|a[42]>>>30,U=a[5]<<30|a[4]>>>2,V=a[4]<<30|a[5]>>>2,C=a[14]<<6|a[15]>>>26,D=a[15]<<6|a[14]>>>26,h=a[25]<<11|a[24]>>>21,f=a[24]<<11|a[25]>>>21,Q=a[34]<<15|a[35]>>>17,R=a[35]<<15|
|
||||
a[34]>>>17,y=a[45]<<29|a[44]>>>3,z=a[44]<<29|a[45]>>>3,p=a[6]<<28|a[7]>>>4,q=a[7]<<28|a[6]>>>4,W=a[17]<<23|a[16]>>>9,X=a[16]<<23|a[17]>>>9,E=a[26]<<25|a[27]>>>7,F=a[27]<<25|a[26]>>>7,d=a[36]<<21|a[37]>>>11,m=a[37]<<21|a[36]>>>11,S=a[47]<<24|a[46]>>>8,T=a[46]<<24|a[47]>>>8,K=a[8]<<27|a[9]>>>5,L=a[9]<<27|a[8]>>>5,r=a[18]<<20|a[19]>>>12,t=a[19]<<20|a[18]>>>12,Y=a[29]<<7|a[28]>>>25,Z=a[28]<<7|a[29]>>>25,G=a[38]<<8|a[39]>>>24,H=a[39]<<8|a[38]>>>24,l=a[48]<<14|a[49]>>>18,n=a[49]<<14|a[48]>>>18,a[0]=b^~g&
|
||||
h,a[1]=c^~k&f,a[10]=p^~r&u,a[11]=q^~t&v,a[20]=A^~C&E,a[21]=B^~D&F,a[30]=K^~M&O,a[31]=L^~N&P,a[40]=U^~W&Y,a[41]=V^~X&Z,a[2]=g^~h&d,a[3]=k^~f&m,a[12]=r^~u&w,a[13]=t^~v&x,a[22]=C^~E&G,a[23]=D^~F&H,a[32]=M^~O&Q,a[33]=N^~P&R,a[42]=W^~Y&aa,a[43]=X^~Z&ba,a[4]=h^~d&l,a[5]=f^~m&n,a[14]=u^~w&y,a[15]=v^~x&z,a[24]=E^~G&I,a[25]=F^~H&J,a[34]=O^~Q&S,a[35]=P^~R&T,a[44]=Y^~aa&ca,a[45]=Z^~ba&da,a[6]=d^~l&b,a[7]=m^~n&c,a[16]=w^~y&p,a[17]=x^~z&q,a[26]=G^~I&A,a[27]=H^~J&B,a[36]=Q^~S&K,a[37]=R^~T&L,a[46]=aa^~ca&U,a[47]=
|
||||
ba^~da&V,a[8]=l^~b&g,a[9]=n^~c&k,a[18]=y^~p&r,a[19]=z^~q&t,a[28]=I^~A&C,a[29]=J^~B&D,a[38]=S^~K&M,a[39]=T^~L&N,a[48]=ca^~U&W,a[49]=da^~V&X,a[0]^=ga[e],a[1]^=ga[e+1]};if(!r.JS_SHA3_TEST&&fa)module.exports=y;else if(r)for(var ja in y)r[ja]=y[ja]})(this);
|
||||
+6
-5
@@ -1,15 +1,16 @@
|
||||
{
|
||||
"name": "js-sha3",
|
||||
"version": "0.1.2",
|
||||
"description": "A simple SHA-3 / Keccak hash function for JavaScript supports UTF-8 encoding.",
|
||||
"version": "0.4.1",
|
||||
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
|
||||
"main": "src/sha3.js",
|
||||
"devDependencies": {
|
||||
"expect.js": "~0.3.1",
|
||||
"jscoverage": "~0.5.9"
|
||||
"jscoverage": "~0.5.9",
|
||||
"mocha": "~2.3.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha test/node-test.js -r jscoverage",
|
||||
"coveralls": "mocha test/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls"
|
||||
"test": "mocha tests/node-test.js -r jscoverage",
|
||||
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
+424
-346
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* js-sha3 v0.1.2
|
||||
* js-sha3 v0.5.0
|
||||
* https://github.com/emn178/js-sha3
|
||||
*
|
||||
* Copyright 2015, emn178@gmail.com
|
||||
@@ -17,379 +17,457 @@
|
||||
root.navigator = { userAgent: 'Chrome'};
|
||||
}
|
||||
}
|
||||
var CHROME = (root.JS_SHA3_TEST || !NODE_JS) && navigator.userAgent.indexOf('Chrome') != -1;
|
||||
var HEX_CHARS = '0123456789abcdef'.split('');
|
||||
var EXTRA = [1, 256, 65536, 16777216];
|
||||
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
|
||||
var KECCAK_PADDING = [1, 256, 65536, 16777216];
|
||||
var PADDING = [6, 1536, 393216, 100663296];
|
||||
var SHIFT = [0, 8, 16, 24];
|
||||
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
|
||||
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
|
||||
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
|
||||
2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
|
||||
2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
|
||||
var BITS = [224, 256, 384, 512];
|
||||
var SHAKE_BITS = [128, 256];
|
||||
var OUTPUT_TYPES = ['hex', 'buffer', 'array'];
|
||||
|
||||
var blocks = [], s = [];
|
||||
|
||||
var sha3_224 = function(message) {
|
||||
return sha3(message, 224);
|
||||
};
|
||||
|
||||
var sha3_256 = function(message) {
|
||||
return sha3(message, 256);
|
||||
};
|
||||
|
||||
var sha3_384 = function(message) {
|
||||
return sha3(message, 384);
|
||||
};
|
||||
|
||||
var sha3 = function(message, bits) {
|
||||
if(bits === undefined) {
|
||||
bits = 512;
|
||||
var createOutputMethod = function(bits, padding, outputType) {
|
||||
return function(message) {
|
||||
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
||||
}
|
||||
};
|
||||
|
||||
var block, code, end = false, index = 0, start = 0, length = message.length,
|
||||
n, i, h, l, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
||||
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
||||
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
|
||||
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
|
||||
var blockCount = (1600 - bits * 2) / 32;
|
||||
var byteCount = blockCount * 4;
|
||||
var createShakeOutputMethod = function(bits, padding, outputType) {
|
||||
return function(message, outputBits) {
|
||||
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
|
||||
}
|
||||
};
|
||||
|
||||
var createMethod = function(bits, padding) {
|
||||
var method = createOutputMethod(bits, padding, 'hex');
|
||||
method.create = function() {
|
||||
return new Keccak(bits, padding, bits);
|
||||
};
|
||||
method.update = function(message) {
|
||||
return method.create().update(message);
|
||||
};
|
||||
for(var i = 0;i < OUTPUT_TYPES.length;++i) {
|
||||
var type = OUTPUT_TYPES[i];
|
||||
method[type] = createOutputMethod(bits, padding, type);
|
||||
}
|
||||
return method;
|
||||
};
|
||||
|
||||
var createShakeMethod = function(bits, padding) {
|
||||
var method = createShakeOutputMethod(bits, padding, 'hex');
|
||||
method.create = function(outputBits) {
|
||||
return new Keccak(bits, padding, outputBits);
|
||||
};
|
||||
method.update = function(message, outputBits) {
|
||||
return method.create(outputBits).update(message);
|
||||
};
|
||||
for(var i = 0;i < OUTPUT_TYPES.length;++i) {
|
||||
var type = OUTPUT_TYPES[i];
|
||||
method[type] = createShakeOutputMethod(bits, padding, type);
|
||||
}
|
||||
return method;
|
||||
};
|
||||
|
||||
var algorithms = [
|
||||
{name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod},
|
||||
{name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod},
|
||||
{name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod}
|
||||
];
|
||||
|
||||
var methods = {};
|
||||
|
||||
for(var i = 0;i < algorithms.length;++i) {
|
||||
var algorithm = algorithms[i];
|
||||
var bits = algorithm.bits;
|
||||
var createMethod = algorithm.createMethod;
|
||||
for(var j = 0;j < bits.length;++j) {
|
||||
var method = algorithm.createMethod(bits[j], algorithm.padding);
|
||||
methods[algorithm.name +'_' + bits[j]] = method;
|
||||
}
|
||||
}
|
||||
|
||||
function Keccak(bits, padding, outputBits) {
|
||||
this.blocks = [];
|
||||
this.s = [];
|
||||
this.padding = padding;
|
||||
this.outputBits = outputBits;
|
||||
this.reset = true;
|
||||
this.block = 0;
|
||||
this.start = 0;
|
||||
this.blockCount = (1600 - (bits << 1)) >> 5;
|
||||
this.byteCount = this.blockCount << 2;
|
||||
this.outputBlocks = outputBits >> 5;
|
||||
this.extraBytes = (outputBits & 31) >> 3;
|
||||
|
||||
for(i = 0;i < 50;++i) {
|
||||
s[i] = 0;
|
||||
this.s[i] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
block = 0;
|
||||
do {
|
||||
blocks[0] = block;
|
||||
Keccak.prototype.update = function(message) {
|
||||
var notString = typeof(message) != 'string';
|
||||
if(notString && message.constructor == root.ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
}
|
||||
var length = message.length, blocks = this.blocks, byteCount = this.byteCount,
|
||||
blockCount = this.blockCount, index = 0, s = this.s, i, code;
|
||||
|
||||
while(index < length) {
|
||||
if(this.reset) {
|
||||
this.reset = false;
|
||||
blocks[0] = this.block;
|
||||
for(i = 1;i < blockCount + 1;++i) {
|
||||
blocks[i] = 0;
|
||||
}
|
||||
}
|
||||
if(notString) {
|
||||
for (i = this.start;index < length && i < byteCount; ++index) {
|
||||
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
||||
}
|
||||
} else {
|
||||
for (i = this.start;index < length && i < byteCount; ++index) {
|
||||
code = message.charCodeAt(index);
|
||||
if (code < 0x80) {
|
||||
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
||||
} else if (code < 0x800) {
|
||||
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else {
|
||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||
blocks[i >> 2] |= (0xf0 | (code >> 18)) << 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 & 0x3f)) << SHIFT[i++ & 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastByteIndex = i;
|
||||
if(i >= byteCount) {
|
||||
this.start = i - byteCount;
|
||||
this.block = blocks[blockCount];
|
||||
for(i = 0;i < blockCount;++i) {
|
||||
s[i] ^= blocks[i];
|
||||
}
|
||||
f(s);
|
||||
this.reset = true;
|
||||
} else {
|
||||
this.start = i;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Keccak.prototype.finalize = function() {
|
||||
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
|
||||
blocks[i >> 2] |= this.padding[i & 3];
|
||||
if(this.lastByteIndex == this.byteCount) {
|
||||
blocks[0] = blocks[blockCount];
|
||||
for(i = 1;i < blockCount + 1;++i) {
|
||||
blocks[i] = 0;
|
||||
}
|
||||
for (i = start;index < length && i < byteCount; ++index) {
|
||||
code = message.charCodeAt(index);
|
||||
if (code < 0x80) {
|
||||
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
||||
} else if (code < 0x800) {
|
||||
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else if (code < 0xd800 || code >= 0xe000) {
|
||||
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
||||
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
||||
} else {
|
||||
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
||||
blocks[i >> 2] |= (0xf0 | (code >> 18)) << 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 & 0x3f)) << SHIFT[i++ & 3];
|
||||
}
|
||||
}
|
||||
start = i - byteCount;
|
||||
if(index == length) {
|
||||
blocks[i >> 2] |= EXTRA[i & 3];
|
||||
++index;
|
||||
}
|
||||
block = blocks[blockCount];
|
||||
if(index > length && i < byteCount) {
|
||||
blocks[blockCount - 1] |= 0x80000000;
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
blocks[blockCount - 1] |= 0x80000000;
|
||||
for(i = 0;i < blockCount;++i) {
|
||||
s[i] ^= blocks[i];
|
||||
}
|
||||
f(s);
|
||||
};
|
||||
|
||||
for(i = 0;i < blockCount;++i) {
|
||||
s[i] ^= blocks[i];
|
||||
Keccak.prototype.toString = Keccak.prototype.hex = function() {
|
||||
this.finalize();
|
||||
|
||||
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
||||
extraBytes = this.extraBytes, i = 0, j = 0;
|
||||
var hex = '', block;
|
||||
while(j < outputBlocks) {
|
||||
for(i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
|
||||
block = s[i];
|
||||
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
|
||||
HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
|
||||
HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
|
||||
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
||||
}
|
||||
|
||||
for(n = 0; n < 48; n += 2) {
|
||||
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
|
||||
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
|
||||
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
|
||||
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
|
||||
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
|
||||
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
|
||||
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
|
||||
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
|
||||
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
|
||||
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
|
||||
|
||||
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
|
||||
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
|
||||
s[0] ^= h;
|
||||
s[1] ^= l;
|
||||
s[10] ^= h;
|
||||
s[11] ^= l;
|
||||
s[20] ^= h;
|
||||
s[21] ^= l;
|
||||
s[30] ^= h;
|
||||
s[31] ^= l;
|
||||
s[40] ^= h;
|
||||
s[41] ^= l;
|
||||
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
|
||||
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
|
||||
s[2] ^= h;
|
||||
s[3] ^= l;
|
||||
s[12] ^= h;
|
||||
s[13] ^= l;
|
||||
s[22] ^= h;
|
||||
s[23] ^= l;
|
||||
s[32] ^= h;
|
||||
s[33] ^= l;
|
||||
s[42] ^= h;
|
||||
s[43] ^= l;
|
||||
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
|
||||
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
|
||||
s[4] ^= h;
|
||||
s[5] ^= l;
|
||||
s[14] ^= h;
|
||||
s[15] ^= l;
|
||||
s[24] ^= h;
|
||||
s[25] ^= l;
|
||||
s[34] ^= h;
|
||||
s[35] ^= l;
|
||||
s[44] ^= h;
|
||||
s[45] ^= l;
|
||||
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
|
||||
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
|
||||
s[6] ^= h;
|
||||
s[7] ^= l;
|
||||
s[16] ^= h;
|
||||
s[17] ^= l;
|
||||
s[26] ^= h;
|
||||
s[27] ^= l;
|
||||
s[36] ^= h;
|
||||
s[37] ^= l;
|
||||
s[46] ^= h;
|
||||
s[47] ^= l;
|
||||
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
|
||||
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
|
||||
s[8] ^= h;
|
||||
s[9] ^= l;
|
||||
s[18] ^= h;
|
||||
s[19] ^= l;
|
||||
s[28] ^= h;
|
||||
s[29] ^= l;
|
||||
s[38] ^= h;
|
||||
s[39] ^= l;
|
||||
s[48] ^= h;
|
||||
s[49] ^= l;
|
||||
|
||||
b0 = s[0];
|
||||
b1 = s[1];
|
||||
b32 = (s[11] << 4) | (s[10] >>> 28);
|
||||
b33 = (s[10] << 4) | (s[11] >>> 28);
|
||||
b14 = (s[20] << 3) | (s[21] >>> 29);
|
||||
b15 = (s[21] << 3) | (s[20] >>> 29);
|
||||
b46 = (s[31] << 9) | (s[30] >>> 23);
|
||||
b47 = (s[30] << 9) | (s[31] >>> 23);
|
||||
b28 = (s[40] << 18) | (s[41] >>> 14);
|
||||
b29 = (s[41] << 18) | (s[40] >>> 14);
|
||||
b20 = (s[2] << 1) | (s[3] >>> 31);
|
||||
b21 = (s[3] << 1) | (s[2] >>> 31);
|
||||
b2 = (s[13] << 12) | (s[12] >>> 20);
|
||||
b3 = (s[12] << 12) | (s[13] >>> 20);
|
||||
b34 = (s[22] << 10) | (s[23] >>> 22);
|
||||
b35 = (s[23] << 10) | (s[22] >>> 22);
|
||||
b16 = (s[33] << 13) | (s[32] >>> 19);
|
||||
b17 = (s[32] << 13) | (s[33] >>> 19);
|
||||
b48 = (s[42] << 2) | (s[43] >>> 30);
|
||||
b49 = (s[43] << 2) | (s[42] >>> 30);
|
||||
b40 = (s[5] << 30) | (s[4] >>> 2);
|
||||
b41 = (s[4] << 30) | (s[5] >>> 2);
|
||||
b22 = (s[14] << 6) | (s[15] >>> 26);
|
||||
b23 = (s[15] << 6) | (s[14] >>> 26);
|
||||
b4 = (s[25] << 11) | (s[24] >>> 21);
|
||||
b5 = (s[24] << 11) | (s[25] >>> 21);
|
||||
b36 = (s[34] << 15) | (s[35] >>> 17);
|
||||
b37 = (s[35] << 15) | (s[34] >>> 17);
|
||||
b18 = (s[45] << 29) | (s[44] >>> 3);
|
||||
b19 = (s[44] << 29) | (s[45] >>> 3);
|
||||
b10 = (s[6] << 28) | (s[7] >>> 4);
|
||||
b11 = (s[7] << 28) | (s[6] >>> 4);
|
||||
b42 = (s[17] << 23) | (s[16] >>> 9);
|
||||
b43 = (s[16] << 23) | (s[17] >>> 9);
|
||||
b24 = (s[26] << 25) | (s[27] >>> 7);
|
||||
b25 = (s[27] << 25) | (s[26] >>> 7);
|
||||
b6 = (s[36] << 21) | (s[37] >>> 11);
|
||||
b7 = (s[37] << 21) | (s[36] >>> 11);
|
||||
b38 = (s[47] << 24) | (s[46] >>> 8);
|
||||
b39 = (s[46] << 24) | (s[47] >>> 8);
|
||||
b30 = (s[8] << 27) | (s[9] >>> 5);
|
||||
b31 = (s[9] << 27) | (s[8] >>> 5);
|
||||
b12 = (s[18] << 20) | (s[19] >>> 12);
|
||||
b13 = (s[19] << 20) | (s[18] >>> 12);
|
||||
b44 = (s[29] << 7) | (s[28] >>> 25);
|
||||
b45 = (s[28] << 7) | (s[29] >>> 25);
|
||||
b26 = (s[38] << 8) | (s[39] >>> 24);
|
||||
b27 = (s[39] << 8) | (s[38] >>> 24);
|
||||
b8 = (s[48] << 14) | (s[49] >>> 18);
|
||||
b9 = (s[49] << 14) | (s[48] >>> 18);
|
||||
|
||||
s[0] = b0 ^ (~b2 & b4);
|
||||
s[1] = b1 ^ (~b3 & b5);
|
||||
s[10] = b10 ^ (~b12 & b14);
|
||||
s[11] = b11 ^ (~b13 & b15);
|
||||
s[20] = b20 ^ (~b22 & b24);
|
||||
s[21] = b21 ^ (~b23 & b25);
|
||||
s[30] = b30 ^ (~b32 & b34);
|
||||
s[31] = b31 ^ (~b33 & b35);
|
||||
s[40] = b40 ^ (~b42 & b44);
|
||||
s[41] = b41 ^ (~b43 & b45);
|
||||
s[2] = b2 ^ (~b4 & b6);
|
||||
s[3] = b3 ^ (~b5 & b7);
|
||||
s[12] = b12 ^ (~b14 & b16);
|
||||
s[13] = b13 ^ (~b15 & b17);
|
||||
s[22] = b22 ^ (~b24 & b26);
|
||||
s[23] = b23 ^ (~b25 & b27);
|
||||
s[32] = b32 ^ (~b34 & b36);
|
||||
s[33] = b33 ^ (~b35 & b37);
|
||||
s[42] = b42 ^ (~b44 & b46);
|
||||
s[43] = b43 ^ (~b45 & b47);
|
||||
s[4] = b4 ^ (~b6 & b8);
|
||||
s[5] = b5 ^ (~b7 & b9);
|
||||
s[14] = b14 ^ (~b16 & b18);
|
||||
s[15] = b15 ^ (~b17 & b19);
|
||||
s[24] = b24 ^ (~b26 & b28);
|
||||
s[25] = b25 ^ (~b27 & b29);
|
||||
s[34] = b34 ^ (~b36 & b38);
|
||||
s[35] = b35 ^ (~b37 & b39);
|
||||
s[44] = b44 ^ (~b46 & b48);
|
||||
s[45] = b45 ^ (~b47 & b49);
|
||||
s[6] = b6 ^ (~b8 & b0);
|
||||
s[7] = b7 ^ (~b9 & b1);
|
||||
s[16] = b16 ^ (~b18 & b10);
|
||||
s[17] = b17 ^ (~b19 & b11);
|
||||
s[26] = b26 ^ (~b28 & b20);
|
||||
s[27] = b27 ^ (~b29 & b21);
|
||||
s[36] = b36 ^ (~b38 & b30);
|
||||
s[37] = b37 ^ (~b39 & b31);
|
||||
s[46] = b46 ^ (~b48 & b40);
|
||||
s[47] = b47 ^ (~b49 & b41);
|
||||
s[8] = b8 ^ (~b0 & b2);
|
||||
s[9] = b9 ^ (~b1 & b3);
|
||||
s[18] = b18 ^ (~b10 & b12);
|
||||
s[19] = b19 ^ (~b11 & b13);
|
||||
s[28] = b28 ^ (~b20 & b22);
|
||||
s[29] = b29 ^ (~b21 & b23);
|
||||
s[38] = b38 ^ (~b30 & b32);
|
||||
s[39] = b39 ^ (~b31 & b33);
|
||||
s[48] = b48 ^ (~b40 & b42);
|
||||
s[49] = b49 ^ (~b41 & b43);
|
||||
|
||||
s[0] ^= RC[n];
|
||||
s[1] ^= RC[n + 1];
|
||||
if(j % blockCount == 0) {
|
||||
f(s);
|
||||
}
|
||||
} while(!end);
|
||||
|
||||
var hex = '';
|
||||
if(CHROME) {
|
||||
b0 = s[0];
|
||||
b1 = s[1];
|
||||
b2 = s[2];
|
||||
b3 = s[3];
|
||||
b4 = s[4];
|
||||
b5 = s[5];
|
||||
b6 = s[6];
|
||||
b7 = s[7];
|
||||
b8 = s[8];
|
||||
b9 = s[9];
|
||||
b10 = s[10];
|
||||
b11 = s[11];
|
||||
b12 = s[12];
|
||||
b13 = s[13];
|
||||
b14 = s[14];
|
||||
b15 = s[15];
|
||||
hex += HEX_CHARS[(b0 >> 4) & 0x0F] + HEX_CHARS[b0 & 0x0F] +
|
||||
HEX_CHARS[(b0 >> 12) & 0x0F] + HEX_CHARS[(b0 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b0 >> 20) & 0x0F] + HEX_CHARS[(b0 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b0 >> 28) & 0x0F] + HEX_CHARS[(b0 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b1 >> 4) & 0x0F] + HEX_CHARS[b1 & 0x0F] +
|
||||
HEX_CHARS[(b1 >> 12) & 0x0F] + HEX_CHARS[(b1 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b1 >> 20) & 0x0F] + HEX_CHARS[(b1 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b1 >> 28) & 0x0F] + HEX_CHARS[(b1 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b2 >> 4) & 0x0F] + HEX_CHARS[b2 & 0x0F] +
|
||||
HEX_CHARS[(b2 >> 12) & 0x0F] + HEX_CHARS[(b2 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b2 >> 20) & 0x0F] + HEX_CHARS[(b2 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b2 >> 28) & 0x0F] + HEX_CHARS[(b2 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b3 >> 4) & 0x0F] + HEX_CHARS[b3 & 0x0F] +
|
||||
HEX_CHARS[(b3 >> 12) & 0x0F] + HEX_CHARS[(b3 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b3 >> 20) & 0x0F] + HEX_CHARS[(b3 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b3 >> 28) & 0x0F] + HEX_CHARS[(b3 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b4 >> 4) & 0x0F] + HEX_CHARS[b4 & 0x0F] +
|
||||
HEX_CHARS[(b4 >> 12) & 0x0F] + HEX_CHARS[(b4 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b4 >> 20) & 0x0F] + HEX_CHARS[(b4 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b4 >> 28) & 0x0F] + HEX_CHARS[(b4 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b5 >> 4) & 0x0F] + HEX_CHARS[b5 & 0x0F] +
|
||||
HEX_CHARS[(b5 >> 12) & 0x0F] + HEX_CHARS[(b5 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b5 >> 20) & 0x0F] + HEX_CHARS[(b5 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b5 >> 28) & 0x0F] + HEX_CHARS[(b5 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b6 >> 4) & 0x0F] + HEX_CHARS[b6 & 0x0F] +
|
||||
HEX_CHARS[(b6 >> 12) & 0x0F] + HEX_CHARS[(b6 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b6 >> 20) & 0x0F] + HEX_CHARS[(b6 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b6 >> 28) & 0x0F] + HEX_CHARS[(b6 >> 24) & 0x0F];
|
||||
|
||||
if(bits >= 256) {
|
||||
hex += HEX_CHARS[(b7 >> 4) & 0x0F] + HEX_CHARS[b7 & 0x0F] +
|
||||
HEX_CHARS[(b7 >> 12) & 0x0F] + HEX_CHARS[(b7 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b7 >> 20) & 0x0F] + HEX_CHARS[(b7 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b7 >> 28) & 0x0F] + HEX_CHARS[(b7 >> 24) & 0x0F];
|
||||
}
|
||||
if(extraBytes) {
|
||||
block = s[i];
|
||||
if(extraBytes > 0) {
|
||||
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
|
||||
}
|
||||
if(bits >= 384) {
|
||||
hex += HEX_CHARS[(b8 >> 4) & 0x0F] + HEX_CHARS[b8 & 0x0F] +
|
||||
HEX_CHARS[(b8 >> 12) & 0x0F] + HEX_CHARS[(b8 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b8 >> 20) & 0x0F] + HEX_CHARS[(b8 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b8 >> 28) & 0x0F] + HEX_CHARS[(b8 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b9 >> 4) & 0x0F] + HEX_CHARS[b9 & 0x0F] +
|
||||
HEX_CHARS[(b9 >> 12) & 0x0F] + HEX_CHARS[(b9 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b9 >> 20) & 0x0F] + HEX_CHARS[(b9 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b9 >> 28) & 0x0F] + HEX_CHARS[(b9 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b10 >> 4) & 0x0F] + HEX_CHARS[b10 & 0x0F] +
|
||||
HEX_CHARS[(b10 >> 12) & 0x0F] + HEX_CHARS[(b10 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b10 >> 20) & 0x0F] + HEX_CHARS[(b10 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b10 >> 28) & 0x0F] + HEX_CHARS[(b10 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b11 >> 4) & 0x0F] + HEX_CHARS[b11 & 0x0F] +
|
||||
HEX_CHARS[(b11 >> 12) & 0x0F] + HEX_CHARS[(b11 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b11 >> 20) & 0x0F] + HEX_CHARS[(b11 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b11 >> 28) & 0x0F] + HEX_CHARS[(b11 >> 24) & 0x0F];
|
||||
if(extraBytes > 1) {
|
||||
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
|
||||
}
|
||||
if(bits == 512) {
|
||||
hex += HEX_CHARS[(b12 >> 4) & 0x0F] + HEX_CHARS[b12 & 0x0F] +
|
||||
HEX_CHARS[(b12 >> 12) & 0x0F] + HEX_CHARS[(b12 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b12 >> 20) & 0x0F] + HEX_CHARS[(b12 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b12 >> 28) & 0x0F] + HEX_CHARS[(b12 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b13 >> 4) & 0x0F] + HEX_CHARS[b13 & 0x0F] +
|
||||
HEX_CHARS[(b13 >> 12) & 0x0F] + HEX_CHARS[(b13 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b13 >> 20) & 0x0F] + HEX_CHARS[(b13 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b13 >> 28) & 0x0F] + HEX_CHARS[(b13 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b14 >> 4) & 0x0F] + HEX_CHARS[b14 & 0x0F] +
|
||||
HEX_CHARS[(b14 >> 12) & 0x0F] + HEX_CHARS[(b14 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b14 >> 20) & 0x0F] + HEX_CHARS[(b14 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b14 >> 28) & 0x0F] + HEX_CHARS[(b14 >> 24) & 0x0F] +
|
||||
HEX_CHARS[(b15 >> 4) & 0x0F] + HEX_CHARS[b15 & 0x0F] +
|
||||
HEX_CHARS[(b15 >> 12) & 0x0F] + HEX_CHARS[(b15 >> 8) & 0x0F] +
|
||||
HEX_CHARS[(b15 >> 20) & 0x0F] + HEX_CHARS[(b15 >> 16) & 0x0F] +
|
||||
HEX_CHARS[(b15 >> 28) & 0x0F] + HEX_CHARS[(b15 >> 24) & 0x0F];
|
||||
}
|
||||
} else {
|
||||
for(i = 0, n = bits / 32;i < n;++i) {
|
||||
h = s[i];
|
||||
hex += HEX_CHARS[(h >> 4) & 0x0F] + HEX_CHARS[h & 0x0F] +
|
||||
HEX_CHARS[(h >> 12) & 0x0F] + HEX_CHARS[(h >> 8) & 0x0F] +
|
||||
HEX_CHARS[(h >> 20) & 0x0F] + HEX_CHARS[(h >> 16) & 0x0F] +
|
||||
HEX_CHARS[(h >> 28) & 0x0F] + HEX_CHARS[(h >> 24) & 0x0F];
|
||||
if(extraBytes > 2) {
|
||||
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
|
||||
}
|
||||
}
|
||||
return hex;
|
||||
};
|
||||
|
||||
Keccak.prototype.buffer = function() {
|
||||
this.finalize();
|
||||
|
||||
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
||||
extraBytes = this.extraBytes, i = 0, j = 0;
|
||||
var bytes = this.outputBits >> 3;
|
||||
var buffer;
|
||||
if(extraBytes) {
|
||||
buffer = new ArrayBuffer((outputBlocks + 1) << 2);
|
||||
} else {
|
||||
buffer = new ArrayBuffer(bytes);
|
||||
}
|
||||
var array = new Uint32Array(buffer);
|
||||
while(j < outputBlocks) {
|
||||
for(i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
|
||||
array[j] = s[i];
|
||||
}
|
||||
if(j % blockCount == 0) {
|
||||
f(s);
|
||||
}
|
||||
}
|
||||
if(extraBytes) {
|
||||
array[i] = s[i];
|
||||
buffer = buffer.slice(0, bytes);
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
|
||||
Keccak.prototype.digest = Keccak.prototype.array = function() {
|
||||
this.finalize();
|
||||
|
||||
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
||||
extraBytes = this.extraBytes, i = 0, j = 0;
|
||||
var array = [], offset, block;
|
||||
while(j < outputBlocks) {
|
||||
for(i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
|
||||
offset = j << 2;
|
||||
block = s[i];
|
||||
array[offset] = block & 0xFF;
|
||||
array[offset + 1] = (block >> 8) & 0xFF;
|
||||
array[offset + 2] = (block >> 16) & 0xFF;
|
||||
array[offset + 3] = (block >> 24) & 0xFF;
|
||||
}
|
||||
if(j % blockCount == 0) {
|
||||
f(s);
|
||||
}
|
||||
}
|
||||
if(extraBytes) {
|
||||
offset = j << 2;
|
||||
block = s[i];
|
||||
if(extraBytes > 0) {
|
||||
array[offset] = block & 0xFF;
|
||||
}
|
||||
if(extraBytes > 1) {
|
||||
array[offset + 1] = (block >> 8) & 0xFF;
|
||||
}
|
||||
if(extraBytes > 2) {
|
||||
array[offset + 2] = (block >> 16) & 0xFF;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
};
|
||||
|
||||
var f = function(s) {
|
||||
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
||||
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
||||
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
|
||||
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
|
||||
for(n = 0; n < 48; n += 2) {
|
||||
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
|
||||
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
|
||||
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
|
||||
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
|
||||
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
|
||||
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
|
||||
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
|
||||
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
|
||||
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
|
||||
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
|
||||
|
||||
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
|
||||
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
|
||||
s[0] ^= h;
|
||||
s[1] ^= l;
|
||||
s[10] ^= h;
|
||||
s[11] ^= l;
|
||||
s[20] ^= h;
|
||||
s[21] ^= l;
|
||||
s[30] ^= h;
|
||||
s[31] ^= l;
|
||||
s[40] ^= h;
|
||||
s[41] ^= l;
|
||||
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
|
||||
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
|
||||
s[2] ^= h;
|
||||
s[3] ^= l;
|
||||
s[12] ^= h;
|
||||
s[13] ^= l;
|
||||
s[22] ^= h;
|
||||
s[23] ^= l;
|
||||
s[32] ^= h;
|
||||
s[33] ^= l;
|
||||
s[42] ^= h;
|
||||
s[43] ^= l;
|
||||
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
|
||||
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
|
||||
s[4] ^= h;
|
||||
s[5] ^= l;
|
||||
s[14] ^= h;
|
||||
s[15] ^= l;
|
||||
s[24] ^= h;
|
||||
s[25] ^= l;
|
||||
s[34] ^= h;
|
||||
s[35] ^= l;
|
||||
s[44] ^= h;
|
||||
s[45] ^= l;
|
||||
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
|
||||
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
|
||||
s[6] ^= h;
|
||||
s[7] ^= l;
|
||||
s[16] ^= h;
|
||||
s[17] ^= l;
|
||||
s[26] ^= h;
|
||||
s[27] ^= l;
|
||||
s[36] ^= h;
|
||||
s[37] ^= l;
|
||||
s[46] ^= h;
|
||||
s[47] ^= l;
|
||||
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
|
||||
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
|
||||
s[8] ^= h;
|
||||
s[9] ^= l;
|
||||
s[18] ^= h;
|
||||
s[19] ^= l;
|
||||
s[28] ^= h;
|
||||
s[29] ^= l;
|
||||
s[38] ^= h;
|
||||
s[39] ^= l;
|
||||
s[48] ^= h;
|
||||
s[49] ^= l;
|
||||
|
||||
b0 = s[0];
|
||||
b1 = s[1];
|
||||
b32 = (s[11] << 4) | (s[10] >>> 28);
|
||||
b33 = (s[10] << 4) | (s[11] >>> 28);
|
||||
b14 = (s[20] << 3) | (s[21] >>> 29);
|
||||
b15 = (s[21] << 3) | (s[20] >>> 29);
|
||||
b46 = (s[31] << 9) | (s[30] >>> 23);
|
||||
b47 = (s[30] << 9) | (s[31] >>> 23);
|
||||
b28 = (s[40] << 18) | (s[41] >>> 14);
|
||||
b29 = (s[41] << 18) | (s[40] >>> 14);
|
||||
b20 = (s[2] << 1) | (s[3] >>> 31);
|
||||
b21 = (s[3] << 1) | (s[2] >>> 31);
|
||||
b2 = (s[13] << 12) | (s[12] >>> 20);
|
||||
b3 = (s[12] << 12) | (s[13] >>> 20);
|
||||
b34 = (s[22] << 10) | (s[23] >>> 22);
|
||||
b35 = (s[23] << 10) | (s[22] >>> 22);
|
||||
b16 = (s[33] << 13) | (s[32] >>> 19);
|
||||
b17 = (s[32] << 13) | (s[33] >>> 19);
|
||||
b48 = (s[42] << 2) | (s[43] >>> 30);
|
||||
b49 = (s[43] << 2) | (s[42] >>> 30);
|
||||
b40 = (s[5] << 30) | (s[4] >>> 2);
|
||||
b41 = (s[4] << 30) | (s[5] >>> 2);
|
||||
b22 = (s[14] << 6) | (s[15] >>> 26);
|
||||
b23 = (s[15] << 6) | (s[14] >>> 26);
|
||||
b4 = (s[25] << 11) | (s[24] >>> 21);
|
||||
b5 = (s[24] << 11) | (s[25] >>> 21);
|
||||
b36 = (s[34] << 15) | (s[35] >>> 17);
|
||||
b37 = (s[35] << 15) | (s[34] >>> 17);
|
||||
b18 = (s[45] << 29) | (s[44] >>> 3);
|
||||
b19 = (s[44] << 29) | (s[45] >>> 3);
|
||||
b10 = (s[6] << 28) | (s[7] >>> 4);
|
||||
b11 = (s[7] << 28) | (s[6] >>> 4);
|
||||
b42 = (s[17] << 23) | (s[16] >>> 9);
|
||||
b43 = (s[16] << 23) | (s[17] >>> 9);
|
||||
b24 = (s[26] << 25) | (s[27] >>> 7);
|
||||
b25 = (s[27] << 25) | (s[26] >>> 7);
|
||||
b6 = (s[36] << 21) | (s[37] >>> 11);
|
||||
b7 = (s[37] << 21) | (s[36] >>> 11);
|
||||
b38 = (s[47] << 24) | (s[46] >>> 8);
|
||||
b39 = (s[46] << 24) | (s[47] >>> 8);
|
||||
b30 = (s[8] << 27) | (s[9] >>> 5);
|
||||
b31 = (s[9] << 27) | (s[8] >>> 5);
|
||||
b12 = (s[18] << 20) | (s[19] >>> 12);
|
||||
b13 = (s[19] << 20) | (s[18] >>> 12);
|
||||
b44 = (s[29] << 7) | (s[28] >>> 25);
|
||||
b45 = (s[28] << 7) | (s[29] >>> 25);
|
||||
b26 = (s[38] << 8) | (s[39] >>> 24);
|
||||
b27 = (s[39] << 8) | (s[38] >>> 24);
|
||||
b8 = (s[48] << 14) | (s[49] >>> 18);
|
||||
b9 = (s[49] << 14) | (s[48] >>> 18);
|
||||
|
||||
s[0] = b0 ^ (~b2 & b4);
|
||||
s[1] = b1 ^ (~b3 & b5);
|
||||
s[10] = b10 ^ (~b12 & b14);
|
||||
s[11] = b11 ^ (~b13 & b15);
|
||||
s[20] = b20 ^ (~b22 & b24);
|
||||
s[21] = b21 ^ (~b23 & b25);
|
||||
s[30] = b30 ^ (~b32 & b34);
|
||||
s[31] = b31 ^ (~b33 & b35);
|
||||
s[40] = b40 ^ (~b42 & b44);
|
||||
s[41] = b41 ^ (~b43 & b45);
|
||||
s[2] = b2 ^ (~b4 & b6);
|
||||
s[3] = b3 ^ (~b5 & b7);
|
||||
s[12] = b12 ^ (~b14 & b16);
|
||||
s[13] = b13 ^ (~b15 & b17);
|
||||
s[22] = b22 ^ (~b24 & b26);
|
||||
s[23] = b23 ^ (~b25 & b27);
|
||||
s[32] = b32 ^ (~b34 & b36);
|
||||
s[33] = b33 ^ (~b35 & b37);
|
||||
s[42] = b42 ^ (~b44 & b46);
|
||||
s[43] = b43 ^ (~b45 & b47);
|
||||
s[4] = b4 ^ (~b6 & b8);
|
||||
s[5] = b5 ^ (~b7 & b9);
|
||||
s[14] = b14 ^ (~b16 & b18);
|
||||
s[15] = b15 ^ (~b17 & b19);
|
||||
s[24] = b24 ^ (~b26 & b28);
|
||||
s[25] = b25 ^ (~b27 & b29);
|
||||
s[34] = b34 ^ (~b36 & b38);
|
||||
s[35] = b35 ^ (~b37 & b39);
|
||||
s[44] = b44 ^ (~b46 & b48);
|
||||
s[45] = b45 ^ (~b47 & b49);
|
||||
s[6] = b6 ^ (~b8 & b0);
|
||||
s[7] = b7 ^ (~b9 & b1);
|
||||
s[16] = b16 ^ (~b18 & b10);
|
||||
s[17] = b17 ^ (~b19 & b11);
|
||||
s[26] = b26 ^ (~b28 & b20);
|
||||
s[27] = b27 ^ (~b29 & b21);
|
||||
s[36] = b36 ^ (~b38 & b30);
|
||||
s[37] = b37 ^ (~b39 & b31);
|
||||
s[46] = b46 ^ (~b48 & b40);
|
||||
s[47] = b47 ^ (~b49 & b41);
|
||||
s[8] = b8 ^ (~b0 & b2);
|
||||
s[9] = b9 ^ (~b1 & b3);
|
||||
s[18] = b18 ^ (~b10 & b12);
|
||||
s[19] = b19 ^ (~b11 & b13);
|
||||
s[28] = b28 ^ (~b20 & b22);
|
||||
s[29] = b29 ^ (~b21 & b23);
|
||||
s[38] = b38 ^ (~b30 & b32);
|
||||
s[39] = b39 ^ (~b31 & b33);
|
||||
s[48] = b48 ^ (~b40 & b42);
|
||||
s[49] = b49 ^ (~b41 & b43);
|
||||
|
||||
s[0] ^= RC[n];
|
||||
s[1] ^= RC[n + 1];
|
||||
}
|
||||
}
|
||||
|
||||
if(!root.JS_SHA3_TEST && NODE_JS) {
|
||||
module.exports = {
|
||||
sha3_512: sha3,
|
||||
sha3_384: sha3_384,
|
||||
sha3_256: sha3_256,
|
||||
sha3_224: sha3_224
|
||||
};
|
||||
module.exports = methods;
|
||||
} else if(root) {
|
||||
root.sha3_512 = sha3;
|
||||
root.sha3_384 = sha3_384;
|
||||
root.sha3_256 = sha3_256;
|
||||
root.sha3_224 = sha3_224;
|
||||
for(var key in methods) {
|
||||
root[key] = methods[key];
|
||||
}
|
||||
}
|
||||
}(this));
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
sha3_512 = require('../src/sha3.js').sha3_512;
|
||||
sha3_384 = require('../src/sha3.js').sha3_384;
|
||||
sha3_256 = require('../src/sha3.js').sha3_256;
|
||||
sha3_224 = require('../src/sha3.js').sha3_224;
|
||||
expect = require('expect.js');
|
||||
require('./test.js');
|
||||
|
||||
delete require.cache[require.resolve('../src/sha3.js')]
|
||||
delete require.cache[require.resolve('./test.js')]
|
||||
sha3_512 = null;
|
||||
sha3_384 = null;
|
||||
sha3_256 = null;
|
||||
sha3_224 = null;
|
||||
|
||||
JS_SHA3_TEST = true;
|
||||
require('../src/sha3.js');
|
||||
require('./test.js');
|
||||
-148
@@ -1,148 +0,0 @@
|
||||
(function(sha3_512, sha3_384, sha3_256, sha3_224) {
|
||||
describe('sha3_512', function() {
|
||||
describe('ascii', function() {
|
||||
describe('less than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_512('')).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e');
|
||||
expect(sha3_512('The quick brown fox jumps over the lazy dog')).to.be('d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609');
|
||||
expect(sha3_512('The quick brown fox jumps over the lazy dog.')).to.be('ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_512('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('10dcbf6389980ce3594547939bbc685363d28adbd6a05bc4abd7fc62e7693a1f6e33569fed5a380bfecb56ae811d25939b95823f39bb0f16a08740629d066d43');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('UTF8', function() {
|
||||
describe('less than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_512('中文')).to.be('2f6a1bd50562230229af34b0ccf46b8754b89d23ae2c5bf7840b4acfcef86f87395edc0a00b2bfef53bafebe3b79de2e3e01cbd8169ddbb08bde888dcc893524');
|
||||
expect(sha3_512('aécio')).to.be('c452ec93e83d4795fcab62a76eed0d88f2231a995ce108ac8f130246f87c4a11cb18a2c1a688a5695906a6f863e71bbe8997c6610319ab97f12d2e5bf0afe458');
|
||||
expect(sha3_512('𠜎')).to.be('8a2d72022ce19d989dbe6a0017faccbf5dc2e22c162d1c5eb168864d32dd1a71e1b4782652c148cf6ca47b77a72c96fff682e72bdfef0566d4b7cca3c9ccc59d');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('6a67c28aa1946ca1be8382b861aac4aaf20052f495db9b6902d13adfa603eaba5d169f8896b86d461b2949283eb98e503c3f0640188ea7d6731526fc06568d37');
|
||||
expect(sha3_512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('d04ff5b0e85e9968be2a4d4e133c15c7ccee7497198bb651599a97d11d00bca6048d329ab75aa454566cd532648fa1cb4551985d9d645de9fa43a311a9ee8e4d');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sha3_384', function() {
|
||||
describe('ascii', function() {
|
||||
describe('less than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_384('')).to.be('2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff');
|
||||
expect(sha3_384('The quick brown fox jumps over the lazy dog')).to.be('283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3');
|
||||
expect(sha3_384('The quick brown fox jumps over the lazy dog.')).to.be('9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_384('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('e7ec8976b4d96e43f50ae8ecdcf2d97a56236e6406e8dd00efd0d9abe885659db58a2f4b138a4ecfb1bd0052f6569516');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('UTF8', function() {
|
||||
describe('less than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_384('中文')).to.be('743f64bb7544c6ed923be4741b738dde18b7cee384a3a09c4e01acaaac9f19222cdee137702bd3aa05dc198373d87d6c');
|
||||
expect(sha3_384('aécio')).to.be('08990555e131af8597687614309da4c5053ce866f348544da0a0c2c78c2cc79680ebb57cfbe238286e78ea133a037897');
|
||||
expect(sha3_384('𠜎')).to.be('2a80f59abf3111f38a35a3daa25123b495f90e9736bd300e35911d19abdd8806498c581333f198ccbbf2252b57c2925d');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('a3b043a2f69e4326a05d478fa4c8aa2bd7612453d775af37665a0b96ef2207cdc74c50cdba1629796a5136fe77300b05');
|
||||
expect(sha3_384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('66414c090cc3fe9c396d313cbaa100aefd335e851838b29382568b7f57357ada7c54b8fa8c17f859945bba88b2c2e332');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sha3_256', function() {
|
||||
describe('ascii', function() {
|
||||
describe('less than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_256('')).to.be('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470');
|
||||
expect(sha3_256('The quick brown fox jumps over the lazy dog')).to.be('4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15');
|
||||
expect(sha3_256('The quick brown fox jumps over the lazy dog.')).to.be('578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_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('af20018353ffb50d507f1555580f5272eca7fdab4f8295db4b1a9ad832c93f6d');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('UTF8', function() {
|
||||
describe('less than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_256('中文')).to.be('70a2b6579047f0a977fcb5e9120a4e07067bea9abb6916fbc2d13ffb9a4e4eee');
|
||||
expect(sha3_256('aécio')).to.be('d7d569202f04daf90432810d6163112b2695d7820da979327ebd894efb0276dc');
|
||||
expect(sha3_256('𠜎')).to.be('16a7cc7a58444cbf7e939611910ddc82e7cba65a99d3e8e08cfcda53180a2180');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('d1021d2d4c5c7e88098c40f422af68493b4b64c913cbd68220bf5e6127c37a88');
|
||||
expect(sha3_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('ffabf9bba2127c4928d360c9905cb4911f0ec21b9c3b89f3b242bccc68389e36');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sha3_224', function() {
|
||||
describe('ascii', function() {
|
||||
describe('less than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_224('')).to.be('f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd');
|
||||
expect(sha3_224('The quick brown fox jumps over the lazy dog')).to.be('310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe');
|
||||
expect(sha3_224('The quick brown fox jumps over the lazy dog.')).to.be('c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_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('8dd58b706e3a08ec4f1f202af39295b38c355a39b23308ade7218a21');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('UTF8', function() {
|
||||
describe('less than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_224('中文')).to.be('7bc2a0b6e7e0a055a61e4f731e2944b560f41ff98967dcbf4bbf77a5');
|
||||
expect(sha3_224('aécio')).to.be('66f3db76bf8cb35726cb278bac412d187c3484ab2083dc50ef5ffb55');
|
||||
expect(sha3_224('𠜎')).to.be('3bfa94845726f4cd5cf17d19b5eacac17b3694790e13a76d5c81c7c2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('more than 128 bytes', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('d59eef8f394ef7d96967bb0bde578785c033f7f0a21913d6ba41ed1b');
|
||||
expect(sha3_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('27123a2a3860d1041d4769778c4b078732bf4300f7e1c56536ab2644');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('special length', function() {
|
||||
it('should be successful', function() {
|
||||
expect(sha3_512('012345678901234567890123456789012345678901234567890123456789012345678901')).to.be('90b1d032c3bf06dcc78a46fe52054bab1250600224bfc6dfbfb40a7877c55e89bb982799a2edf198568a4166f6736678b45e76b12fac813cfdf0a76714e5eae8');
|
||||
expect(sha3_512('01234567890123456789012345678901234567890123456789012345678901234567890')).to.be('3173e7abc754a0b2909410d78986428a9183e996864af02f421d273d9fa1b4e4a5b14e2998b20767712f53a01ff8f6ae2c3e71e51e2c0f24257b03e6da09eb77');
|
||||
});
|
||||
});
|
||||
})(sha3_512, sha3_384, sha3_256, sha3_224);
|
||||
@@ -14,6 +14,8 @@
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
<script src="test.js"></script>
|
||||
<script src="test-keccak.js"></script>
|
||||
<script src="test-shake.js"></script>
|
||||
<script>
|
||||
mocha.checkLeaks();
|
||||
mocha.run();
|
||||
@@ -0,0 +1,34 @@
|
||||
expect = require('expect.js');
|
||||
keccak_512 = require('../src/sha3.js').keccak_512;
|
||||
keccak_384 = require('../src/sha3.js').keccak_384;
|
||||
keccak_256 = require('../src/sha3.js').keccak_256;
|
||||
keccak_224 = require('../src/sha3.js').keccak_224;
|
||||
sha3_512 = require('../src/sha3.js').sha3_512;
|
||||
sha3_384 = require('../src/sha3.js').sha3_384;
|
||||
sha3_256 = require('../src/sha3.js').sha3_256;
|
||||
sha3_224 = require('../src/sha3.js').sha3_224;
|
||||
shake_128 = require('../src/sha3.js').shake_128;
|
||||
shake_256 = require('../src/sha3.js').shake_256;
|
||||
require('./test-keccak.js');
|
||||
require('./test.js');
|
||||
|
||||
delete require.cache[require.resolve('../src/sha3.js')]
|
||||
delete require.cache[require.resolve('./test.js')]
|
||||
delete require.cache[require.resolve('./test-keccak.js')]
|
||||
delete require.cache[require.resolve('./test-shake.js')]
|
||||
sha3_512 = null;
|
||||
sha3_384 = null;
|
||||
sha3_256 = null;
|
||||
sha3_224 = null;
|
||||
keccak_512 = null;
|
||||
keccak_384 = null;
|
||||
keccak_256 = null;
|
||||
keccak_224 = null;
|
||||
shake_128 = null;
|
||||
shake_256 = null;
|
||||
|
||||
JS_SHA3_TEST = true;
|
||||
require('../src/sha3.js');
|
||||
require('./test-keccak.js');
|
||||
require('./test-shake.js');
|
||||
require('./test.js');
|
||||
@@ -0,0 +1,180 @@
|
||||
(function(keccak_512, keccak_384, keccak_256, keccak_224) {
|
||||
describe('keccak_512', function() {
|
||||
context('when ascii', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512('')).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e');
|
||||
expect(keccak_512('The quick brown fox jumps over the lazy dog')).to.be('d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609');
|
||||
expect(keccak_512('The quick brown fox jumps over the lazy dog.')).to.be('ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512('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('10dcbf6389980ce3594547939bbc685363d28adbd6a05bc4abd7fc62e7693a1f6e33569fed5a380bfecb56ae811d25939b95823f39bb0f16a08740629d066d43');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when UTF8', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512('中文')).to.be('2f6a1bd50562230229af34b0ccf46b8754b89d23ae2c5bf7840b4acfcef86f87395edc0a00b2bfef53bafebe3b79de2e3e01cbd8169ddbb08bde888dcc893524');
|
||||
expect(keccak_512('aécio')).to.be('c452ec93e83d4795fcab62a76eed0d88f2231a995ce108ac8f130246f87c4a11cb18a2c1a688a5695906a6f863e71bbe8997c6610319ab97f12d2e5bf0afe458');
|
||||
expect(keccak_512('𠜎')).to.be('8a2d72022ce19d989dbe6a0017faccbf5dc2e22c162d1c5eb168864d32dd1a71e1b4782652c148cf6ca47b77a72c96fff682e72bdfef0566d4b7cca3c9ccc59d');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('6a67c28aa1946ca1be8382b861aac4aaf20052f495db9b6902d13adfa603eaba5d169f8896b86d461b2949283eb98e503c3f0640188ea7d6731526fc06568d37');
|
||||
expect(keccak_512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('d04ff5b0e85e9968be2a4d4e133c15c7ccee7497198bb651599a97d11d00bca6048d329ab75aa454566cd532648fa1cb4551985d9d645de9fa43a311a9ee8e4d');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when special length', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512('012345678901234567890123456789012345678901234567890123456789012345678901')).to.be('90b1d032c3bf06dcc78a46fe52054bab1250600224bfc6dfbfb40a7877c55e89bb982799a2edf198568a4166f6736678b45e76b12fac813cfdf0a76714e5eae8');
|
||||
expect(keccak_512('01234567890123456789012345678901234567890123456789012345678901234567890')).to.be('3173e7abc754a0b2909410d78986428a9183e996864af02f421d273d9fa1b4e4a5b14e2998b20767712f53a01ff8f6ae2c3e71e51e2c0f24257b03e6da09eb77');
|
||||
});
|
||||
});
|
||||
|
||||
context('when Array', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512([])).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e');
|
||||
expect(keccak_512([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])).to.be('d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609');
|
||||
});
|
||||
});
|
||||
|
||||
context('when Uint8Array', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512(new Uint8Array([]))).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e');
|
||||
expect(keccak_512(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]))).to.be('d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609');
|
||||
});
|
||||
});
|
||||
|
||||
context('when ArrayBuffer', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512(new ArrayBuffer(0))).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e');
|
||||
});
|
||||
});
|
||||
|
||||
context('when output ArrayBuffer', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512.buffer('').toHexString()).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e');
|
||||
});
|
||||
});
|
||||
|
||||
context('when output Array', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_512.array('').toHexString()).to.be('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('keccak_384', function() {
|
||||
context('when ascii', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_384('')).to.be('2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff');
|
||||
expect(keccak_384('The quick brown fox jumps over the lazy dog')).to.be('283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3');
|
||||
expect(keccak_384('The quick brown fox jumps over the lazy dog.')).to.be('9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_384('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('e7ec8976b4d96e43f50ae8ecdcf2d97a56236e6406e8dd00efd0d9abe885659db58a2f4b138a4ecfb1bd0052f6569516');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when UTF8', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_384('中文')).to.be('743f64bb7544c6ed923be4741b738dde18b7cee384a3a09c4e01acaaac9f19222cdee137702bd3aa05dc198373d87d6c');
|
||||
expect(keccak_384('aécio')).to.be('08990555e131af8597687614309da4c5053ce866f348544da0a0c2c78c2cc79680ebb57cfbe238286e78ea133a037897');
|
||||
expect(keccak_384('𠜎')).to.be('2a80f59abf3111f38a35a3daa25123b495f90e9736bd300e35911d19abdd8806498c581333f198ccbbf2252b57c2925d');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('a3b043a2f69e4326a05d478fa4c8aa2bd7612453d775af37665a0b96ef2207cdc74c50cdba1629796a5136fe77300b05');
|
||||
expect(keccak_384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('66414c090cc3fe9c396d313cbaa100aefd335e851838b29382568b7f57357ada7c54b8fa8c17f859945bba88b2c2e332');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('keccak_256', function() {
|
||||
context('when ascii', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_256('')).to.be('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470');
|
||||
expect(keccak_256('The quick brown fox jumps over the lazy dog')).to.be('4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15');
|
||||
expect(keccak_256('The quick brown fox jumps over the lazy dog.')).to.be('578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_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('af20018353ffb50d507f1555580f5272eca7fdab4f8295db4b1a9ad832c93f6d');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when UTF8', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_256('中文')).to.be('70a2b6579047f0a977fcb5e9120a4e07067bea9abb6916fbc2d13ffb9a4e4eee');
|
||||
expect(keccak_256('aécio')).to.be('d7d569202f04daf90432810d6163112b2695d7820da979327ebd894efb0276dc');
|
||||
expect(keccak_256('𠜎')).to.be('16a7cc7a58444cbf7e939611910ddc82e7cba65a99d3e8e08cfcda53180a2180');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('d1021d2d4c5c7e88098c40f422af68493b4b64c913cbd68220bf5e6127c37a88');
|
||||
expect(keccak_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('ffabf9bba2127c4928d360c9905cb4911f0ec21b9c3b89f3b242bccc68389e36');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('keccak_224', function() {
|
||||
context('when ascii', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_224('')).to.be('f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd');
|
||||
expect(keccak_224('The quick brown fox jumps over the lazy dog')).to.be('310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe');
|
||||
expect(keccak_224('The quick brown fox jumps over the lazy dog.')).to.be('c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_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('8dd58b706e3a08ec4f1f202af39295b38c355a39b23308ade7218a21');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when UTF8', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_224('中文')).to.be('7bc2a0b6e7e0a055a61e4f731e2944b560f41ff98967dcbf4bbf77a5');
|
||||
expect(keccak_224('aécio')).to.be('66f3db76bf8cb35726cb278bac412d187c3484ab2083dc50ef5ffb55');
|
||||
expect(keccak_224('𠜎')).to.be('3bfa94845726f4cd5cf17d19b5eacac17b3694790e13a76d5c81c7c2');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(keccak_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('d59eef8f394ef7d96967bb0bde578785c033f7f0a21913d6ba41ed1b');
|
||||
expect(keccak_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('27123a2a3860d1041d4769778c4b078732bf4300f7e1c56536ab2644');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})(keccak_512, keccak_384, keccak_256, keccak_224);
|
||||
@@ -0,0 +1,92 @@
|
||||
(function(shake_256, shake_128) {
|
||||
describe('shake_128', function() {
|
||||
context('with 256 output', function() {
|
||||
it('should be equal', function() {
|
||||
expect(shake_128('', 256)).to.be('7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26');
|
||||
expect(shake_128('The quick brown fox jumps over the lazy dog', 256)).to.be('f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66e');
|
||||
expect(shake_128('The quick brown fox jumps over the lazy dof', 256)).to.be('853f4538be0db9621a6cea659a06c1107b1f83f02b13d18297bd39d7411cf10c');
|
||||
});
|
||||
});
|
||||
|
||||
context('with 8 output', function() {
|
||||
it('should be equal', function() {
|
||||
expect(shake_128('', 8)).to.be('7f');
|
||||
expect(shake_128('The quick brown fox jumps over the lazy dog', 8)).to.be('f4');
|
||||
expect(shake_128('The quick brown fox jumps over the lazy dof', 8)).to.be('85');
|
||||
});
|
||||
});
|
||||
|
||||
context('with more output', function() {
|
||||
it('should be equal', function() {
|
||||
expect(shake_128('', 16)).to.be('7f9c');
|
||||
expect(shake_128('', 24)).to.be('7f9c2b');
|
||||
expect(shake_128.array('', 16)).to.eql([0x7f, 0x9c]);
|
||||
expect(shake_128.array('', 24)).to.eql([0x7f, 0x9c, 0x2b]);
|
||||
});
|
||||
});
|
||||
|
||||
context('with 8 output ArrayBuffer', function() {
|
||||
it('should be equal', function() {
|
||||
expect(shake_128.buffer('', 8).toHexString()).to.be('7f');
|
||||
expect(shake_128.buffer('The quick brown fox jumps over the lazy dog', 8).toHexString()).to.be('f4');
|
||||
expect(shake_128.buffer('The quick brown fox jumps over the lazy dof', 8).toHexString()).to.be('85');
|
||||
});
|
||||
});
|
||||
|
||||
context('with 4100 output ArrayBuffer', function() {
|
||||
it('should be equal', function() {
|
||||
// https://raw.githubusercontent.com/gvanas/KeccakCodePackage/master/TestVectors/ShortMsgKAT_SHAKE256.txt
|
||||
// Len = 0, Msg = 00
|
||||
expect(shake_256.buffer('', 4100).toHexString()).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a');
|
||||
|
||||
// Len = 2040
|
||||
// Msg = 3A3A819C48EFDE2AD914FBF00E18AB6BC4F14513AB27D0C178A188B61431E7F5623CB66B23346775D386B50E982C493ADBBFC54B9A3CD383382336A1A0B2150A15358F336D03AE18F666C7573D55C4FD181C29E6CCFDE63EA35F0ADF5885CFC0A3D84A2B2E4DD24496DB789E663170CEF74798AA1BBCD4574EA0BBA40489D764B2F83AADC66B148B4A0CD95246C127D5871C4F11418690A5DDF01246A0C80A43C70088B6183639DCFDA4125BD113A8F49EE23ED306FAAC576C3FB0C1E256671D817FC2534A52F5B439F72E424DE376F4C565CCA82307DD9EF76DA5B7C4EB7E085172E328807C02D011FFBF33785378D79DC266F6A5BE6BB0E4A92ECEEBAEB1
|
||||
expect(shake_256.buffer([0x3A,0x3A,0x81,0x9C,0x48,0xEF,0xDE,0x2A,0xD9,0x14,0xFB,0xF0,0x0E,0x18,0xAB,0x6B,0xC4,0xF1,0x45,0x13,0xAB,0x27,0xD0,0xC1,0x78,0xA1,0x88,0xB6,0x14,0x31,0xE7,0xF5,0x62,0x3C,0xB6,0x6B,0x23,0x34,0x67,0x75,0xD3,0x86,0xB5,0x0E,0x98,0x2C,0x49,0x3A,0xDB,0xBF,0xC5,0x4B,0x9A,0x3C,0xD3,0x83,0x38,0x23,0x36,0xA1,0xA0,0xB2,0x15,0x0A,0x15,0x35,0x8F,0x33,0x6D,0x03,0xAE,0x18,0xF6,0x66,0xC7,0x57,0x3D,0x55,0xC4,0xFD,0x18,0x1C,0x29,0xE6,0xCC,0xFD,0xE6,0x3E,0xA3,0x5F,0x0A,0xDF,0x58,0x85,0xCF,0xC0,0xA3,0xD8,0x4A,0x2B,0x2E,0x4D,0xD2,0x44,0x96,0xDB,0x78,0x9E,0x66,0x31,0x70,0xCE,0xF7,0x47,0x98,0xAA,0x1B,0xBC,0xD4,0x57,0x4E,0xA0,0xBB,0xA4,0x04,0x89,0xD7,0x64,0xB2,0xF8,0x3A,0xAD,0xC6,0x6B,0x14,0x8B,0x4A,0x0C,0xD9,0x52,0x46,0xC1,0x27,0xD5,0x87,0x1C,0x4F,0x11,0x41,0x86,0x90,0xA5,0xDD,0xF0,0x12,0x46,0xA0,0xC8,0x0A,0x43,0xC7,0x00,0x88,0xB6,0x18,0x36,0x39,0xDC,0xFD,0xA4,0x12,0x5B,0xD1,0x13,0xA8,0xF4,0x9E,0xE2,0x3E,0xD3,0x06,0xFA,0xAC,0x57,0x6C,0x3F,0xB0,0xC1,0xE2,0x56,0x67,0x1D,0x81,0x7F,0xC2,0x53,0x4A,0x52,0xF5,0xB4,0x39,0xF7,0x2E,0x42,0x4D,0xE3,0x76,0xF4,0xC5,0x65,0xCC,0xA8,0x23,0x07,0xDD,0x9E,0xF7,0x6D,0xA5,0xB7,0xC4,0xEB,0x7E,0x08,0x51,0x72,0xE3,0x28,0x80,0x7C,0x02,0xD0,0x11,0xFF,0xBF,0x33,0x78,0x53,0x78,0xD7,0x9D,0xC2,0x66,0xF6,0xA5,0xBE,0x6B,0xB0,0xE4,0xA9,0x2E,0xCE,0xEB,0xAE,0xB1], 4100).toHexString()).to.be('8a5199b4a7e133e264a86202720655894d48cff344a928cf8347f48379cef347dfc5bcffab99b27b1f89aa2735e23d30088ffa03b9edb02b9635470ab9f1038985d55f9ca774572dd006470ea65145469609f9fa0831bf1ffd842dc24acade27bd9816e3b5bf2876cb112232a0eb4475f1dff9f5c713d9ffd4ccb89ae5607fe35731df06317949eef646e9591cf3be53add6b7dd2b6096e2b3fb06e662ec8b2d77422daad9463cd155204acdbd38e319613f39f99b6dfb35ca9365160066db19835888c2241ff9a731a4acbb5663727aac34a401247fbaa7499e7d5ee5b69d31025e63d04c35c798bca1262d5673a9cf0930b5ad89bd485599dc184528da4790f088ebd170b635d9581632d2ff90db79665ced430089af13c9f21f6d443a818064f17aec9e9c5457001fa8dc6afbadbe3138f388d89d0e6f22f66671255b210754ed63d81dce75ce8f189b534e6d6b3539aa51e837c42df9df59c71e6171cd4902fe1bdc73fb1775b5c754a1ed4ea7f3105fc543ee0418dad256f3f6118ea77114a16c15355b42877a1db2a7df0e155ae1d8670abcec3450f4e2eec9838f895423ef63d261138baaf5d9f104cb5a957aea06c0b9b8c78b0d441796dc0350ddeabb78a33b6f1f9e68ede3d1805c7b7e2cfd54e0fad62f0d8ca67a775dc4546af9096f2edb221db42843d65327861282dc946a0ba01a11863ab2d1dfd16e3973d4');
|
||||
});
|
||||
});
|
||||
|
||||
context('with 4100 output Array', function() {
|
||||
it('should be equal', function() {
|
||||
// https://raw.githubusercontent.com/gvanas/KeccakCodePackage/master/TestVectors/ShortMsgKAT_SHAKE256.txt
|
||||
// Len = 0, Msg = 00
|
||||
expect(shake_256.array('', 4100).toHexString()).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a');
|
||||
|
||||
// Len = 2040
|
||||
// Msg = 3A3A819C48EFDE2AD914FBF00E18AB6BC4F14513AB27D0C178A188B61431E7F5623CB66B23346775D386B50E982C493ADBBFC54B9A3CD383382336A1A0B2150A15358F336D03AE18F666C7573D55C4FD181C29E6CCFDE63EA35F0ADF5885CFC0A3D84A2B2E4DD24496DB789E663170CEF74798AA1BBCD4574EA0BBA40489D764B2F83AADC66B148B4A0CD95246C127D5871C4F11418690A5DDF01246A0C80A43C70088B6183639DCFDA4125BD113A8F49EE23ED306FAAC576C3FB0C1E256671D817FC2534A52F5B439F72E424DE376F4C565CCA82307DD9EF76DA5B7C4EB7E085172E328807C02D011FFBF33785378D79DC266F6A5BE6BB0E4A92ECEEBAEB1
|
||||
expect(shake_256.array([0x3A,0x3A,0x81,0x9C,0x48,0xEF,0xDE,0x2A,0xD9,0x14,0xFB,0xF0,0x0E,0x18,0xAB,0x6B,0xC4,0xF1,0x45,0x13,0xAB,0x27,0xD0,0xC1,0x78,0xA1,0x88,0xB6,0x14,0x31,0xE7,0xF5,0x62,0x3C,0xB6,0x6B,0x23,0x34,0x67,0x75,0xD3,0x86,0xB5,0x0E,0x98,0x2C,0x49,0x3A,0xDB,0xBF,0xC5,0x4B,0x9A,0x3C,0xD3,0x83,0x38,0x23,0x36,0xA1,0xA0,0xB2,0x15,0x0A,0x15,0x35,0x8F,0x33,0x6D,0x03,0xAE,0x18,0xF6,0x66,0xC7,0x57,0x3D,0x55,0xC4,0xFD,0x18,0x1C,0x29,0xE6,0xCC,0xFD,0xE6,0x3E,0xA3,0x5F,0x0A,0xDF,0x58,0x85,0xCF,0xC0,0xA3,0xD8,0x4A,0x2B,0x2E,0x4D,0xD2,0x44,0x96,0xDB,0x78,0x9E,0x66,0x31,0x70,0xCE,0xF7,0x47,0x98,0xAA,0x1B,0xBC,0xD4,0x57,0x4E,0xA0,0xBB,0xA4,0x04,0x89,0xD7,0x64,0xB2,0xF8,0x3A,0xAD,0xC6,0x6B,0x14,0x8B,0x4A,0x0C,0xD9,0x52,0x46,0xC1,0x27,0xD5,0x87,0x1C,0x4F,0x11,0x41,0x86,0x90,0xA5,0xDD,0xF0,0x12,0x46,0xA0,0xC8,0x0A,0x43,0xC7,0x00,0x88,0xB6,0x18,0x36,0x39,0xDC,0xFD,0xA4,0x12,0x5B,0xD1,0x13,0xA8,0xF4,0x9E,0xE2,0x3E,0xD3,0x06,0xFA,0xAC,0x57,0x6C,0x3F,0xB0,0xC1,0xE2,0x56,0x67,0x1D,0x81,0x7F,0xC2,0x53,0x4A,0x52,0xF5,0xB4,0x39,0xF7,0x2E,0x42,0x4D,0xE3,0x76,0xF4,0xC5,0x65,0xCC,0xA8,0x23,0x07,0xDD,0x9E,0xF7,0x6D,0xA5,0xB7,0xC4,0xEB,0x7E,0x08,0x51,0x72,0xE3,0x28,0x80,0x7C,0x02,0xD0,0x11,0xFF,0xBF,0x33,0x78,0x53,0x78,0xD7,0x9D,0xC2,0x66,0xF6,0xA5,0xBE,0x6B,0xB0,0xE4,0xA9,0x2E,0xCE,0xEB,0xAE,0xB1], 4100).toHexString()).to.be('8a5199b4a7e133e264a86202720655894d48cff344a928cf8347f48379cef347dfc5bcffab99b27b1f89aa2735e23d30088ffa03b9edb02b9635470ab9f1038985d55f9ca774572dd006470ea65145469609f9fa0831bf1ffd842dc24acade27bd9816e3b5bf2876cb112232a0eb4475f1dff9f5c713d9ffd4ccb89ae5607fe35731df06317949eef646e9591cf3be53add6b7dd2b6096e2b3fb06e662ec8b2d77422daad9463cd155204acdbd38e319613f39f99b6dfb35ca9365160066db19835888c2241ff9a731a4acbb5663727aac34a401247fbaa7499e7d5ee5b69d31025e63d04c35c798bca1262d5673a9cf0930b5ad89bd485599dc184528da4790f088ebd170b635d9581632d2ff90db79665ced430089af13c9f21f6d443a818064f17aec9e9c5457001fa8dc6afbadbe3138f388d89d0e6f22f66671255b210754ed63d81dce75ce8f189b534e6d6b3539aa51e837c42df9df59c71e6171cd4902fe1bdc73fb1775b5c754a1ed4ea7f3105fc543ee0418dad256f3f6118ea77114a16c15355b42877a1db2a7df0e155ae1d8670abcec3450f4e2eec9838f895423ef63d261138baaf5d9f104cb5a957aea06c0b9b8c78b0d441796dc0350ddeabb78a33b6f1f9e68ede3d1805c7b7e2cfd54e0fad62f0d8ca67a775dc4546af9096f2edb221db42843d65327861282dc946a0ba01a11863ab2d1dfd16e3973d4');
|
||||
});
|
||||
});
|
||||
|
||||
context('#update', function() {
|
||||
it('should be equal', function() {
|
||||
expect(shake_128.update('', 256).hex()).to.be('7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26');
|
||||
expect(shake_128.update('The quick brown fox ', 256).update('jumps over the lazy dog').hex()).to.be('f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66e');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('shake_256', function() {
|
||||
context('with 512 output', function() {
|
||||
it('should be equal', function() {
|
||||
expect(shake_256('', 512)).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be');
|
||||
});
|
||||
});
|
||||
context('with 8 output', function() {
|
||||
it('should be equal', function() {
|
||||
expect(shake_256('', 8)).to.be('46');
|
||||
});
|
||||
});
|
||||
|
||||
context('with 4100 output', function() {
|
||||
it('should be equal', function() {
|
||||
// https://raw.githubusercontent.com/gvanas/KeccakCodePackage/master/TestVectors/ShortMsgKAT_SHAKE256.txt
|
||||
// Len = 0, Msg = 00
|
||||
expect(shake_256('', 4100)).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a');
|
||||
|
||||
// Len = 2040
|
||||
// Msg = 3A3A819C48EFDE2AD914FBF00E18AB6BC4F14513AB27D0C178A188B61431E7F5623CB66B23346775D386B50E982C493ADBBFC54B9A3CD383382336A1A0B2150A15358F336D03AE18F666C7573D55C4FD181C29E6CCFDE63EA35F0ADF5885CFC0A3D84A2B2E4DD24496DB789E663170CEF74798AA1BBCD4574EA0BBA40489D764B2F83AADC66B148B4A0CD95246C127D5871C4F11418690A5DDF01246A0C80A43C70088B6183639DCFDA4125BD113A8F49EE23ED306FAAC576C3FB0C1E256671D817FC2534A52F5B439F72E424DE376F4C565CCA82307DD9EF76DA5B7C4EB7E085172E328807C02D011FFBF33785378D79DC266F6A5BE6BB0E4A92ECEEBAEB1
|
||||
expect(shake_256([0x3A,0x3A,0x81,0x9C,0x48,0xEF,0xDE,0x2A,0xD9,0x14,0xFB,0xF0,0x0E,0x18,0xAB,0x6B,0xC4,0xF1,0x45,0x13,0xAB,0x27,0xD0,0xC1,0x78,0xA1,0x88,0xB6,0x14,0x31,0xE7,0xF5,0x62,0x3C,0xB6,0x6B,0x23,0x34,0x67,0x75,0xD3,0x86,0xB5,0x0E,0x98,0x2C,0x49,0x3A,0xDB,0xBF,0xC5,0x4B,0x9A,0x3C,0xD3,0x83,0x38,0x23,0x36,0xA1,0xA0,0xB2,0x15,0x0A,0x15,0x35,0x8F,0x33,0x6D,0x03,0xAE,0x18,0xF6,0x66,0xC7,0x57,0x3D,0x55,0xC4,0xFD,0x18,0x1C,0x29,0xE6,0xCC,0xFD,0xE6,0x3E,0xA3,0x5F,0x0A,0xDF,0x58,0x85,0xCF,0xC0,0xA3,0xD8,0x4A,0x2B,0x2E,0x4D,0xD2,0x44,0x96,0xDB,0x78,0x9E,0x66,0x31,0x70,0xCE,0xF7,0x47,0x98,0xAA,0x1B,0xBC,0xD4,0x57,0x4E,0xA0,0xBB,0xA4,0x04,0x89,0xD7,0x64,0xB2,0xF8,0x3A,0xAD,0xC6,0x6B,0x14,0x8B,0x4A,0x0C,0xD9,0x52,0x46,0xC1,0x27,0xD5,0x87,0x1C,0x4F,0x11,0x41,0x86,0x90,0xA5,0xDD,0xF0,0x12,0x46,0xA0,0xC8,0x0A,0x43,0xC7,0x00,0x88,0xB6,0x18,0x36,0x39,0xDC,0xFD,0xA4,0x12,0x5B,0xD1,0x13,0xA8,0xF4,0x9E,0xE2,0x3E,0xD3,0x06,0xFA,0xAC,0x57,0x6C,0x3F,0xB0,0xC1,0xE2,0x56,0x67,0x1D,0x81,0x7F,0xC2,0x53,0x4A,0x52,0xF5,0xB4,0x39,0xF7,0x2E,0x42,0x4D,0xE3,0x76,0xF4,0xC5,0x65,0xCC,0xA8,0x23,0x07,0xDD,0x9E,0xF7,0x6D,0xA5,0xB7,0xC4,0xEB,0x7E,0x08,0x51,0x72,0xE3,0x28,0x80,0x7C,0x02,0xD0,0x11,0xFF,0xBF,0x33,0x78,0x53,0x78,0xD7,0x9D,0xC2,0x66,0xF6,0xA5,0xBE,0x6B,0xB0,0xE4,0xA9,0x2E,0xCE,0xEB,0xAE,0xB1], 4100)).to.be('8a5199b4a7e133e264a86202720655894d48cff344a928cf8347f48379cef347dfc5bcffab99b27b1f89aa2735e23d30088ffa03b9edb02b9635470ab9f1038985d55f9ca774572dd006470ea65145469609f9fa0831bf1ffd842dc24acade27bd9816e3b5bf2876cb112232a0eb4475f1dff9f5c713d9ffd4ccb89ae5607fe35731df06317949eef646e9591cf3be53add6b7dd2b6096e2b3fb06e662ec8b2d77422daad9463cd155204acdbd38e319613f39f99b6dfb35ca9365160066db19835888c2241ff9a731a4acbb5663727aac34a401247fbaa7499e7d5ee5b69d31025e63d04c35c798bca1262d5673a9cf0930b5ad89bd485599dc184528da4790f088ebd170b635d9581632d2ff90db79665ced430089af13c9f21f6d443a818064f17aec9e9c5457001fa8dc6afbadbe3138f388d89d0e6f22f66671255b210754ed63d81dce75ce8f189b534e6d6b3539aa51e837c42df9df59c71e6171cd4902fe1bdc73fb1775b5c754a1ed4ea7f3105fc543ee0418dad256f3f6118ea77114a16c15355b42877a1db2a7df0e155ae1d8670abcec3450f4e2eec9838f895423ef63d261138baaf5d9f104cb5a957aea06c0b9b8c78b0d441796dc0350ddeabb78a33b6f1f9e68ede3d1805c7b7e2cfd54e0fad62f0d8ca67a775dc4546af9096f2edb221db42843d65327861282dc946a0ba01a11863ab2d1dfd16e3973d4');
|
||||
});
|
||||
});
|
||||
});
|
||||
})(shake_256, shake_128);
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
(function(sha3_512, sha3_384, sha3_256, sha3_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;
|
||||
};
|
||||
describe('sha3_512', function() {
|
||||
context('when ascii', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512('')).to.be('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
|
||||
expect(sha3_512('The quick brown fox jumps over the lazy dog')).to.be('01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450');
|
||||
expect(sha3_512('The quick brown fox jumps over the lazy dog.')).to.be('18f4f4bd419603f95538837003d9d254c26c23765565162247483f65c50303597bc9ce4d289f21d1c2f1f458828e33dc442100331b35e7eb031b5d38ba6460f8');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512('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('4f8bcf3a60d3ee56a0bd405c3e6bb37dac44b6781c41bf76c91a5d8e621d472b7b13b8806d88914af3d97585df996363ebe17566d5dfeb6f4884a7949ba8263d');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when UTF8', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512('中文')).to.be('059bbe2efc50cc30e4d8ec5a96be697e2108fcbf9193e1296192eddabc13b143c0120d059399a13d0d42651efe23a6c1ce2d1efb576c5b207fa2516050505af7');
|
||||
expect(sha3_512('aécio')).to.be('35dfaf82d2ce4be79393dc90e327b4dd15b1c150d8a30f59d8d1b42ca4fc3c87f50b77da36acccf9dc76494d07fc57cfcc9470e627c38f95bce4deab311b87e0');
|
||||
expect(sha3_512('𠜎')).to.be('33ef254289f36527c93cd203ef1973aec1eff7475c23fa842c3092b0d30965d13b0805c61d0aa92c51245c56bfe26978c35c00f26eb558a043982043ee8b178c');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('accb127bb24b0ffbb7550dc637222d2f78538a8a186c98bc5efdad685b9b396639f34148bf0b94ed470f0e9c3665dc3b4c1cb321bacd32dd317a646295e073d9');
|
||||
expect(sha3_512('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('5b70eaad083f1b86fd535b6812e02f5f2876a4bd8b43aede8d62ae71bb1743ebd919dc41be56d73ba45b67b2876ff215d0575788560e7b0c92b879f8a2fc3111');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when special length', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512('012345678901234567890123456789012345678901234567890123456789012345678901')).to.be('bce9da5b408846edd5bec9f26c2dee9bd835215c3f2b3876197067d87bc4d1af0cd97f94fda59761a0d804fe82383be2c6c4886fbb82e005fcf899449029f221');
|
||||
expect(sha3_512('01234567890123456789012345678901234567890123456789012345678901234567890')).to.be('8bdcb85e6b52c29fafac0d3daf65492f2e3499e066da1a095a65eb1144849a26b2790a8b39c2a7fb747456f749391d953841a61cb13289f9806f04981c180a86');
|
||||
});
|
||||
});
|
||||
|
||||
context('when Array', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512([])).to.be('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
|
||||
expect(sha3_512([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])).to.be('01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450');
|
||||
});
|
||||
});
|
||||
|
||||
context('when Uint8Array', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512(new Uint8Array([]))).to.be('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
|
||||
expect(sha3_512(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]))).to.be('01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450');
|
||||
});
|
||||
});
|
||||
|
||||
context('when ArrayBuffer', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512(new ArrayBuffer(0))).to.be('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
|
||||
});
|
||||
});
|
||||
|
||||
context('when output ArrayBuffer', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512.buffer('').toHexString()).to.be('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
|
||||
});
|
||||
});
|
||||
|
||||
context('#hex', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512.hex('')).to.be('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
|
||||
});
|
||||
});
|
||||
|
||||
context('#update', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_512.update('').hex()).to.be('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
|
||||
expect(sha3_512.update('The quick brown fox ').update('jumps over the lazy dog').hex()).to.be('01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450');
|
||||
});
|
||||
});
|
||||
|
||||
context('#create', function() {
|
||||
it('should be equal', function() {
|
||||
var bytes = [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 hash = sha3_512.create();
|
||||
for(var i = 0;i < bytes.length;++i) {
|
||||
hash.update([bytes[i]]);
|
||||
}
|
||||
expect(hash.hex()).to.be('01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sha3_384', function() {
|
||||
context('when ascii', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_384('')).to.be('0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004');
|
||||
expect(sha3_384('The quick brown fox jumps over the lazy dog')).to.be('7063465e08a93bce31cd89d2e3ca8f602498696e253592ed26f07bf7e703cf328581e1471a7ba7ab119b1a9ebdf8be41');
|
||||
expect(sha3_384('The quick brown fox jumps over the lazy dog.')).to.be('1a34d81695b622df178bc74df7124fe12fac0f64ba5250b78b99c1273d4b080168e10652894ecad5f1f4d5b965437fb9');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_384('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('ca6b121a6060bc85de05e5a8d70577838fad2481b092c8263d6f7bcbe5148740f0c7f9c4dc27061339570496956aaef6');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when UTF8', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_384('中文')).to.be('9fb5b99e3c546f2738dcd50a14e9aef9c313800c1bf8cf76bc9b2c3a23307841364c5a2d0794702662c5796fb72f5432');
|
||||
expect(sha3_384('aécio')).to.be('70b447f1bd5ce5a4753ccf7a3697eca0315954774374bc1042aff19582ccc32d5067f7da6c2bea9d6d344e11924cbe72');
|
||||
expect(sha3_384('𠜎')).to.be('7add8d544b0a7cf188b54b1697a046f77e49d5f292e7ffe56feeed90a500b0bf026b9b68892888a1bafb9f8cb89ed874');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('7d0f80fe5c79a04a2a37a30a440e0cc068eb78fe6c3182246ede29645c144b5d33c44607cb2c3111ba77ffc66107f1cd');
|
||||
expect(sha3_384('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('e344b95c6a961a27793eff00fa5103ef78b4180fe41c93fc60a31aff49b3b5e95a92c84fda9a6c80fa403b7df58db59f');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sha3_256', function() {
|
||||
context('when ascii', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_256('')).to.be('a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a');
|
||||
expect(sha3_256('The quick brown fox jumps over the lazy dog')).to.be('69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04');
|
||||
expect(sha3_256('The quick brown fox jumps over the lazy dog.')).to.be('a80f839cd4f83f6c3dafc87feae470045e4eb0d366397d5c6ce34ba1739f734d');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_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('fa198893674a0bf9fb35980504e8cefb250aabd2311a37e5d2205f07fb023d36');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when UTF8', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_256('中文')).to.be('ac5305da3d18be1aed44aa7c70ea548da243a59a5fd546f489348fd5718fb1a0');
|
||||
expect(sha3_256('aécio')).to.be('65c756408eb6c35a1ffa2d7e09711bdc9f0b28716b1376223844a2b4c52b6718');
|
||||
expect(sha3_256('𠜎')).to.be('babe9afc555b0311700dfb0b5b6296d49347b3d770480baedfcdc47a4aea6e82');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('4b2f36e4320b86e6ead0ad001e47e6d9e7fcf0044cd5a5fd65490a633c0372a4');
|
||||
expect(sha3_256('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('558a7f843b1ac5e7a8bbef90357876bcce0612992d0dfa2907e95521612f507f');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sha3_224', function() {
|
||||
context('when ascii', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_224('')).to.be('6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7');
|
||||
expect(sha3_224('The quick brown fox jumps over the lazy dog')).to.be('d15dadceaa4d5d7bb3b48f446421d542e08ad8887305e28d58335795');
|
||||
expect(sha3_224('The quick brown fox jumps over the lazy dog.')).to.be('2d0708903833afabdd232a20201176e8b58c5be8a6fe74265ac54db0');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_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('06885009a28e43e15bf1af718561ad211515a27b542eabc36764a0ca');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('when UTF8', function() {
|
||||
context('and less than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_224('中文')).to.be('106d169e10b61c2a2a05554d3e631ec94467f8316640f29545d163ee');
|
||||
expect(sha3_224('aécio')).to.be('b16bad54608dc01864a5d7510d4c19b09f3a0f39cfc4ba1e53aa952a');
|
||||
expect(sha3_224('𠜎')).to.be('f59253c41cb87e5cd953311656716cb5b64dbafc9e8155f0dd68123c');
|
||||
});
|
||||
});
|
||||
|
||||
context('and more than 128 bytes', function() {
|
||||
it('should be equal', function() {
|
||||
expect(sha3_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一')).to.be('135c13deb71fdf6fb77b52b720c43ddd6ce7467f9147a74248557114');
|
||||
expect(sha3_224('訊息摘要演算法第五版(英語:Message-Digest Algorithm 5,縮寫為MD5),是當前電腦領域用於確保資訊傳輸完整一致而廣泛使用的雜湊演算法之一(又譯雜湊演算法、摘要演算法等),主流程式語言普遍已有MD5的實作。')).to.be('bd05581e02445c53e05aad2014f6a3819d77a9dff918b8c6bf60bd06');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})(sha3_512, sha3_384, sha3_256, sha3_224);
|
||||
Reference in New Issue
Block a user