mirror of
https://github.com/emn178/js-sha3.git
synced 2026-08-12 19:41:36 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f95ceb733 |
@@ -1,5 +1,9 @@
|
||||
# Change Log
|
||||
|
||||
## v0.12.0 / 2026-07-18
|
||||
### Added
|
||||
- KMACXOF128 and KMACXOF256 (NIST SP 800-185)
|
||||
|
||||
## v0.11.0 / 2026-07-18
|
||||
### Added
|
||||
- TupleHash128, TupleHash256, TupleHashXOF128, and TupleHashXOF256 (NIST SP 800-185)
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
Copyright 2015-2023 Chen, Yi-Cyuan
|
||||
Copyright 2015-2026 Chen, Yi-Cyuan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -53,6 +53,8 @@ cshake128('Message to hash', 256, 'function name', 'customization');
|
||||
cshake256('Message to hash', 512, 'function name', 'customization');
|
||||
kmac128('key', 'Message to hash', 256, 'customization');
|
||||
kmac256('key', 'Message to hash', 512, 'customization');
|
||||
kmacxof128('key', 'Message to hash', 256, 'customization');
|
||||
kmacxof256('key', 'Message to hash', 512, 'customization');
|
||||
tuplehash128(['abc', 'd'], 256, 'customization');
|
||||
tuplehash256(['abc', 'd'], 512, 'customization');
|
||||
tuplehashxof128(['abc', 'd'], 256, 'customization');
|
||||
@@ -129,6 +131,8 @@ const {
|
||||
cshake256,
|
||||
kmac128,
|
||||
kmac256,
|
||||
kmacxof128,
|
||||
kmacxof256,
|
||||
tuplehash128,
|
||||
tuplehash256,
|
||||
tuplehashxof128,
|
||||
@@ -154,6 +158,8 @@ import {
|
||||
cshake256,
|
||||
kmac128,
|
||||
kmac256,
|
||||
kmacxof128,
|
||||
kmacxof256,
|
||||
tuplehash128,
|
||||
tuplehash256,
|
||||
tuplehashxof128,
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "js-sha3",
|
||||
"version": "0.9.3",
|
||||
"version": "0.12.0",
|
||||
"main": ["src/sha3.js"],
|
||||
"ignore": [
|
||||
"samples",
|
||||
|
||||
Vendored
+3
-3
File diff suppressed because one or more lines are too long
+3
-3
File diff suppressed because one or more lines are too long
+48
-54
@@ -9,9 +9,9 @@ var sha3$1 = {exports: {}};
|
||||
/**
|
||||
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
||||
*
|
||||
* @version 0.11.0
|
||||
* @version 0.12.0
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2015-2023
|
||||
* @copyright Chen, Yi-Cyuan 2015-2026
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
@@ -119,9 +119,15 @@ var sha3$1 = {exports: {}};
|
||||
};
|
||||
};
|
||||
|
||||
var createKmacOutputMethod = function (bits, padding, outputType) {
|
||||
var createKmacOutputMethod = function (bits, padding, xof, outputType) {
|
||||
return function (key, message, outputBits, s) {
|
||||
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
||||
return methods[(xof ? 'kmacxof' : 'kmac') + bits].update(key, message, outputBits, s)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
var createTupleHashOutputMethod = function (bits, padding, xof, outputType) {
|
||||
return function (inputs, outputBits, s) {
|
||||
return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -171,22 +177,18 @@ var sha3$1 = {exports: {}};
|
||||
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
||||
};
|
||||
|
||||
var createKmacMethod = function (bits, padding) {
|
||||
var createKmacMethod = function (bits, padding, xof) {
|
||||
var w = CSHAKE_BYTEPAD[bits];
|
||||
var method = createKmacOutputMethod(bits, padding, 'hex');
|
||||
var method = createKmacOutputMethod(bits, padding, xof, 'hex');
|
||||
method.create = function (key, outputBits, s) {
|
||||
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
||||
return new Kmac(bits, padding, outputBits, xof).bytepad(['KMAC', s], w).bytepad([key], w);
|
||||
};
|
||||
method.update = function (key, message, outputBits, s) {
|
||||
return method.create(key, outputBits, s).update(message);
|
||||
};
|
||||
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
||||
};
|
||||
|
||||
var createTupleHashOutputMethod = function (bits, padding, xof, outputType) {
|
||||
return function (inputs, outputBits, s) {
|
||||
return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType]();
|
||||
};
|
||||
return createOutputMethods(method, function (b, p, outputType) {
|
||||
return createKmacOutputMethod(b, p, xof, outputType);
|
||||
}, bits, padding);
|
||||
};
|
||||
|
||||
var createTupleHashMethod = function (bits, padding, xof) {
|
||||
@@ -215,7 +217,12 @@ var sha3$1 = {exports: {}};
|
||||
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
||||
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
||||
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
||||
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod },
|
||||
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
||||
return createKmacMethod(bits, padding, false);
|
||||
}},
|
||||
{ name: 'kmacxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
||||
return createKmacMethod(bits, padding, true);
|
||||
}},
|
||||
{ name: 'tuplehash', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
||||
return createTupleHashMethod(bits, padding, false);
|
||||
}},
|
||||
@@ -496,27 +503,27 @@ var sha3$1 = {exports: {}};
|
||||
return array;
|
||||
};
|
||||
|
||||
function Kmac(bits, padding, outputBits) {
|
||||
function Kmac(bits, padding, outputBits, xof) {
|
||||
Keccak.call(this, bits, padding, outputBits);
|
||||
this.xof = xof;
|
||||
}
|
||||
|
||||
Kmac.prototype = new Keccak();
|
||||
|
||||
Kmac.prototype.finalize = function () {
|
||||
if (!this.finalized) {
|
||||
this.encode(this.outputBits, true);
|
||||
this.encode(this.xof ? 0 : this.outputBits, true);
|
||||
}
|
||||
return Keccak.prototype.finalize.call(this);
|
||||
};
|
||||
|
||||
function TupleHash(bits, padding, outputBits, xof) {
|
||||
Keccak.call(this, bits, padding, outputBits);
|
||||
this.xof = !!xof;
|
||||
Kmac.call(this, bits, padding, outputBits, xof);
|
||||
this.inputActive = false;
|
||||
this.inputBytesRemaining = 0;
|
||||
}
|
||||
|
||||
TupleHash.prototype = new Keccak();
|
||||
TupleHash.prototype = new Kmac();
|
||||
|
||||
TupleHash.prototype.getMessageByteLength = function (message) {
|
||||
var result = formatMessage(message);
|
||||
@@ -542,9 +549,6 @@ var sha3$1 = {exports: {}};
|
||||
};
|
||||
|
||||
TupleHash.prototype.beginInput = function (byteLength) {
|
||||
if (this.finalized) {
|
||||
throw new Error(FINALIZE_ERROR);
|
||||
}
|
||||
if (this.inputActive) {
|
||||
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
||||
}
|
||||
@@ -553,28 +557,15 @@ var sha3$1 = {exports: {}};
|
||||
throw new Error(TUPLE_BYTE_LENGTH_ERROR);
|
||||
}
|
||||
this.encode(byteLength * 8, false);
|
||||
if (byteLength === 0) {
|
||||
this.inputActive = false;
|
||||
this.inputBytesRemaining = 0;
|
||||
} else {
|
||||
if (byteLength !== 0) {
|
||||
this.inputActive = true;
|
||||
this.inputBytesRemaining = byteLength;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
TupleHash.prototype.updateChunk = function (message) {
|
||||
if (this.finalized) {
|
||||
throw new Error(FINALIZE_ERROR);
|
||||
}
|
||||
if (!this.inputActive) {
|
||||
throw new Error(TUPLE_ACTIVE_ERROR);
|
||||
}
|
||||
var byteLength = this.getMessageByteLength(message);
|
||||
if (byteLength > this.inputBytesRemaining) {
|
||||
throw new Error(TUPLE_LENGTH_ERROR);
|
||||
}
|
||||
Keccak.prototype.update.call(this, message);
|
||||
TupleHash.prototype._updateChunk = function (message, byteLength) {
|
||||
Kmac.prototype.update.call(this, message);
|
||||
this.inputBytesRemaining -= byteLength;
|
||||
if (this.inputBytesRemaining === 0) {
|
||||
this.inputActive = false;
|
||||
@@ -582,29 +573,28 @@ var sha3$1 = {exports: {}};
|
||||
return this;
|
||||
};
|
||||
|
||||
TupleHash.prototype.update = function (message) {
|
||||
if (this.finalized) {
|
||||
throw new Error(FINALIZE_ERROR);
|
||||
}
|
||||
if (this.inputActive) {
|
||||
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
||||
TupleHash.prototype.updateChunk = function (message) {
|
||||
if (!this.inputActive) {
|
||||
throw new Error(TUPLE_ACTIVE_ERROR);
|
||||
}
|
||||
var byteLength = this.getMessageByteLength(message);
|
||||
this.beginInput(byteLength);
|
||||
if (byteLength === 0) {
|
||||
return this;
|
||||
if (byteLength > this.inputBytesRemaining) {
|
||||
throw new Error(TUPLE_LENGTH_ERROR);
|
||||
}
|
||||
return this.updateChunk(message);
|
||||
return this._updateChunk(message, byteLength);
|
||||
};
|
||||
|
||||
TupleHash.prototype.update = function (message) {
|
||||
var byteLength = this.getMessageByteLength(message);
|
||||
this.beginInput(byteLength);
|
||||
return this._updateChunk(message, byteLength);
|
||||
};
|
||||
|
||||
TupleHash.prototype.finalize = function () {
|
||||
if (this.inputActive) {
|
||||
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
||||
}
|
||||
if (!this.finalized) {
|
||||
this.encode(this.xof ? 0 : this.outputBits, true);
|
||||
}
|
||||
return Keccak.prototype.finalize.call(this);
|
||||
return Kmac.prototype.finalize.call(this);
|
||||
};
|
||||
|
||||
var f = function (s) {
|
||||
@@ -834,6 +824,10 @@ const {
|
||||
kmac_256,
|
||||
kmac128,
|
||||
kmac256,
|
||||
kmacxof_128,
|
||||
kmacxof_256,
|
||||
kmacxof128,
|
||||
kmacxof256,
|
||||
|
||||
tuplehash_128,
|
||||
tuplehash_256,
|
||||
@@ -845,4 +839,4 @@ const {
|
||||
tuplehashxof256
|
||||
} = sha3;
|
||||
|
||||
export { cshake128, cshake256, cshake_128, cshake_256, sha3 as default, keccak224, keccak256, keccak384, keccak512, keccak_224, keccak_256, keccak_384, keccak_512, kmac128, kmac256, kmac_128, kmac_256, sha3_224, sha3_256, sha3_384, sha3_512, shake128, shake256, shake_128, shake_256, tuplehash128, tuplehash256, tuplehash_128, tuplehash_256, tuplehashxof128, tuplehashxof256, tuplehashxof_128, tuplehashxof_256 };
|
||||
export { cshake128, cshake256, cshake_128, cshake_256, sha3 as default, keccak224, keccak256, keccak384, keccak512, keccak_224, keccak_256, keccak_384, keccak_512, kmac128, kmac256, kmac_128, kmac_256, kmacxof128, kmacxof256, kmacxof_128, kmacxof_256, sha3_224, sha3_256, sha3_384, sha3_512, shake128, shake256, shake_128, shake_256, tuplehash128, tuplehash256, tuplehash_128, tuplehash_256, tuplehashxof128, tuplehashxof256, tuplehashxof_128, tuplehashxof_256 };
|
||||
|
||||
Vendored
+4
@@ -405,6 +405,10 @@ export var kmac_128: KmacHash;
|
||||
export var kmac_256: KmacHash;
|
||||
export var kmac128: KmacHash;
|
||||
export var kmac256: KmacHash;
|
||||
export var kmacxof_128: KmacHash;
|
||||
export var kmacxof_256: KmacHash;
|
||||
export var kmacxof128: KmacHash;
|
||||
export var kmacxof256: KmacHash;
|
||||
export var tuplehash_128: TupleHashMethod;
|
||||
export var tuplehash_256: TupleHashMethod;
|
||||
export var tuplehash128: TupleHashMethod;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "js-sha3",
|
||||
"version": "0.11.0",
|
||||
"version": "0.12.0",
|
||||
"description": "A simple SHA-3 / Keccak / SHAKE / cSHAKE / KMAC / TupleHash hash function for JavaScript supports UTF-8 encoding.",
|
||||
"main": "src/sha3.js",
|
||||
"module": "build/sha3.mjs",
|
||||
|
||||
+43
-53
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
||||
*
|
||||
* @version 0.11.0
|
||||
* @version 0.12.0
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2015-2023
|
||||
* @copyright Chen, Yi-Cyuan 2015-2026
|
||||
* @license MIT
|
||||
*/
|
||||
/*jslint bitwise: true */
|
||||
@@ -111,9 +111,15 @@
|
||||
};
|
||||
};
|
||||
|
||||
var createKmacOutputMethod = function (bits, padding, outputType) {
|
||||
var createKmacOutputMethod = function (bits, padding, xof, outputType) {
|
||||
return function (key, message, outputBits, s) {
|
||||
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
||||
return methods[(xof ? 'kmacxof' : 'kmac') + bits].update(key, message, outputBits, s)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
var createTupleHashOutputMethod = function (bits, padding, xof, outputType) {
|
||||
return function (inputs, outputBits, s) {
|
||||
return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType]();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -163,22 +169,18 @@
|
||||
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
||||
};
|
||||
|
||||
var createKmacMethod = function (bits, padding) {
|
||||
var createKmacMethod = function (bits, padding, xof) {
|
||||
var w = CSHAKE_BYTEPAD[bits];
|
||||
var method = createKmacOutputMethod(bits, padding, 'hex');
|
||||
var method = createKmacOutputMethod(bits, padding, xof, 'hex');
|
||||
method.create = function (key, outputBits, s) {
|
||||
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
||||
return new Kmac(bits, padding, outputBits, xof).bytepad(['KMAC', s], w).bytepad([key], w);
|
||||
};
|
||||
method.update = function (key, message, outputBits, s) {
|
||||
return method.create(key, outputBits, s).update(message);
|
||||
};
|
||||
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
||||
};
|
||||
|
||||
var createTupleHashOutputMethod = function (bits, padding, xof, outputType) {
|
||||
return function (inputs, outputBits, s) {
|
||||
return methods[(xof ? 'tuplehashxof' : 'tuplehash') + bits].update(inputs, outputBits, s)[outputType]();
|
||||
};
|
||||
return createOutputMethods(method, function (b, p, outputType) {
|
||||
return createKmacOutputMethod(b, p, xof, outputType);
|
||||
}, bits, padding);
|
||||
};
|
||||
|
||||
var createTupleHashMethod = function (bits, padding, xof) {
|
||||
@@ -207,7 +209,12 @@
|
||||
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
||||
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
||||
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
||||
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod },
|
||||
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
||||
return createKmacMethod(bits, padding, false);
|
||||
}},
|
||||
{ name: 'kmacxof', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
||||
return createKmacMethod(bits, padding, true);
|
||||
}},
|
||||
{ name: 'tuplehash', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: function (bits, padding) {
|
||||
return createTupleHashMethod(bits, padding, false);
|
||||
}},
|
||||
@@ -488,27 +495,27 @@
|
||||
return array;
|
||||
};
|
||||
|
||||
function Kmac(bits, padding, outputBits) {
|
||||
function Kmac(bits, padding, outputBits, xof) {
|
||||
Keccak.call(this, bits, padding, outputBits);
|
||||
this.xof = xof;
|
||||
}
|
||||
|
||||
Kmac.prototype = new Keccak();
|
||||
|
||||
Kmac.prototype.finalize = function () {
|
||||
if (!this.finalized) {
|
||||
this.encode(this.outputBits, true);
|
||||
this.encode(this.xof ? 0 : this.outputBits, true);
|
||||
}
|
||||
return Keccak.prototype.finalize.call(this);
|
||||
};
|
||||
|
||||
function TupleHash(bits, padding, outputBits, xof) {
|
||||
Keccak.call(this, bits, padding, outputBits);
|
||||
this.xof = !!xof;
|
||||
Kmac.call(this, bits, padding, outputBits, xof);
|
||||
this.inputActive = false;
|
||||
this.inputBytesRemaining = 0;
|
||||
}
|
||||
|
||||
TupleHash.prototype = new Keccak();
|
||||
TupleHash.prototype = new Kmac();
|
||||
|
||||
TupleHash.prototype.getMessageByteLength = function (message) {
|
||||
var result = formatMessage(message);
|
||||
@@ -534,9 +541,6 @@
|
||||
};
|
||||
|
||||
TupleHash.prototype.beginInput = function (byteLength) {
|
||||
if (this.finalized) {
|
||||
throw new Error(FINALIZE_ERROR);
|
||||
}
|
||||
if (this.inputActive) {
|
||||
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
||||
}
|
||||
@@ -545,28 +549,15 @@
|
||||
throw new Error(TUPLE_BYTE_LENGTH_ERROR);
|
||||
}
|
||||
this.encode(byteLength * 8, false);
|
||||
if (byteLength === 0) {
|
||||
this.inputActive = false;
|
||||
this.inputBytesRemaining = 0;
|
||||
} else {
|
||||
if (byteLength !== 0) {
|
||||
this.inputActive = true;
|
||||
this.inputBytesRemaining = byteLength;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
TupleHash.prototype.updateChunk = function (message) {
|
||||
if (this.finalized) {
|
||||
throw new Error(FINALIZE_ERROR);
|
||||
}
|
||||
if (!this.inputActive) {
|
||||
throw new Error(TUPLE_ACTIVE_ERROR);
|
||||
}
|
||||
var byteLength = this.getMessageByteLength(message);
|
||||
if (byteLength > this.inputBytesRemaining) {
|
||||
throw new Error(TUPLE_LENGTH_ERROR);
|
||||
}
|
||||
Keccak.prototype.update.call(this, message);
|
||||
TupleHash.prototype._updateChunk = function (message, byteLength) {
|
||||
Kmac.prototype.update.call(this, message);
|
||||
this.inputBytesRemaining -= byteLength;
|
||||
if (this.inputBytesRemaining === 0) {
|
||||
this.inputActive = false;
|
||||
@@ -574,29 +565,28 @@
|
||||
return this;
|
||||
};
|
||||
|
||||
TupleHash.prototype.update = function (message) {
|
||||
if (this.finalized) {
|
||||
throw new Error(FINALIZE_ERROR);
|
||||
}
|
||||
if (this.inputActive) {
|
||||
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
||||
TupleHash.prototype.updateChunk = function (message) {
|
||||
if (!this.inputActive) {
|
||||
throw new Error(TUPLE_ACTIVE_ERROR);
|
||||
}
|
||||
var byteLength = this.getMessageByteLength(message);
|
||||
this.beginInput(byteLength);
|
||||
if (byteLength === 0) {
|
||||
return this;
|
||||
if (byteLength > this.inputBytesRemaining) {
|
||||
throw new Error(TUPLE_LENGTH_ERROR);
|
||||
}
|
||||
return this.updateChunk(message);
|
||||
return this._updateChunk(message, byteLength);
|
||||
};
|
||||
|
||||
TupleHash.prototype.update = function (message) {
|
||||
var byteLength = this.getMessageByteLength(message);
|
||||
this.beginInput(byteLength);
|
||||
return this._updateChunk(message, byteLength);
|
||||
};
|
||||
|
||||
TupleHash.prototype.finalize = function () {
|
||||
if (this.inputActive) {
|
||||
throw new Error(TUPLE_INCOMPLETE_ERROR);
|
||||
}
|
||||
if (!this.finalized) {
|
||||
this.encode(this.xof ? 0 : this.outputBits, true);
|
||||
}
|
||||
return Keccak.prototype.finalize.call(this);
|
||||
return Kmac.prototype.finalize.call(this);
|
||||
};
|
||||
|
||||
var f = function (s) {
|
||||
|
||||
@@ -29,6 +29,10 @@ export const {
|
||||
kmac_256,
|
||||
kmac128,
|
||||
kmac256,
|
||||
kmacxof_128,
|
||||
kmacxof_256,
|
||||
kmacxof128,
|
||||
kmacxof256,
|
||||
|
||||
tuplehash_128,
|
||||
tuplehash_256,
|
||||
|
||||
@@ -16,6 +16,8 @@ function unset() {
|
||||
shake256 = null;
|
||||
kmac128 = null;
|
||||
kmac256 = null;
|
||||
kmacxof128 = null;
|
||||
kmacxof256 = null;
|
||||
tuplehash128 = null;
|
||||
tuplehash256 = null;
|
||||
tuplehashxof128 = null;
|
||||
@@ -45,6 +47,8 @@ function requireToGlobal() {
|
||||
cshake256 = sha3.cshake256;
|
||||
kmac128 = sha3.kmac128;
|
||||
kmac256 = sha3.kmac256;
|
||||
kmacxof128 = sha3.kmacxof128;
|
||||
kmacxof256 = sha3.kmacxof256;
|
||||
tuplehash128 = sha3.tuplehash128;
|
||||
tuplehash256 = sha3.tuplehash256;
|
||||
tuplehashxof128 = sha3.tuplehashxof128;
|
||||
@@ -117,6 +121,8 @@ define = function (func) {
|
||||
cshake256 = sha3.cshake256;
|
||||
kmac128 = sha3.kmac128;
|
||||
kmac256 = sha3.kmac256;
|
||||
kmacxof128 = sha3.kmacxof128;
|
||||
kmacxof256 = sha3.kmacxof256;
|
||||
tuplehash128 = sha3.tuplehash128;
|
||||
tuplehash256 = sha3.tuplehash256;
|
||||
tuplehashxof128 = sha3.tuplehashxof128;
|
||||
|
||||
+95
-56
@@ -1,42 +1,47 @@
|
||||
(function (kmac256, kmac128) {
|
||||
(function (kmac256, kmac128, kmacxof256, kmacxof128) {
|
||||
// http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/KMAC_samples.pdf
|
||||
// https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/KMACXOF_samples.pdf
|
||||
var 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];
|
||||
var shortInput = [0x00, 0x01, 0x02, 0x03];
|
||||
var longInput = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
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,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7
|
||||
];
|
||||
|
||||
var testCases = [
|
||||
{
|
||||
name: 'kmac128',
|
||||
method: kmac128,
|
||||
cases: [
|
||||
{
|
||||
input: [0x00, 0x01, 0x02, 0x03],
|
||||
input: shortInput,
|
||||
bits: 256,
|
||||
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],
|
||||
key: key,
|
||||
s: '',
|
||||
output: 'e5780b0d3ea6f7d3a429c5706aa43a00fadbd7d49628839e3187243f456ee14e'
|
||||
},
|
||||
{
|
||||
input: [0x00, 0x01, 0x02, 0x03],
|
||||
input: shortInput,
|
||||
bits: 256,
|
||||
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],
|
||||
key: key,
|
||||
s: 'My Tagged Application',
|
||||
output: '3b1fba963cd8b0b59e8c1a6d71888b7143651af8ba0a7070c0979e2811324aa5'
|
||||
},
|
||||
{
|
||||
input: [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
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,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7
|
||||
],
|
||||
input: longInput,
|
||||
bits: 256,
|
||||
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],
|
||||
key: key,
|
||||
s: 'My Tagged Application',
|
||||
output: '1f5b4e6cca02209e0dcb5ca635b89a15e271ecc760071dfd805faa38f9729230'
|
||||
}
|
||||
@@ -47,51 +52,23 @@
|
||||
method: kmac256,
|
||||
cases: [
|
||||
{
|
||||
input: [0x00, 0x01, 0x02, 0x03],
|
||||
input: shortInput,
|
||||
bits: 512,
|
||||
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],
|
||||
key: key,
|
||||
s: 'My Tagged Application',
|
||||
output: '20c570c31346f703c9ac36c61c03cb64c3970d0cfc787e9b79599d273a68d2f7f69d4cc3de9d104a351689f27cf6f5951f0103f33f4f24871024d9c27773a8dd'
|
||||
},
|
||||
{
|
||||
input: [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
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,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7
|
||||
],
|
||||
input: longInput,
|
||||
bits: 512,
|
||||
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],
|
||||
key: key,
|
||||
s: '',
|
||||
output: '75358cf39e41494e949707927cee0af20a3ff553904c86b08f21cc414bcfd691589d27cf5e15369cbbff8b9a4c2eb17800855d0235ff635da82533ec6b759b69'
|
||||
},
|
||||
{
|
||||
input: [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
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,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7
|
||||
],
|
||||
input: longInput,
|
||||
bits: 512,
|
||||
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],
|
||||
key: key,
|
||||
s: 'My Tagged Application',
|
||||
output: 'b58618f71f92e1d56c1b8c55ddd7cd188b97b4ca4d99831eb2699a837da2e4d970fbacfde50033aea585f1a2708510c32d07880801bd182898fe476876fc8965'
|
||||
},
|
||||
@@ -103,6 +80,60 @@
|
||||
output: '031801b0b50ebeef772fbe7a279bc144'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'kmacxof128',
|
||||
method: kmacxof128,
|
||||
cases: [
|
||||
{
|
||||
input: shortInput,
|
||||
bits: 256,
|
||||
key: key,
|
||||
s: '',
|
||||
output: 'cd83740bbd92ccc8cf032b1481a0f4460e7ca9dd12b08a0c4031178bacd6ec35'
|
||||
},
|
||||
{
|
||||
input: shortInput,
|
||||
bits: 256,
|
||||
key: key,
|
||||
s: 'My Tagged Application',
|
||||
output: '31a44527b4ed9f5c6101d11de6d26f0620aa5c341def41299657fe9df1a3b16c'
|
||||
},
|
||||
{
|
||||
input: longInput,
|
||||
bits: 256,
|
||||
key: key,
|
||||
s: 'My Tagged Application',
|
||||
output: '47026c7cd793084aa0283c253ef658490c0db61438b8326fe9bddf281b83ae0f'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'kmacxof256',
|
||||
method: kmacxof256,
|
||||
cases: [
|
||||
{
|
||||
input: shortInput,
|
||||
bits: 512,
|
||||
key: key,
|
||||
s: 'My Tagged Application',
|
||||
output: '1755133f1534752aad0748f2c706fb5c784512cab835cd15676b16c0c6647fa96faa7af634a0bf8ff6df39374fa00fad9a39e322a7c92065a64eb1fb0801eb2b'
|
||||
},
|
||||
{
|
||||
input: longInput,
|
||||
bits: 512,
|
||||
key: key,
|
||||
s: '',
|
||||
output: 'ff7b171f1e8a2b24683eed37830ee797538ba8dc563f6da1e667391a75edc02ca633079f81ce12a25f45615ec89972031d18337331d24ceb8f8ca8e6a19fd98b'
|
||||
},
|
||||
{
|
||||
input: longInput,
|
||||
bits: 512,
|
||||
key: key,
|
||||
s: 'My Tagged Application',
|
||||
output: 'd5be731c954ed7732846bb59dbe3a8e30f83e77a4bff4459f2f1c2b4ecebb8ce67ba01c62e8ab8578d2d499bd1bb276768781190020a306a97de281dcc30305d'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
@@ -115,4 +146,12 @@
|
||||
});
|
||||
});
|
||||
});
|
||||
})(kmac256, kmac128);
|
||||
|
||||
describe('#kmacxof aliases', function () {
|
||||
it('should export identical aliases', function () {
|
||||
var sha3 = require('../src/sha3.js');
|
||||
expect(sha3.kmacxof128).to.be(sha3.kmacxof_128);
|
||||
expect(sha3.kmacxof256).to.be(sha3.kmacxof_256);
|
||||
});
|
||||
});
|
||||
})(kmac256, kmac128, kmacxof256, kmacxof128);
|
||||
|
||||
@@ -203,7 +203,7 @@
|
||||
expect(array).to.eql(digest);
|
||||
expect(Array.prototype.slice.call(new Uint8Array(buffer))).to.eql(array);
|
||||
expect(function () { hash.update(t1); }).to.throwError(/finalize already called/);
|
||||
expect(function () { hash.updateChunk(t1); }).to.throwError(/finalize already called/);
|
||||
expect(function () { hash.updateChunk(t1); }).to.throwError(/no active tuple input/);
|
||||
});
|
||||
|
||||
it('should require customization like KMAC', function () {
|
||||
|
||||
Reference in New Issue
Block a user