Fix all zeros after 16384 bytes with Blake3 (#2351)
Co-authored-by: GCHQDeveloper581 <63102987+GCHQDeveloper581@users.noreply.github.com> (added test)
This commit is contained in:
parent
8de0ded56c
commit
49002e15cf
8
package-lock.json
generated
8
package-lock.json
generated
@ -13,6 +13,7 @@
|
||||
"@alexaltea/capstone-js": "^3.0.5",
|
||||
"@astronautlabs/amf": "^0.0.6",
|
||||
"@blu3r4y/lzma": "^2.3.3",
|
||||
"@noble/hashes": "2.2.0",
|
||||
"@wavesenterprise/crypto-gost-js": "^2.1.0-RC1",
|
||||
"@xmldom/xmldom": "^0.8.13",
|
||||
"argon2-browser": "^1.18.0",
|
||||
@ -49,7 +50,6 @@
|
||||
"flat": "^6.0.1",
|
||||
"geodesy": "1.1.3",
|
||||
"handlebars": "^4.7.9",
|
||||
"hash-wasm": "^4.12.0",
|
||||
"highlight.js": "^11.11.1",
|
||||
"ieee754": "^1.2.1",
|
||||
"jimp": "1.6.0",
|
||||
@ -11018,12 +11018,6 @@
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/hash-wasm": {
|
||||
"version": "4.12.0",
|
||||
"resolved": "https://registry.npmjs.org/hash-wasm/-/hash-wasm-4.12.0.tgz",
|
||||
"integrity": "sha512-+/2B2rYLb48I/evdOIhP+K/DD2ca2fgBjp6O+GBEnCDk2e4rpeXIK8GvIyRPjTezgmWn9gmKwkQjjx6BtqDHVQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/hash.js": {
|
||||
"version": "1.1.7",
|
||||
"resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz",
|
||||
|
||||
@ -104,6 +104,7 @@
|
||||
"avsc": "^5.7.9",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"bignumber.js": "^9.3.1",
|
||||
"@noble/hashes": "2.2.0",
|
||||
"blakejs": "^1.2.1",
|
||||
"bootstrap": "4.6.2",
|
||||
"bootstrap-colorpicker": "^3.4.0",
|
||||
@ -132,7 +133,6 @@
|
||||
"flat": "^6.0.1",
|
||||
"geodesy": "1.1.3",
|
||||
"handlebars": "^4.7.9",
|
||||
"hash-wasm": "^4.12.0",
|
||||
"highlight.js": "^11.11.1",
|
||||
"ieee754": "^1.2.1",
|
||||
"jimp": "1.6.0",
|
||||
|
||||
@ -6,7 +6,10 @@
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import { blake3 } from "hash-wasm";
|
||||
import Utils from "../Utils.mjs";
|
||||
import { blake3 } from "@noble/hashes/blake3.js";
|
||||
import { bytesToHex } from "@noble/hashes/utils.js";
|
||||
|
||||
/**
|
||||
* BLAKE3 operation
|
||||
*/
|
||||
@ -44,13 +47,16 @@ class BLAKE3 extends Operation {
|
||||
run(input, args) {
|
||||
const key = args[1];
|
||||
const size = args[0];
|
||||
// Check if the user want a key hash or not
|
||||
if (key === "") {
|
||||
return blake3(input, size*8);
|
||||
} if (key.length !== 32) {
|
||||
throw new OperationError("The key must be exactly 32 bytes long");
|
||||
const opts = { dkLen: size };
|
||||
const inputBytes = new Uint8Array(Utils.strToArrayBuffer(input));
|
||||
if (key !== "") {
|
||||
const keyBytes = new Uint8Array(Utils.strToArrayBuffer(key));
|
||||
if (keyBytes.length !== 32) {
|
||||
throw new OperationError("The key must be exactly 32 bytes long");
|
||||
}
|
||||
opts.key = keyBytes;
|
||||
}
|
||||
return blake3(input, size*8, key);
|
||||
return bytesToHex(blake3(inputBytes, opts));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -51,5 +51,23 @@ TestRegister.addTests([
|
||||
{ "op": "BLAKE3",
|
||||
"args": [8, "ThiskeyisexactlythirtytwoByteslo"] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE3: 16390 - test",
|
||||
input: "test",
|
||||
expectedMatch: /4878.{32760}555fe06b242738d5/,
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE3",
|
||||
"args": [16390, ""] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE3: 16390 - key test",
|
||||
input: "test",
|
||||
expectedMatch: /a8d0.{32760}19ccd9b9726b46ae/,
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE3",
|
||||
"args": [16390, "ThiskeyisexactlythirtytwoBytesLo"] }
|
||||
]
|
||||
}
|
||||
]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user