Compare commits

...

10 Commits

Author SHA1 Message Date
dependabot[bot] 6efde1cf1b
Bump @babel/traverse from 7.21.2 to 7.23.2 (#35)
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.21.2 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2 years ago
Yi-Cyuan Chen a6f6da7483 ### Fixed
- Fix error in arrayBuffer when there are extra bytes #37
- fixed output if finalized.
2 years ago
iatll 707ee7ced1
Fix error in arrayBuffer when there are extra bytes (#37) 2 years ago
Yi-Cyuan Chen 59caf17eca bump version 2 years ago
legobeat d6325442bd
refactor: simplify formatMessage internal logic (#34)
* fix: don't modify global Array and ArrayBuffer prototypes

* wip: simplify formatMessage

* wip: simplify formatMessage internal logic

* wip: simplify formatMessage internal logic

* wip: simplify formatMessage internal logic

* refactor: simplify formatMessage internal logic

* formatMessage: remove double-negation: now returns istring instead of notString

* refactor: remove double-negation of isString

* refactor: remove double-negation of isString

* add comment on formatMessage return type
2 years ago
Yi-Cyuan Chen f293b5d508 ## v0.9.1 / 2023-08-31
### Fixed
- cSHAKE empty Array bug. #24
2 years ago
Yi-Cyuan Chen dbb0ea401f ## v0.9.0 / 2023-08-30
### Fixed
- cSHAKE bug. #24
- dependencies and security issues.
2 years ago
dependabot[bot] 5aecbd6968
Bump minimist, mocha and nyc (#28)
Removes [minimist](https://github.com/minimistjs/minimist). It's no longer used after updating ancestor dependencies [minimist](https://github.com/minimistjs/minimist), [mocha](https://github.com/mochajs/mocha) and [nyc](https://github.com/istanbuljs/nyc). These dependencies need to be updated together.


Removes `minimist`

Updates `mocha` from 2.3.4 to 10.2.0
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/2.3.4...v10.2.0)

Updates `nyc` from 11.3.0 to 15.1.0
- [Release notes](https://github.com/istanbuljs/nyc/releases)
- [Changelog](https://github.com/istanbuljs/nyc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/istanbuljs/nyc/compare/v11.3.0...v15.1.0)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
- dependency-name: mocha
  dependency-type: direct:development
- dependency-name: nyc
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2 years ago
Yi-Cyuan Chen b39d0910cb - Added TypeScript definitions.
- Changed throw error if update after finalize
7 years ago
Micah Zoltu 1c00d97268 Adds arrayBuffer and buffer definitions. (#16)
This is based entirely on the examples in the readme.  If the examples in the readme are incorrect then this definition is also incorrect.
7 years ago

@ -1,5 +1,31 @@
# Change Log # Change Log
## v0.9.3 / 2023-12-16
### Fixed
- Fix error in arrayBuffer when there are extra bytes #37
- fixed output if finalized.
## v0.9.2 / 2023-09-16
### Fixed
- don't modify global Array and ArrayBuffer prototypes. #33
- refactor: simplify formatMessage internal logic. #34
## v0.9.1 / 2023-08-31
### Fixed
- cSHAKE empty Array bug. #24
## v0.9.0 / 2023-08-30
### Fixed
- cSHAKE bug. #24
- dependencies and security issues.
## v0.8.0 / 2018-08-05
### Added
- TypeScript definitions.
### Changed
- throw error if update after finalize
## v0.7.0 / 2017-12-01 ## v0.7.0 / 2017-12-01
### Added ### Added
- AMD support. - AMD support.

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

@ -7,6 +7,7 @@
A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding. A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.
## Notice ## Notice
* v0.8.0+ will throw an error if try to update hash after finalize.
* 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. * 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.
* `buffer` method is deprecated. This maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead. * `buffer` method is deprecated. This maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
@ -54,10 +55,11 @@ kmac128('key', 'Message to hash', 256, 'customization');
kmac256('key', 'Message to hash', 512, 'customization'); kmac256('key', 'Message to hash', 512, 'customization');
// Support ArrayBuffer output // Support ArrayBuffer output
var buffer = keccak224.buffer('Message to hash'); var arrayBuffer = keccak224.arrayBuffer('Message to hash');
// Support Array output // Support Array output
var buffer = keccak224.array('Message to hash'); var bytes = keccak224.digest('Message to hash');
var bytes = keccak224.array('Message to hash');
// update hash // update hash
sha3_512.update('Message ').update('to ').update('hash').hex(); sha3_512.update('Message ').update('to ').update('hash').hex();
@ -82,26 +84,46 @@ var hash = cshake128.create(256, 'function name', 'customization');
// specify kmac key, output bits and customization when creating // specify kmac key, output bits and customization when creating
var hash = kmac128.create('key', 256, 'customization'); var hash = kmac128.create('key', 256, 'customization');
``` ```
### Node.js
If you use node.js, you should require the module first: If you use node.js, you should require the module first:
```JavaScript ```JavaScript
sha3_512 = require('js-sha3').sha3_512; const {
sha3_384 = require('js-sha3').sha3_384; sha3_512,
sha3_256 = require('js-sha3').sha3_256; sha3_384,
sha3_224 = require('js-sha3').sha3_224; sha3_256,
keccak512 = require('js-sha3').keccak512; sha3_224,
keccak384 = require('js-sha3').keccak384; keccak512,
keccak256 = require('js-sha3').keccak256; keccak384,
keccak224 = require('js-sha3').keccak224; keccak256,
shake128 = require('js-sha3').shake128; keccak224,
shake256 = require('js-sha3').shake256; shake128,
cshake128 = require('js-sha3').cshake128; shake256,
cshake256 = require('js-sha3').cshake256; cshake128,
kmac128 = require('js-sha3').kmac128; cshake256,
kmac256 = require('js-sha3').kmac256; kmac128,
kmac25
} = require('js-sha3');
``` ```
### TypeScript
If you use TypeScript, you can import like this: If you use TypeScript, you can import like this:
```TypeScript ```TypeScript
import { sha3_512 } from 'js-sha3'; import {
sha3_512,
sha3_384,
sha3_256,
sha3_224,
keccak512,
keccak384,
keccak256,
keccak224,
shake128,
shake256,
cshake128,
cshake256,
kmac128,
kmac256
} from 'js-sha3';
``` ```
## Example ## Example

@ -1,6 +1,6 @@
{ {
"name": "js-sha3", "name": "js-sha3",
"version": "0.7.0", "version": "0.9.3",
"main": ["src/sha3.js"], "main": ["src/sha3.js"],
"ignore": [ "ignore": [
"samples", "samples",

6
build/sha3.min.js vendored

File diff suppressed because one or more lines are too long

149
index.d.ts vendored

@ -42,6 +42,34 @@ interface Hash {
*/ */
(message: Message): string; (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 a hash object.
*/ */
@ -64,10 +92,43 @@ interface ShakeHash {
*/ */
(message: Message, outputBits: number): string; (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. * Create a hash object.
* *
* @param outputBits The length of output. * @param outputBits The length of output.
* @param outputBits The length of output.
*/ */
create(outputBits: number): Hasher; create(outputBits: number): Hasher;
@ -91,6 +152,54 @@ interface CshakeHash {
*/ */
(message: Message, outputBits: number, functionName: Message, customization: Message): 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. * Create a hash object.
* *
@ -122,6 +231,46 @@ interface KmacHash {
*/ */
(key: Message, message: Message, outputBits: number, customization: Message): 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. * Create a hash object.
* *

2631
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,14 +1,14 @@
{ {
"name": "js-sha3", "name": "js-sha3",
"version": "0.7.0", "version": "0.9.3",
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.", "description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
"main": "src/sha3.js", "main": "src/sha3.js",
"devDependencies": { "devDependencies": {
"expect.js": "~0.3.1", "expect.js": "~0.3.1",
"mocha": "~2.3.4", "mocha": "~10.2.0",
"nyc": "^11.3.0", "nyc": "^15.1.0",
"uglify-js": "^3.1.9", "tiny-worker": "^2.3.0",
"webworker-threads": "^0.7.13" "uglify-js": "^3.1.9"
}, },
"scripts": { "scripts": {
"test": "nyc mocha tests/node-test.js", "test": "nyc mocha tests/node-test.js",

@ -1,16 +1,17 @@
/** /**
* [js-sha3]{@link https://github.com/emn178/js-sha3} * [js-sha3]{@link https://github.com/emn178/js-sha3}
* *
* @version 0.7.0 * @version 0.9.3
* @author Chen, Yi-Cyuan [emn178@gmail.com] * @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2017 * @copyright Chen, Yi-Cyuan 2015-2023
* @license MIT * @license MIT
*/ */
/*jslint bitwise: true */ /*jslint bitwise: true */
(function () { (function () {
'use strict'; 'use strict';
var ERROR = 'input is invalid type'; var INPUT_ERROR = 'input is invalid type';
var FINALIZE_ERROR = 'finalize already called';
var WINDOW = typeof window === 'object'; var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {}; var root = WINDOW ? window : {};
if (root.JS_SHA3_NO_WINDOW) { if (root.JS_SHA3_NO_WINDOW) {
@ -45,16 +46,47 @@
'256': 136 '256': 136
}; };
if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) {
Array.isArray = function (obj) { var isArray = root.JS_SHA3_NO_NODE_JS || !Array.isArray
? function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]'; return Object.prototype.toString.call(obj) === '[object Array]';
};
} }
: Array.isArray;
if (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { var isView = (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView))
ArrayBuffer.isView = function (obj) { ? function (obj) {
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer; return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
}
: ArrayBuffer.isView;
// [message: string, isString: bool]
var formatMessage = function (message) {
var type = typeof message;
if (type === 'string') {
return [message, true];
}
if (type !== 'object' || message === null) {
throw new Error(INPUT_ERROR);
}
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
return [new Uint8Array(message), false];
}
if (!isArray(message) && !isView(message)) {
throw new Error(INPUT_ERROR);
}
return [message, false];
}
var empty = function (message) {
return formatMessage(message)[0].length === 0;
}; };
var cloneArray = function (array) {
var newArray = [];
for (var i = 0; i < array.length; ++i) {
newArray[i] = array[i];
}
return newArray;
} }
var createOutputMethod = function (bits, padding, outputType) { var createOutputMethod = function (bits, padding, outputType) {
@ -115,7 +147,7 @@
var w = CSHAKE_BYTEPAD[bits]; var w = CSHAKE_BYTEPAD[bits];
var method = createCshakeOutputMethod(bits, padding, 'hex'); var method = createCshakeOutputMethod(bits, padding, 'hex');
method.create = function (outputBits, n, s) { method.create = function (outputBits, n, s) {
if (!n && !s) { if (empty(n) && empty(s)) {
return methods['shake' + bits].create(outputBits); return methods['shake' + bits].create(outputBits);
} else { } else {
return new Keccak(bits, padding, outputBits).bytepad([n, s], w); return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
@ -185,25 +217,11 @@
Keccak.prototype.update = function (message) { Keccak.prototype.update = function (message) {
if (this.finalized) { if (this.finalized) {
return; throw new Error(FINALIZE_ERROR);
}
var notString, type = typeof message;
if (type !== 'string') {
if (type === 'object') {
if (message === null) {
throw ERROR;
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw ERROR;
}
}
} else {
throw ERROR;
}
notString = true;
} }
var result = formatMessage(message);
message = result[0];
var isString = result[1];
var blocks = this.blocks, byteCount = this.byteCount, length = message.length, var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
blockCount = this.blockCount, index = 0, s = this.s, i, code; blockCount = this.blockCount, index = 0, s = this.s, i, code;
@ -215,11 +233,7 @@
blocks[i] = 0; blocks[i] = 0;
} }
} }
if (notString) { if (isString) {
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) { for (i = this.start; index < length && i < byteCount; ++index) {
code = message.charCodeAt(index); code = message.charCodeAt(index);
if (code < 0x80) { if (code < 0x80) {
@ -239,6 +253,10 @@
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} }
} }
} else {
for (i = this.start; index < length && i < byteCount; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
} }
this.lastByteIndex = i; this.lastByteIndex = i;
if (i >= byteCount) { if (i >= byteCount) {
@ -277,27 +295,11 @@
}; };
Keccak.prototype.encodeString = function (str) { Keccak.prototype.encodeString = function (str) {
var notString, type = typeof str; var result = formatMessage(str);
if (type !== 'string') { str = result[0];
if (type === 'object') { var isString = result[1];
if (str === null) {
throw ERROR;
} else if (ARRAY_BUFFER && str.constructor === ArrayBuffer) {
str = new Uint8Array(str);
} else if (!Array.isArray(str)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(str)) {
throw ERROR;
}
}
} else {
throw ERROR;
}
notString = true;
}
var bytes = 0, length = str.length; var bytes = 0, length = str.length;
if (notString) { if (isString) {
bytes = length;
} else {
for (var i = 0; i < str.length; ++i) { for (var i = 0; i < str.length; ++i) {
var code = str.charCodeAt(i); var code = str.charCodeAt(i);
if (code < 0x80) { if (code < 0x80) {
@ -311,6 +313,8 @@
bytes += 4; bytes += 4;
} }
} }
} else {
bytes = length;
} }
bytes += this.encode(bytes * 8); bytes += this.encode(bytes * 8);
this.update(str); this.update(str);
@ -322,7 +326,7 @@
for (var i = 0; i < strs.length; ++i) { for (var i = 0; i < strs.length; ++i) {
bytes += this.encodeString(strs[i]); bytes += this.encodeString(strs[i]);
} }
var paddingBytes = w - bytes % w; var paddingBytes = (w - bytes % w) % w;
var zeros = []; var zeros = [];
zeros.length = paddingBytes; zeros.length = paddingBytes;
this.update(zeros); this.update(zeros);
@ -364,6 +368,7 @@
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F]; HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
} }
if (j % blockCount === 0) { if (j % blockCount === 0) {
s = cloneArray(s);
f(s); f(s);
i = 0; i = 0;
} }
@ -399,11 +404,12 @@
array[j] = s[i]; array[j] = s[i];
} }
if (j % blockCount === 0) { if (j % blockCount === 0) {
s = cloneArray(s);
f(s); f(s);
} }
} }
if (extraBytes) { if (extraBytes) {
array[i] = s[i]; array[j] = s[i];
buffer = buffer.slice(0, bytes); buffer = buffer.slice(0, bytes);
} }
return buffer; return buffer;
@ -427,6 +433,7 @@
array[offset + 3] = (block >> 24) & 0xFF; array[offset + 3] = (block >> 24) & 0xFF;
} }
if (j % blockCount === 0) { if (j % blockCount === 0) {
s = cloneArray(s);
f(s); f(s);
} }
} }

@ -1,5 +1,5 @@
expect = require('expect.js'); expect = require('expect.js');
Worker = require('webworker-threads').Worker; Worker = require("tiny-worker");
function unset() { function unset() {
delete require.cache[require.resolve('../src/sha3.js')]; delete require.cache[require.resolve('../src/sha3.js')];

@ -25,6 +25,27 @@
n: '', n: '',
s: '', s: '',
output: '7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26' 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'
} }
] ]
}, },

@ -94,6 +94,13 @@
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], 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', s: 'My Tagged Application',
output: 'b58618f71f92e1d56c1b8c55ddd7cd188b97b4ca4d99831eb2699a837da2e4d970fbacfde50033aea585f1a2708510c32d07880801bd182898fe476876fc8965' 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'
} }
] ]
} }

@ -35,9 +35,9 @@
context('with 8 output ArrayBuffer', function () { context('with 8 output ArrayBuffer', function () {
it('should be equal', function () { it('should be equal', function () {
expect(shake128.buffer('', 8).toHexString()).to.be('7f'); expect(shake128.arrayBuffer('', 8).toHexString()).to.be('7f');
expect(shake128.buffer('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 dog', 8).toHexString()).to.be('f4');
expect(shake128.buffer('The quick brown fox jumps over the lazy dof', 8).toHexString()).to.be('85'); expect(shake128.arrayBuffer('The quick brown fox jumps over the lazy dof', 8).toHexString()).to.be('85');
}); });
}); });
@ -55,6 +55,7 @@
expect(shake256('', 512)).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be'); expect(shake256('', 512)).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be');
}); });
}); });
context('with 8 output', function () { context('with 8 output', function () {
it('should be equal', function () { it('should be equal', function () {
expect(shake256('', 8)).to.be('46'); expect(shake256('', 8)).to.be('46');
@ -84,11 +85,11 @@
it('should be equal', function () { it('should be equal', function () {
// https://raw.githubusercontent.com/gvanas/KeccakCodePackage/master/TestVectors/ShortMsgKAT_SHAKE256.txt // https://raw.githubusercontent.com/gvanas/KeccakCodePackage/master/TestVectors/ShortMsgKAT_SHAKE256.txt
// Len = 0, Msg = 00 // Len = 0, Msg = 00
expect(shake256.buffer('', 4100).toHexString()).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a'); expect(shake256.arrayBuffer('', 4100).toHexString()).to.be('46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a');
// Len = 2040 // Len = 2040
// Msg = 3A3A819C48EFDE2AD914FBF00E18AB6BC4F14513AB27D0C178A188B61431E7F5623CB66B23346775D386B50E982C493ADBBFC54B9A3CD383382336A1A0B2150A15358F336D03AE18F666C7573D55C4FD181C29E6CCFDE63EA35F0ADF5885CFC0A3D84A2B2E4DD24496DB789E663170CEF74798AA1BBCD4574EA0BBA40489D764B2F83AADC66B148B4A0CD95246C127D5871C4F11418690A5DDF01246A0C80A43C70088B6183639DCFDA4125BD113A8F49EE23ED306FAAC576C3FB0C1E256671D817FC2534A52F5B439F72E424DE376F4C565CCA82307DD9EF76DA5B7C4EB7E085172E328807C02D011FFBF33785378D79DC266F6A5BE6BB0E4A92ECEEBAEB1 // Msg = 3A3A819C48EFDE2AD914FBF00E18AB6BC4F14513AB27D0C178A188B61431E7F5623CB66B23346775D386B50E982C493ADBBFC54B9A3CD383382336A1A0B2150A15358F336D03AE18F666C7573D55C4FD181C29E6CCFDE63EA35F0ADF5885CFC0A3D84A2B2E4DD24496DB789E663170CEF74798AA1BBCD4574EA0BBA40489D764B2F83AADC66B148B4A0CD95246C127D5871C4F11418690A5DDF01246A0C80A43C70088B6183639DCFDA4125BD113A8F49EE23ED306FAAC576C3FB0C1E256671D817FC2534A52F5B439F72E424DE376F4C565CCA82307DD9EF76DA5B7C4EB7E085172E328807C02D011FFBF33785378D79DC266F6A5BE6BB0E4A92ECEEBAEB1
expect(shake256.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'); 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');
}); });
}); });
@ -103,5 +104,11 @@
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'); 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); })(shake256, shake128);

@ -185,8 +185,8 @@
if (typeof BUFFER === 'boolean' && BUFFER) { if (typeof BUFFER === 'boolean' && BUFFER) {
testCases.sha3_512.Buffer = { testCases.sha3_512.Buffer = {
'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': new Buffer(0), 'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': Buffer.from([]),
'01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450': new Buffer(new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103])) '01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450': Buffer.from(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]))
}; };
} }
@ -264,7 +264,7 @@
call: function (message) { call: function (message) {
var hash = algorithm.update(message); var hash = algorithm.update(message);
hash.hex(); hash.hex();
hash.update(message); hash.finalize();
return hash.hex(); return hash.hex();
} }
} }
@ -321,6 +321,16 @@
}); });
}); });
}); });
context('when update after finalize', function () {
it('should throw error', function () {
expect(function () {
var hash = algorithm.update('any');
hash.hex();
hash.update('any');
}).to.throwError(/finalize already called/);
});
});
}); });
}); });
} }

@ -11,6 +11,9 @@
var worker = new Worker(WORKER); var worker = new Worker(WORKER);
worker.onmessage = function(event) { worker.onmessage = function(event) {
expect(event.data).to.be(hash); expect(event.data).to.be(hash);
if (worker.terminate) {
worker.terminate();
}
done(); done();
}; };
worker.postMessage(SOURCE); worker.postMessage(SOURCE);

Loading…
Cancel
Save