Compare commits
37 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
6efde1cf1b | 2 years ago |
![]() |
a6f6da7483 | 2 years ago |
![]() |
707ee7ced1 | 2 years ago |
![]() |
59caf17eca | 2 years ago |
![]() |
d6325442bd | 2 years ago |
![]() |
f293b5d508 | 2 years ago |
![]() |
dbb0ea401f | 2 years ago |
![]() |
5aecbd6968 | 2 years ago |
![]() |
b39d0910cb | 7 years ago |
![]() |
1c00d97268 | 7 years ago |
![]() |
fb7e6403d9 | 8 years ago |
![]() |
c43f9d1d18 | 8 years ago |
![]() |
94a2758bf7 | 8 years ago |
![]() |
540bbee16b | 8 years ago |
![]() |
e9084afbdf | 8 years ago |
![]() |
5d6193d7f2 | 9 years ago |
![]() |
8ae70989ae | 9 years ago |
![]() |
035642212a | 9 years ago |
![]() |
9f8c2a3fb3 | 9 years ago |
![]() |
ec2a9948f9 | 9 years ago |
![]() |
f34e33dc99 | 9 years ago |
![]() |
97e70fed97 | 9 years ago |
![]() |
bb08d1fc64 | 9 years ago |
![]() |
f0ff77ca47 | 9 years ago |
![]() |
06a3fa8f52 | 9 years ago |
![]() |
f22d720caa | 10 years ago |
![]() |
63f2823f49 | 10 years ago |
![]() |
fbedaa1f4c | 10 years ago |
![]() |
09db28deed | 10 years ago |
![]() |
ca56f2ac21 | 10 years ago |
![]() |
99d724b22a | 10 years ago |
![]() |
63a860bdf9 | 10 years ago |
![]() |
7423f9ef37 | 10 years ago |
![]() |
61300d2d34 | 10 years ago |
![]() |
0d1753fd8d | 10 years ago |
![]() |
7851f7ad68 | 10 years ago |
![]() |
db3ab779a8 | 10 years ago |
@ -1,2 +0,0 @@
|
||||
/tests/
|
||||
node_modules/
|
@ -1,3 +1,3 @@
|
||||
node_modules/
|
||||
covreporter
|
||||
my_test
|
||||
/node_modules/
|
||||
/coverage/
|
||||
/.nyc_output/
|
||||
|
@ -1,4 +1,7 @@
|
||||
my_test
|
||||
covreporter
|
||||
build
|
||||
tests
|
||||
/node_modules/
|
||||
/coverage/
|
||||
/.nyc_output/
|
||||
/tests/
|
||||
.travis.yml
|
||||
.npmignore
|
||||
bower.json
|
||||
|
@ -1,13 +1,10 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.11"
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
- "6.11.4"
|
||||
- "8.6.0"
|
||||
before_install:
|
||||
- npm install mocha -g
|
||||
- npm install coveralls -g
|
||||
- npm install mocha-lcov-reporter -g
|
||||
script: npm run-script coveralls
|
||||
- npm install coveralls
|
||||
after_success: npm run coveralls
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
@ -1,16 +1,125 @@
|
||||
# v0.2.0 / 2015-04-04
|
||||
# Change Log
|
||||
|
||||
* Implement NIST's May 2014 SHA-3 version.
|
||||
* Rename original methods to keccak.
|
||||
## v0.9.3 / 2023-12-16
|
||||
### Fixed
|
||||
- Fix error in arrayBuffer when there are extra bytes #37
|
||||
- fixed output if finalized.
|
||||
|
||||
# v0.1.2 / 2015-02-27
|
||||
## v0.9.2 / 2023-09-16
|
||||
### Fixed
|
||||
- don't modify global Array and ArrayBuffer prototypes. #33
|
||||
- refactor: simplify formatMessage internal logic. #34
|
||||
|
||||
* Improve performance.
|
||||
## v0.9.1 / 2023-08-31
|
||||
### Fixed
|
||||
- cSHAKE empty Array bug. #24
|
||||
|
||||
# v0.1.1 / 2015-02-26
|
||||
## v0.9.0 / 2023-08-30
|
||||
### Fixed
|
||||
- cSHAKE bug. #24
|
||||
- dependencies and security issues.
|
||||
|
||||
* Improve performance.
|
||||
## v0.8.0 / 2018-08-05
|
||||
### Added
|
||||
- TypeScript definitions.
|
||||
|
||||
# v0.1.0 / 2015-02-23
|
||||
### Changed
|
||||
- throw error if update after finalize
|
||||
|
||||
* Initial release
|
||||
## v0.7.0 / 2017-12-01
|
||||
### Added
|
||||
- AMD support.
|
||||
- support for web worker. #13
|
||||
|
||||
### Changed
|
||||
- throw error if input type is incorrect when cSHAKE and KMAC.
|
||||
- freeze hash after finalize.
|
||||
|
||||
## v0.6.1 / 2017-07-03
|
||||
### Fixed
|
||||
- Typo on variable kmac_256 type definition. #12
|
||||
|
||||
## v0.6.0 / 2017-06-15
|
||||
### Added
|
||||
- cSHAKE method.
|
||||
- KMAC method.
|
||||
- alias methods without underscore like shake128, keccak512.
|
||||
|
||||
### Changed
|
||||
- throw error if input type is incorrect.
|
||||
|
||||
## v0.5.7 / 2016-12-30
|
||||
### Fixed
|
||||
- ArrayBuffer detection in old browsers.
|
||||
|
||||
## v0.5.6 / 2016-12-29
|
||||
### Fixed
|
||||
- ArrayBuffer dosen't work in Webpack.
|
||||
|
||||
## v0.5.5 / 2016-09-26
|
||||
### Added
|
||||
- TypeScript support.
|
||||
- ArrayBuffer method.
|
||||
|
||||
### Deprecated
|
||||
- Buffer method.
|
||||
|
||||
## v0.5.4 / 2016-09-12
|
||||
### Fixed
|
||||
- CommonJS detection.
|
||||
|
||||
## v0.5.3 / 2016-09-08
|
||||
### Added
|
||||
- Some missing files to npm package.
|
||||
|
||||
## v0.5.2 / 2016-06-06
|
||||
### Fixed
|
||||
- Shake output incorrect in the special length.
|
||||
|
||||
## v0.5.1 / 2015-10-27
|
||||
### Fixed
|
||||
- Version in package.json and bower.json.
|
||||
|
||||
## v0.5.0 / 2015-09-23
|
||||
### Added
|
||||
- Hash object with create/update interface.
|
||||
|
||||
## v0.4.1 / 2015-09-18
|
||||
### Added
|
||||
- Integer array output.
|
||||
|
||||
### Fixed
|
||||
- Shake output incorrect when it's greater than 1088.
|
||||
|
||||
## v0.4.0 / 2015-09-17
|
||||
### Added
|
||||
- ArrayBuffer output.
|
||||
- Shake alogirthms.
|
||||
|
||||
## v0.3.1 / 2015-05-22
|
||||
### Fixed
|
||||
- Some bugs.
|
||||
|
||||
## v0.3.0 / 2015-05-21
|
||||
### Added
|
||||
- Integer array input.
|
||||
- ArrayBuffer input.
|
||||
|
||||
## v0.2.0 / 2015-04-04
|
||||
### Added
|
||||
- NIST's May 2014 SHA-3 version.
|
||||
|
||||
### Changed
|
||||
- Rename original methods to keccak.
|
||||
|
||||
## v0.1.2 / 2015-02-27
|
||||
### Changed
|
||||
- Improve performance.
|
||||
|
||||
## v0.1.1 / 2015-02-26
|
||||
### Changed
|
||||
- Improve performance.
|
||||
|
||||
## v0.1.0 / 2015-02-23
|
||||
### Added
|
||||
- First version implementation.
|
||||
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,317 @@
|
||||
type Message = string | number[] | ArrayBuffer | Uint8Array;
|
||||
|
||||
interface Hasher {
|
||||
/**
|
||||
* Update hash
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(message: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*/
|
||||
hex(): string;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/**
|
||||
* Return hash in ArrayBuffer.
|
||||
*/
|
||||
arrayBuffer(): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*/
|
||||
digest(): number[];
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*/
|
||||
array(): number[];
|
||||
}
|
||||
|
||||
interface Hash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
(message: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
hex(message: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
arrayBuffer(message: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
digest(message: Message): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
array(message: Message): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*/
|
||||
create(): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(message: Message): Hasher;
|
||||
}
|
||||
|
||||
interface ShakeHash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
(message: Message, outputBits: number): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
hex(message: Message, outputBits: number): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
arrayBuffer(message: Message, outputBits: number): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
digest(message: Message, outputBits: number): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
array(message: Message, outputBits: number): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*
|
||||
* @param outputBits The length of output.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
create(outputBits: number): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
update(message: Message, outputBits: number): Hasher;
|
||||
}
|
||||
|
||||
interface CshakeHash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
(message: Message, outputBits: number, functionName: Message, customization: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
hex(message: Message, outputBits: number, functionName: Message, customization: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
arrayBuffer(message: Message, outputBits: number, functionName: Message, customization: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
digest(message: Message, outputBits: number, functionName: Message, customization: Message): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
array(message: Message, outputBits: number, functionName: Message, customization: Message): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*
|
||||
* @param outputBits The length of output.
|
||||
* @param outputBits The length of output.
|
||||
*/
|
||||
create(outputBits: number): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
create(outputBits: number, functionName: Message, customization: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param functionName The function name string.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
update(message: Message, outputBits: number, functionName: Message, customization: Message): Hasher;
|
||||
}
|
||||
|
||||
interface KmacHash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
(key: Message, message: Message, outputBits: number, customization: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
hex(key: Message, message: Message, outputBits: number, customization: Message): string;
|
||||
|
||||
/**
|
||||
* Hash and return ArrayBuffer.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
arrayBuffer(key: Message, message: Message, outputBits: number, customization: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
digest(key: Message, message: Message, outputBits: number, customization: Message): number[];
|
||||
|
||||
/**
|
||||
* Hash and return integer array.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
array(key: Message, message: Message, outputBits: number, customization: Message): number[];
|
||||
|
||||
/**
|
||||
* Create a hash object.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
create(key: Message, outputBits: number, customization: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message.
|
||||
*
|
||||
* @param key The key string.
|
||||
* @param message The message you want to hash.
|
||||
* @param outputBits The length of output.
|
||||
* @param customization The customization string.
|
||||
*/
|
||||
update(key: Message, message: Message, outputBits: number, customization: Message): Hasher;
|
||||
}
|
||||
|
||||
export var sha3_512: Hash;
|
||||
export var sha3_384: Hash;
|
||||
export var sha3_256: Hash;
|
||||
export var sha3_224: Hash;
|
||||
export var keccak_512: Hash;
|
||||
export var keccak_384: Hash;
|
||||
export var keccak_256: Hash;
|
||||
export var keccak_224: Hash;
|
||||
export var keccak512: Hash;
|
||||
export var keccak384: Hash;
|
||||
export var keccak256: Hash;
|
||||
export var keccak224: Hash;
|
||||
export var shake_128: ShakeHash;
|
||||
export var shake_256: ShakeHash;
|
||||
export var shake128: ShakeHash;
|
||||
export var shake256: ShakeHash;
|
||||
export var cshake_128: CshakeHash;
|
||||
export var cshake_256: CshakeHash;
|
||||
export var cshake128: CshakeHash;
|
||||
export var cshake256: CshakeHash;
|
||||
export var kmac_128: KmacHash;
|
||||
export var kmac_256: KmacHash;
|
||||
export var kmac128: KmacHash;
|
||||
export var kmac256: KmacHash;
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,28 +1,150 @@
|
||||
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;
|
||||
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')]
|
||||
sha3_512 = null;
|
||||
sha3_384 = null;
|
||||
sha3_256 = null;
|
||||
sha3_224 = null;
|
||||
keccak_512 = null;
|
||||
keccak_384 = null;
|
||||
keccak_256 = null;
|
||||
keccak_224 = null;
|
||||
|
||||
JS_SHA3_TEST = true;
|
||||
Worker = require("tiny-worker");
|
||||
|
||||
function unset() {
|
||||
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;
|
||||
keccak512 = null;
|
||||
keccak384 = null;
|
||||
keccak256 = null;
|
||||
keccak224 = null;
|
||||
shake128 = null;
|
||||
shake256 = null;
|
||||
kmac128 = null;
|
||||
kmac256 = null;
|
||||
BUFFER = undefined;
|
||||
JS_SHA3_NO_WINDOW = undefined;
|
||||
JS_SHA3_NO_NODE_JS = undefined;
|
||||
JS_SHA3_NO_COMMON_JS = undefined;
|
||||
JS_SHA3_NO_ARRAY_BUFFER = undefined;
|
||||
JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW = undefined;
|
||||
window = undefined;
|
||||
}
|
||||
|
||||
function requireToGlobal() {
|
||||
var sha3 = require('../src/sha3.js');
|
||||
keccak512 = sha3.keccak512;
|
||||
keccak384 = sha3.keccak384;
|
||||
keccak256 = sha3.keccak256;
|
||||
keccak224 = sha3.keccak224;
|
||||
sha3_512 = sha3.sha3_512;
|
||||
sha3_384 = sha3.sha3_384;
|
||||
sha3_256 = sha3.sha3_256;
|
||||
sha3_224 = sha3.sha3_224;
|
||||
shake128 = sha3.shake128;
|
||||
shake256 = sha3.shake256;
|
||||
cshake128 = sha3.cshake128;
|
||||
cshake256 = sha3.cshake256;
|
||||
kmac128 = sha3.kmac128;
|
||||
kmac256 = sha3.kmac256;
|
||||
}
|
||||
|
||||
function runCommonJsTest() {
|
||||
requireToGlobal();
|
||||
require('./test.js');
|
||||
unset();
|
||||
}
|
||||
|
||||
function runWindowTest(extra) {
|
||||
window = global;
|
||||
require('../src/sha3.js');
|
||||
require('./test.js');
|
||||
if (extra) {
|
||||
require('./test-shake.js');
|
||||
require('./test-cshake.js');
|
||||
require('./test-kmac.js');
|
||||
}
|
||||
unset();
|
||||
}
|
||||
|
||||
// Node.js env
|
||||
BUFFER = true;
|
||||
runCommonJsTest();
|
||||
|
||||
// Webpack browser env
|
||||
JS_SHA3_NO_NODE_JS = true;
|
||||
window = global;
|
||||
runCommonJsTest();
|
||||
|
||||
// browser env
|
||||
JS_SHA3_NO_NODE_JS = true;
|
||||
JS_SHA3_NO_COMMON_JS = true;
|
||||
runWindowTest(true);
|
||||
|
||||
// browser env and no array buffer
|
||||
JS_SHA3_NO_NODE_JS = true;
|
||||
JS_SHA3_NO_COMMON_JS = true;
|
||||
JS_SHA3_NO_ARRAY_BUFFER = true;
|
||||
runWindowTest();
|
||||
|
||||
// browser env and no isView
|
||||
JS_SHA3_NO_NODE_JS = true;
|
||||
JS_SHA3_NO_COMMON_JS = true;
|
||||
JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW = true;
|
||||
runWindowTest();
|
||||
|
||||
// browser AMD
|
||||
JS_SHA3_NO_NODE_JS = true;
|
||||
JS_SHA3_NO_COMMON_JS = true;
|
||||
JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW = false;
|
||||
window = global;
|
||||
define = function (func) {
|
||||
sha3 = func();
|
||||
keccak512 = sha3.keccak512;
|
||||
keccak384 = sha3.keccak384;
|
||||
keccak256 = sha3.keccak256;
|
||||
keccak224 = sha3.keccak224;
|
||||
sha3_512 = sha3.sha3_512;
|
||||
sha3_384 = sha3.sha3_384;
|
||||
sha3_256 = sha3.sha3_256;
|
||||
sha3_224 = sha3.sha3_224;
|
||||
shake128 = sha3.shake128;
|
||||
shake256 = sha3.shake256;
|
||||
cshake128 = sha3.cshake128;
|
||||
cshake256 = sha3.cshake256;
|
||||
kmac128 = sha3.kmac128;
|
||||
kmac256 = sha3.kmac256;
|
||||
require('./test.js');
|
||||
};
|
||||
define.amd = true;
|
||||
|
||||
require('../src/sha3.js');
|
||||
require('./test-keccak.js');
|
||||
require('./test.js');
|
||||
unset();
|
||||
|
||||
// webworker
|
||||
WORKER = 'tests/worker.js';
|
||||
SOURCE = 'src/sha3.js';
|
||||
|
||||
require('./worker-test.js');
|
||||
|
||||
delete require.cache[require.resolve('./worker-test.js')];
|
||||
|
||||
// cover webworker
|
||||
JS_SHA3_NO_WINDOW = true;
|
||||
JS_SHA3_NO_NODE_JS = true;
|
||||
WORKER = './worker.js';
|
||||
SOURCE = '../src/sha3.js';
|
||||
window = global;
|
||||
self = global;
|
||||
|
||||
Worker = function (file) {
|
||||
require(file);
|
||||
currentWorker = this;
|
||||
|
||||
this.postMessage = function (data) {
|
||||
onmessage({data: data});
|
||||
};
|
||||
}
|
||||
|
||||
postMessage = function (data) {
|
||||
currentWorker.onmessage({data: data});
|
||||
}
|
||||
|
||||
importScripts = function () {};
|
||||
|
||||
requireToGlobal();
|
||||
require('./worker-test.js');
|
||||
|
@ -0,0 +1,90 @@
|
||||
(function (cshake256, cshake128) {
|
||||
// http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/cSHAKE_samples.pdf
|
||||
var testCases = [
|
||||
{
|
||||
name: 'cshake128',
|
||||
method: cshake128,
|
||||
cases: [
|
||||
{
|
||||
input: [0x00, 0x01, 0x02, 0x03],
|
||||
bits: 256,
|
||||
n: '',
|
||||
s: 'Email Signature',
|
||||
output: 'c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5'
|
||||
},
|
||||
{
|
||||
input: [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7],
|
||||
bits: 256,
|
||||
n: '',
|
||||
s: 'Email Signature',
|
||||
output: 'c5221d50e4f822d96a2e8881a961420f294b7b24fe3d2094baed2c6524cc166b'
|
||||
},
|
||||
{
|
||||
input: '',
|
||||
bits: 256,
|
||||
n: '',
|
||||
s: '',
|
||||
output: '7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26'
|
||||
},
|
||||
{
|
||||
input: [],
|
||||
bits: 256,
|
||||
n: [],
|
||||
s: [],
|
||||
output: '7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26'
|
||||
},
|
||||
{
|
||||
input: [],
|
||||
bits: 256,
|
||||
n: new ArrayBuffer(0),
|
||||
s: new ArrayBuffer(0),
|
||||
output: '7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26'
|
||||
},
|
||||
{
|
||||
input: [],
|
||||
bits: 256,
|
||||
n: new Uint8Array([]),
|
||||
s: new Uint8Array([]),
|
||||
output: '7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'cshake256',
|
||||
method: cshake256,
|
||||
cases: [
|
||||
{
|
||||
input: [0x00, 0x01, 0x02, 0x03],
|
||||
bits: 512,
|
||||
n: '',
|
||||
s: 'Email Signature',
|
||||
output: 'd008828e2b80ac9d2218ffee1d070c48b8e4c87bff32c9699d5b6896eee0edd164020e2be0560858d9c00c037e34a96937c561a74c412bb4c746469527281c8c'
|
||||
},
|
||||
{
|
||||
input: [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7],
|
||||
bits: 512,
|
||||
n: '',
|
||||
s: 'Email Signature',
|
||||
output: '07dc27b11e51fbac75bc7b3c1d983e8b4b85fb1defaf218912ac86430273091727f42b17ed1df63e8ec118f04b23633c1dfb1574c8fb55cb45da8e25afb092bb'
|
||||
},
|
||||
{
|
||||
input: '',
|
||||
bits: 512,
|
||||
n: '',
|
||||
s: '',
|
||||
output: '46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
testCases.forEach(function (testCase) {
|
||||
describe('#' + testCase.name, function () {
|
||||
testCase.cases.forEach(function (c) {
|
||||
it('should be equal', function () {
|
||||
expect(testCase.method(c.input, c.bits, c.n, c.s)).to.be(c.output);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})(cshake256, cshake128);
|
@ -0,0 +1,118 @@
|
||||
(function (kmac256, kmac128) {
|
||||
// http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/KMAC_samples.pdf
|
||||
var testCases = [
|
||||
{
|
||||
name: 'kmac128',
|
||||
method: kmac128,
|
||||
cases: [
|
||||
{
|
||||
input: [0x00, 0x01, 0x02, 0x03],
|
||||
bits: 256,
|
||||
key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F],
|
||||
s: '',
|
||||
output: 'e5780b0d3ea6f7d3a429c5706aa43a00fadbd7d49628839e3187243f456ee14e'
|
||||
},
|
||||
{
|
||||
input: [0x00, 0x01, 0x02, 0x03],
|
||||
bits: 256,
|
||||
key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F],
|
||||
s: 'My Tagged Application',
|
||||
output: '3b1fba963cd8b0b59e8c1a6d71888b7143651af8ba0a7070c0979e2811324aa5'
|
||||
},
|
||||
{
|
||||
input: [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7
|
||||
],
|
||||
bits: 256,
|
||||
key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F],
|
||||
s: 'My Tagged Application',
|
||||
output: '1f5b4e6cca02209e0dcb5ca635b89a15e271ecc760071dfd805faa38f9729230'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'kmac256',
|
||||
method: kmac256,
|
||||
cases: [
|
||||
{
|
||||
input: [0x00, 0x01, 0x02, 0x03],
|
||||
bits: 512,
|
||||
key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F],
|
||||
s: 'My Tagged Application',
|
||||
output: '20c570c31346f703c9ac36c61c03cb64c3970d0cfc787e9b79599d273a68d2f7f69d4cc3de9d104a351689f27cf6f5951f0103f33f4f24871024d9c27773a8dd'
|
||||
},
|
||||
{
|
||||
input: [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7
|
||||
],
|
||||
bits: 512,
|
||||
key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F],
|
||||
s: '',
|
||||
output: '75358cf39e41494e949707927cee0af20a3ff553904c86b08f21cc414bcfd691589d27cf5e15369cbbff8b9a4c2eb17800855d0235ff635da82533ec6b759b69'
|
||||
},
|
||||
{
|
||||
input: [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7
|
||||
],
|
||||
bits: 512,
|
||||
key: [0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F],
|
||||
s: 'My Tagged Application',
|
||||
output: 'b58618f71f92e1d56c1b8c55ddd7cd188b97b4ca4d99831eb2699a837da2e4d970fbacfde50033aea585f1a2708510c32d07880801bd182898fe476876fc8965'
|
||||
},
|
||||
{
|
||||
input: [],
|
||||
bits: 128,
|
||||
key: [],
|
||||
s: [8, 79, 237, 8, 185, 120, 175, 77, 125, 25, 106, 116, 70, 168, 107, 88, 0, 158, 99, 107, 97, 29, 177, 98, 17, 182, 90, 154, 173, 255, 41, 197, 8, 79, 237, 8, 185, 120, 175, 77, 125, 25, 106, 116, 70, 168, 107, 88, 0, 158, 99, 107, 97, 29, 177, 98, 17, 182, 90, 154, 173, 255, 41, 197, 8, 79, 237, 8, 185, 120, 175, 77, 125, 25, 106, 116, 70, 168, 107, 88, 0, 158, 99, 107, 97, 29, 177, 98, 17, 182, 90, 154, 173, 255, 41, 197, 8, 79, 237, 8, 185, 120, 175, 77, 125, 25, 106, 116, 70, 168, 107, 88, 0, 158, 99, 107, 97, 29, 177, 98, 17, 182, 90, 154, 173],
|
||||
output: '031801b0b50ebeef772fbe7a279bc144'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
testCases.forEach(function (testCase) {
|
||||
describe('#' + testCase.name, function () {
|
||||
testCase.cases.forEach(function (c) {
|
||||
it('should be equal', function () {
|
||||
expect(testCase.method(c.key, c.input, c.bits, c.s)).to.be(c.output);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})(kmac256, kmac128);
|
@ -0,0 +1,114 @@
|
||||
(function (shake256, shake128) {
|
||||
describe('#shake128', function () {
|
||||
context('with 256 output', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake128('', 256)).to.be('7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26');
|
||||
expect(shake128('The quick brown fox jumps over the lazy dog', 256)).to.be('f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66e');
|
||||
expect(shake128('The quick brown fox jumps over the lazy dof', 256)).to.be('853f4538be0db9621a6cea659a06c1107b1f83f02b13d18297bd39d7411cf10c');
|
||||
});
|
||||
});
|
||||
|
||||
context('with 8 output', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake128('', 8)).to.be('7f');
|
||||
expect(shake128('The quick brown fox jumps over the lazy dog', 8)).to.be('f4');
|
||||
expect(shake128('The quick brown fox jumps over the lazy dof', 8)).to.be('85');
|
||||
});
|
||||
});
|
||||
|
||||
context('with 1368 output', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake128('AAA', 1368)).to.be('15e0fe495a05b74f9fd3eaa8a898a623488220dcbf9ba2f12d23d278b7cecfa4a5e4b8d0fccb0fdbc9e51cd0b4344a32a83f0ba40a514a7b86a77c854c61b836192849da9214c43c4f8bc09ec7a76af92b2fc56e4952024be65b1a47835e0bc014733b24d0e31197ca648f831caebbfd8a5b237ae6bdc9d6cc803a2c5e57dd9346eecf972bd85450f18a413dc6239982e1eb6e0c6df856385c9597d0320edb40b6fe60a74f07524015ad36');
|
||||
expect(shake128('AAA', 1376)).to.be('15e0fe495a05b74f9fd3eaa8a898a623488220dcbf9ba2f12d23d278b7cecfa4a5e4b8d0fccb0fdbc9e51cd0b4344a32a83f0ba40a514a7b86a77c854c61b836192849da9214c43c4f8bc09ec7a76af92b2fc56e4952024be65b1a47835e0bc014733b24d0e31197ca648f831caebbfd8a5b237ae6bdc9d6cc803a2c5e57dd9346eecf972bd85450f18a413dc6239982e1eb6e0c6df856385c9597d0320edb40b6fe60a74f07524015ad36b6');
|
||||
});
|
||||
});
|
||||
|
||||
context('with more output', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake128('', 16)).to.be('7f9c');
|
||||
expect(shake128('', 24)).to.be('7f9c2b');
|
||||
expect(shake128.array('', 8)).to.eql([0x7f]);
|
||||
expect(shake128.array('', 16)).to.eql([0x7f, 0x9c]);
|
||||
expect(shake128.array('', 24)).to.eql([0x7f, 0x9c, 0x2b]);
|
||||
});
|
||||
});
|
||||
|
||||
context('with 8 output ArrayBuffer', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake128.arrayBuffer('', 8).toHexString()).to.be('7f');
|
||||
expect(shake128.arrayBuffer('The quick brown fox jumps over the lazy dog', 8).toHexString()).to.be('f4');
|
||||
expect(shake128.arrayBuffer('The quick brown fox jumps over the lazy dof', 8).toHexString()).to.be('85');
|
||||
});
|
||||
});
|
||||
|
||||
context('#update', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake128.update('', 256).hex()).to.be('7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26');
|
||||
expect(shake128.update('The quick brown fox ', 256).update('jumps over the lazy dog').hex()).to.be('f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66e');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#shake256', function () {
|
||||
context('with 512 output', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake256('', 512)).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be');
|
||||
});
|
||||
});
|
||||
|
||||
context('with 8 output', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake256('', 8)).to.be('46');
|
||||
});
|
||||
});
|
||||
|
||||
context('with 1112 output', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake256('AAA', 1112)).to.be('419614c8b247ee5e9f4a540f7aaa5ca5b44b119f47ab7f494c05095ae5a61ab6b62c84b8b27888813ce8a4d4dab3ed7617c6bab643aa01bb1b113e6d48c3e1eeb73e96f96ffaf12e0c36b190404982b856087acfcb467535e17152e5c15a4d62a18a15d8fe434b3a7274362b0d46b627df1e011a1d037e161d5b540df7ebadab351fb730904daa9a4f40fd');
|
||||
expect(shake256('AAA', 1120)).to.be('419614c8b247ee5e9f4a540f7aaa5ca5b44b119f47ab7f494c05095ae5a61ab6b62c84b8b27888813ce8a4d4dab3ed7617c6bab643aa01bb1b113e6d48c3e1eeb73e96f96ffaf12e0c36b190404982b856087acfcb467535e17152e5c15a4d62a18a15d8fe434b3a7274362b0d46b627df1e011a1d037e161d5b540df7ebadab351fb730904daa9a4f40fdb5');
|
||||
});
|
||||
});
|
||||
|
||||
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(shake256('', 4100)).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a');
|
||||
|
||||
// Len = 2040
|
||||
// Msg = 3A3A819C48EFDE2AD914FBF00E18AB6BC4F14513AB27D0C178A188B61431E7F5623CB66B23346775D386B50E982C493ADBBFC54B9A3CD383382336A1A0B2150A15358F336D03AE18F666C7573D55C4FD181C29E6CCFDE63EA35F0ADF5885CFC0A3D84A2B2E4DD24496DB789E663170CEF74798AA1BBCD4574EA0BBA40489D764B2F83AADC66B148B4A0CD95246C127D5871C4F11418690A5DDF01246A0C80A43C70088B6183639DCFDA4125BD113A8F49EE23ED306FAAC576C3FB0C1E256671D817FC2534A52F5B439F72E424DE376F4C565CCA82307DD9EF76DA5B7C4EB7E085172E328807C02D011FFBF33785378D79DC266F6A5BE6BB0E4A92ECEEBAEB1
|
||||
expect(shake256([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');
|
||||
});
|
||||
});
|
||||
|
||||
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(shake256.arrayBuffer('', 4100).toHexString()).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a');
|
||||
|
||||
// Len = 2040
|
||||
// Msg = 3A3A819C48EFDE2AD914FBF00E18AB6BC4F14513AB27D0C178A188B61431E7F5623CB66B23346775D386B50E982C493ADBBFC54B9A3CD383382336A1A0B2150A15358F336D03AE18F666C7573D55C4FD181C29E6CCFDE63EA35F0ADF5885CFC0A3D84A2B2E4DD24496DB789E663170CEF74798AA1BBCD4574EA0BBA40489D764B2F83AADC66B148B4A0CD95246C127D5871C4F11418690A5DDF01246A0C80A43C70088B6183639DCFDA4125BD113A8F49EE23ED306FAAC576C3FB0C1E256671D817FC2534A52F5B439F72E424DE376F4C565CCA82307DD9EF76DA5B7C4EB7E085172E328807C02D011FFBF33785378D79DC266F6A5BE6BB0E4A92ECEEBAEB1
|
||||
expect(shake256.arrayBuffer([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(shake256.array('', 4100).toHexString()).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a');
|
||||
|
||||
// Len = 2040
|
||||
// Msg = 3A3A819C48EFDE2AD914FBF00E18AB6BC4F14513AB27D0C178A188B61431E7F5623CB66B23346775D386B50E982C493ADBBFC54B9A3CD383382336A1A0B2150A15358F336D03AE18F666C7573D55C4FD181C29E6CCFDE63EA35F0ADF5885CFC0A3D84A2B2E4DD24496DB789E663170CEF74798AA1BBCD4574EA0BBA40489D764B2F83AADC66B148B4A0CD95246C127D5871C4F11418690A5DDF01246A0C80A43C70088B6183639DCFDA4125BD113A8F49EE23ED306FAAC576C3FB0C1E256671D817FC2534A52F5B439F72E424DE376F4C565CCA82307DD9EF76DA5B7C4EB7E085172E328807C02D011FFBF33785378D79DC266F6A5BE6BB0E4A92ECEEBAEB1
|
||||
expect(shake256.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('with 1128 output arrayBuffer', function () {
|
||||
it('should be equal', function () {
|
||||
expect(shake256.arrayBuffer('', 1128).toHexString()).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec46');
|
||||
});
|
||||
});
|
||||
});
|
||||
})(shake256, shake128);
|
@ -0,0 +1,24 @@
|
||||
(function (Worker, WORKER, SOURCE) {
|
||||
var cases = {
|
||||
'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': '',
|
||||
'01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450': 'The quick brown fox jumps over the lazy dog',
|
||||
'18f4f4bd419603f95538837003d9d254c26c23765565162247483f65c50303597bc9ce4d289f21d1c2f1f458828e33dc442100331b35e7eb031b5d38ba6460f8': 'The quick brown fox jumps over the lazy dog.'
|
||||
};
|
||||
|
||||
describe('#sha3_512', function () {
|
||||
Object.keys(cases).forEach(function (hash) {
|
||||
it('should be equal', function (done) {
|
||||
var worker = new Worker(WORKER);
|
||||
worker.onmessage = function(event) {
|
||||
expect(event.data).to.be(hash);
|
||||
if (worker.terminate) {
|
||||
worker.terminate();
|
||||
}
|
||||
done();
|
||||
};
|
||||
worker.postMessage(SOURCE);
|
||||
worker.postMessage(cases[hash]);
|
||||
});
|
||||
});
|
||||
});
|
||||
})(Worker, WORKER, SOURCE);
|
@ -0,0 +1,26 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>SHA3</title>
|
||||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
|
||||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../node_modules/expect.js/index.js"></script>
|
||||
<script src="../src/sha3.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script>
|
||||
WORKER = 'worker.js';
|
||||
SOURCE = '../src/sha3.js';
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
<script src="worker-test.js"></script>
|
||||
<script>
|
||||
mocha.checkLeaks();
|
||||
mocha.run();
|
||||
</script>
|
||||
<script>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,12 @@
|
||||
var imported = false;
|
||||
onmessage = function(e) {
|
||||
if (imported) {
|
||||
postMessage(sha3_512(e.data));
|
||||
if (typeof exports !== 'undefined') {
|
||||
imported = false;
|
||||
}
|
||||
} else {
|
||||
imported = true;
|
||||
importScripts(e.data);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue