Skip to content

Commit

Permalink
## v0.9.0 / 2023-08-30
Browse files Browse the repository at this point in the history
### Fixed
- cSHAKE bug. #24
- dependencies and security issues.
  • Loading branch information
emn178 committed Aug 30, 2023
1 parent 5aecbd6 commit dbb0ea4
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 56 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Change Log

## v0.9.0 / 2023-08-30
### Fixed
- cSHAKE bug. #24
- dependencies and security issues.

## v0.8.0 / 2018-08-05
### Added
- TypeScript definitions.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,4 +1,4 @@
Copyright 2015-2018 Chen, Yi-Cyuan
Copyright 2015-2023 Chen, Yi-Cyuan

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
50 changes: 35 additions & 15 deletions README.md
Expand Up @@ -84,26 +84,46 @@ var hash = cshake128.create(256, 'function name', 'customization');
// specify kmac key, output bits and customization when creating
var hash = kmac128.create('key', 256, 'customization');
```
### Node.js
If you use node.js, you should require the module first:
```JavaScript
sha3_512 = require('js-sha3').sha3_512;
sha3_384 = require('js-sha3').sha3_384;
sha3_256 = require('js-sha3').sha3_256;
sha3_224 = require('js-sha3').sha3_224;
keccak512 = require('js-sha3').keccak512;
keccak384 = require('js-sha3').keccak384;
keccak256 = require('js-sha3').keccak256;
keccak224 = require('js-sha3').keccak224;
shake128 = require('js-sha3').shake128;
shake256 = require('js-sha3').shake256;
cshake128 = require('js-sha3').cshake128;
cshake256 = require('js-sha3').cshake256;
kmac128 = require('js-sha3').kmac128;
kmac256 = require('js-sha3').kmac256;
const {
sha3_512,
sha3_384,
sha3_256,
sha3_224,
keccak512,
keccak384,
keccak256,
keccak224,
shake128,
shake256,
cshake128,
cshake256,
kmac128,
kmac25
} = require('js-sha3');
```

### TypeScript
If you use TypeScript, you can import like this:
```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
Expand Down
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "js-sha3",
"version": "0.8.0",
"version": "0.9.0",
"main": ["src/sha3.js"],
"ignore": [
"samples",
Expand Down
6 changes: 3 additions & 3 deletions build/sha3.min.js

Large diffs are not rendered by default.

49 changes: 21 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
@@ -1,14 +1,14 @@
{
"name": "js-sha3",
"version": "0.8.0",
"version": "0.9.0",
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
"main": "src/sha3.js",
"devDependencies": {
"expect.js": "~0.3.1",
"mocha": "~10.2.0",
"nyc": "^15.1.0",
"uglify-js": "^3.1.9",
"webworker-threads": "^0.7.13"
"tiny-worker": "^2.3.0",
"uglify-js": "^3.1.9"
},
"scripts": {
"test": "nyc mocha tests/node-test.js",
Expand Down
6 changes: 3 additions & 3 deletions src/sha3.js
@@ -1,9 +1,9 @@
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.8.0
* @version 0.9.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2018
* @copyright Chen, Yi-Cyuan 2015-2023
* @license MIT
*/
/*jslint bitwise: true */
Expand Down Expand Up @@ -323,7 +323,7 @@
for (var i = 0; i < strs.length; ++i) {
bytes += this.encodeString(strs[i]);
}
var paddingBytes = w - bytes % w;
var paddingBytes = (w - bytes % w) % w;
var zeros = [];
zeros.length = paddingBytes;
this.update(zeros);
Expand Down
2 changes: 1 addition & 1 deletion tests/node-test.js
@@ -1,5 +1,5 @@
expect = require('expect.js');
Worker = require('webworker-threads').Worker;
Worker = require("tiny-worker");

function unset() {
delete require.cache[require.resolve('../src/sha3.js')];
Expand Down
9 changes: 8 additions & 1 deletion tests/test-kmac.js
Expand Up @@ -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],
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'
}
]
}
Expand All @@ -106,6 +113,6 @@
expect(testCase.method(c.key, c.input, c.bits, c.s)).to.be(c.output);
});
});
});
});
});
})(kmac256, kmac128);
3 changes: 3 additions & 0 deletions tests/worker-test.js
Expand Up @@ -11,6 +11,9 @@
var worker = new Worker(WORKER);
worker.onmessage = function(event) {
expect(event.data).to.be(hash);
if (worker.terminate) {
worker.terminate();
}
done();
};
worker.postMessage(SOURCE);
Expand Down

0 comments on commit dbb0ea4

Please sign in to comment.