Skip to content

Commit dbb0ea4

Browse files
committed
## v0.9.0 / 2023-08-30
### Fixed - cSHAKE bug. #24 - dependencies and security issues.
1 parent 5aecbd6 commit dbb0ea4

11 files changed

+84
-56
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## v0.9.0 / 2023-08-30
4+
### Fixed
5+
- cSHAKE bug. #24
6+
- dependencies and security issues.
7+
38
## v0.8.0 / 2018-08-05
49
### Added
510
- TypeScript definitions.

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2015-2018 Chen, Yi-Cyuan
1+
Copyright 2015-2023 Chen, Yi-Cyuan
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

+35-15
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,46 @@ var hash = cshake128.create(256, 'function name', 'customization');
8484
// specify kmac key, output bits and customization when creating
8585
var hash = kmac128.create('key', 256, 'customization');
8686
```
87+
### Node.js
8788
If you use node.js, you should require the module first:
8889
```JavaScript
89-
sha3_512 = require('js-sha3').sha3_512;
90-
sha3_384 = require('js-sha3').sha3_384;
91-
sha3_256 = require('js-sha3').sha3_256;
92-
sha3_224 = require('js-sha3').sha3_224;
93-
keccak512 = require('js-sha3').keccak512;
94-
keccak384 = require('js-sha3').keccak384;
95-
keccak256 = require('js-sha3').keccak256;
96-
keccak224 = require('js-sha3').keccak224;
97-
shake128 = require('js-sha3').shake128;
98-
shake256 = require('js-sha3').shake256;
99-
cshake128 = require('js-sha3').cshake128;
100-
cshake256 = require('js-sha3').cshake256;
101-
kmac128 = require('js-sha3').kmac128;
102-
kmac256 = require('js-sha3').kmac256;
90+
const {
91+
sha3_512,
92+
sha3_384,
93+
sha3_256,
94+
sha3_224,
95+
keccak512,
96+
keccak384,
97+
keccak256,
98+
keccak224,
99+
shake128,
100+
shake256,
101+
cshake128,
102+
cshake256,
103+
kmac128,
104+
kmac25
105+
} = require('js-sha3');
103106
```
107+
108+
### TypeScript
104109
If you use TypeScript, you can import like this:
105110
```TypeScript
106-
import { sha3_512 } from 'js-sha3';
111+
import {
112+
sha3_512,
113+
sha3_384,
114+
sha3_256,
115+
sha3_224,
116+
keccak512,
117+
keccak384,
118+
keccak256,
119+
keccak224,
120+
shake128,
121+
shake256,
122+
cshake128,
123+
cshake256,
124+
kmac128,
125+
kmac256
126+
} from 'js-sha3';
107127
```
108128

109129
## Example

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-sha3",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"main": ["src/sha3.js"],
55
"ignore": [
66
"samples",

build/sha3.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+21-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "js-sha3",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
55
"main": "src/sha3.js",
66
"devDependencies": {
77
"expect.js": "~0.3.1",
88
"mocha": "~10.2.0",
99
"nyc": "^15.1.0",
10-
"uglify-js": "^3.1.9",
11-
"webworker-threads": "^0.7.13"
10+
"tiny-worker": "^2.3.0",
11+
"uglify-js": "^3.1.9"
1212
},
1313
"scripts": {
1414
"test": "nyc mocha tests/node-test.js",

src/sha3.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* [js-sha3]{@link https://github.com/emn178/js-sha3}
33
*
4-
* @version 0.8.0
4+
* @version 0.9.0
55
* @author Chen, Yi-Cyuan [[email protected]]
6-
* @copyright Chen, Yi-Cyuan 2015-2018
6+
* @copyright Chen, Yi-Cyuan 2015-2023
77
* @license MIT
88
*/
99
/*jslint bitwise: true */
@@ -323,7 +323,7 @@
323323
for (var i = 0; i < strs.length; ++i) {
324324
bytes += this.encodeString(strs[i]);
325325
}
326-
var paddingBytes = w - bytes % w;
326+
var paddingBytes = (w - bytes % w) % w;
327327
var zeros = [];
328328
zeros.length = paddingBytes;
329329
this.update(zeros);

tests/node-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
expect = require('expect.js');
2-
Worker = require('webworker-threads').Worker;
2+
Worker = require("tiny-worker");
33

44
function unset() {
55
delete require.cache[require.resolve('../src/sha3.js')];

tests/test-kmac.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@
9494
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],
9595
s: 'My Tagged Application',
9696
output: 'b58618f71f92e1d56c1b8c55ddd7cd188b97b4ca4d99831eb2699a837da2e4d970fbacfde50033aea585f1a2708510c32d07880801bd182898fe476876fc8965'
97+
},
98+
{
99+
input: [],
100+
bits: 128,
101+
key: [],
102+
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],
103+
output: '031801b0b50ebeef772fbe7a279bc144'
97104
}
98105
]
99106
}
@@ -106,6 +113,6 @@
106113
expect(testCase.method(c.key, c.input, c.bits, c.s)).to.be(c.output);
107114
});
108115
});
109-
});
116+
});
110117
});
111118
})(kmac256, kmac128);

tests/worker-test.js

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
var worker = new Worker(WORKER);
1212
worker.onmessage = function(event) {
1313
expect(event.data).to.be(hash);
14+
if (worker.terminate) {
15+
worker.terminate();
16+
}
1417
done();
1518
};
1619
worker.postMessage(SOURCE);

0 commit comments

Comments
 (0)