## 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
## v0.9.1 / 2023-08-31
### Fixed
- cSHAKE empty Array bug. #24
## v0.9.0 / 2023-08-30
### Fixed
- cSHAKE bug. #24

@ -1,6 +1,6 @@
{
"name": "js-sha3",
"version": "0.9.0",
"version": "0.9.1",
"main": ["src/sha3.js"],
"ignore": [
"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",
"version": "0.9.0",
"version": "0.9.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

@ -1,6 +1,6 @@
{
"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.",
"main": "src/sha3.js",
"devDependencies": {

@ -1,7 +1,7 @@
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.9.0
* @version 0.9.1
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2023
* @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) {
return function (message) {
return new Keccak(bits, padding, bits).update(message)[outputType]();
@ -116,7 +141,7 @@
var w = CSHAKE_BYTEPAD[bits];
var method = createCshakeOutputMethod(bits, padding, 'hex');
method.create = function (outputBits, n, s) {
if (!n && !s) {
if (empty(n) && empty(s)) {
return methods['shake' + bits].create(outputBits);
} else {
return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
@ -188,23 +213,9 @@
if (this.finalized) {
throw new Error(FINALIZE_ERROR);
}
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;
}
var result = formatMessage(message);
message = result[0];
var notString = result[1];
var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
blockCount = this.blockCount, index = 0, s = this.s, i, code;
@ -278,23 +289,9 @@
};
Keccak.prototype.encodeString = function (str) {
var notString, type = typeof str;
if (type !== 'string') {
if (type === 'object') {
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 result = formatMessage(str);
str = result[0];
var notString = result[1];
var bytes = 0, length = str.length;
if (notString) {
bytes = length;

@ -25,6 +25,27 @@
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'
}
]
},

Loading…
Cancel
Save