## v0.9.1 / 2023-08-31

### Fixed
- cSHAKE empty Array bug. #24
pull/33/head v0.9.1
Yi-Cyuan Chen 2 years ago
parent dbb0ea401f
commit f293b5d508

@ -1,5 +1,9 @@
# Change Log # Change Log
## v0.9.1 / 2023-08-31
### Fixed
- cSHAKE empty Array bug. #24
## v0.9.0 / 2023-08-30 ## v0.9.0 / 2023-08-30
### Fixed ### Fixed
- cSHAKE bug. #24 - cSHAKE bug. #24

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

4
build/sha3.min.js vendored

File diff suppressed because one or more lines are too long

2
package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "js-sha3", "name": "js-sha3",
"version": "0.9.0", "version": "0.9.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

@ -1,6 +1,6 @@
{ {
"name": "js-sha3", "name": "js-sha3",
"version": "0.9.0", "version": "0.9.1",
"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": {

@ -1,7 +1,7 @@
/** /**
* [js-sha3]{@link https://github.com/emn178/js-sha3} * [js-sha3]{@link https://github.com/emn178/js-sha3}
* *
* @version 0.9.0 * @version 0.9.1
* @author Chen, Yi-Cyuan [emn178@gmail.com] * @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2023 * @copyright Chen, Yi-Cyuan 2015-2023
* @license MIT * @license MIT
@ -58,6 +58,31 @@
}; };
} }
var formatMessage = function (message) {
var notString, type = typeof message;
if (type !== 'string') {
if (type === 'object') {
if (message === null) {
throw new Error(INPUT_ERROR);
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw new Error(INPUT_ERROR);
}
}
} else {
throw new Error(INPUT_ERROR);
}
notString = true;
}
return [message, notString];
}
var empty = function (message) {
return formatMessage(message)[0].length === 0;
};
var createOutputMethod = function (bits, padding, outputType) { var createOutputMethod = function (bits, padding, outputType) {
return function (message) { return function (message) {
return new Keccak(bits, padding, bits).update(message)[outputType](); return new Keccak(bits, padding, bits).update(message)[outputType]();
@ -116,7 +141,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);
@ -188,23 +213,9 @@
if (this.finalized) { if (this.finalized) {
throw new Error(FINALIZE_ERROR); throw new Error(FINALIZE_ERROR);
} }
var notString, type = typeof message; var result = formatMessage(message);
if (type !== 'string') { message = result[0];
if (type === 'object') { var notString = result[1];
if (message === null) {
throw new Error(INPUT_ERROR);
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw new Error(INPUT_ERROR);
}
}
} else {
throw new Error(INPUT_ERROR);
}
notString = true;
}
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;
@ -278,23 +289,9 @@
}; };
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 notString = result[1];
if (str === null) {
throw new Error(INPUT_ERROR);
} else if (ARRAY_BUFFER && str.constructor === ArrayBuffer) {
str = new Uint8Array(str);
} else if (!Array.isArray(str)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(str)) {
throw new Error(INPUT_ERROR);
}
}
} else {
throw new Error(INPUT_ERROR);
}
notString = true;
}
var bytes = 0, length = str.length; var bytes = 0, length = str.length;
if (notString) { if (notString) {
bytes = length; bytes = length;

@ -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'
} }
] ]
}, },

Loading…
Cancel
Save