keccak unit tests

This commit is contained in:
2025-02-18 15:01:30 +01:00
parent a761bdb209
commit 7732504136
5 changed files with 124 additions and 82 deletions

View File

@ -146,27 +146,26 @@ function Keccak(rate, capacity, inputBytes, delimitedSuffix, outputByteLen) {
return new Uint8Array(output);
}
// SHAKE and SHA3 functions
function SHAKE128(inputBytes, outputByteLen) {
return Keccak(1344, 256, inputBytes, 0x1f, outputByteLen);
const keccak = {
// SHAKE and SHA3 functions
SHAKE128: (inputBytes, outputByteLen) => {
return Keccak(1344, 256, inputBytes, 0x1f, outputByteLen);
},
SHAKE256: (inputBytes, outputByteLen) => {
return Keccak(1088, 512, inputBytes, 0x1f, outputByteLen);
},
SHA3_224: (inputBytes) => {
return Keccak(1152, 448, inputBytes, 0x06, 224 / 8);
},
SHA3_256: (inputBytes) => {
return Keccak(1088, 512, inputBytes, 0x06, 256 / 8);
},
SHA3_384: (inputBytes) => {
return Keccak(832, 768, inputBytes, 0x06, 384 / 8);
},
SHA3_512: (inputBytes) => {
return Keccak(576, 1024, inputBytes, 0x06, 512 / 8);
}
}
function SHAKE256(inputBytes, outputByteLen) {
return Keccak(1088, 512, inputBytes, 0x1f, outputByteLen);
}
function SHA3_224(inputBytes) {
return Keccak(1152, 448, inputBytes, 0x06, 224 / 8);
}
function SHA3_256(inputBytes) {
return Keccak(1088, 512, inputBytes, 0x06, 256 / 8);
}
function SHA3_384(inputBytes) {
return Keccak(832, 768, inputBytes, 0x06, 384 / 8);
}
function SHA3_512(inputBytes) {
return Keccak(576, 1024, inputBytes, 0x06, 512 / 8);
}
module.exports = keccak;

9
src/stringutils.js Normal file
View File

@ -0,0 +1,9 @@
const stringutils = {
hexToArray: (hexString) => {
return Uint8Array.from(Buffer.from(hexString, 'hex'));
},
arrayToHex: (hex) => {
return Buffer.from(hex).toString('hex');
}
}
module.exports = stringutils;