|
|
|
@ -1,19 +1,21 @@
|
|
|
|
|
/**
|
|
|
|
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
|
|
|
*
|
|
|
|
|
* @version 0.5.5
|
|
|
|
|
* @version 0.5.6
|
|
|
|
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
|
|
|
* @copyright Chen, Yi-Cyuan 2015-2016
|
|
|
|
|
* @license MIT
|
|
|
|
|
*/
|
|
|
|
|
(function (root) {
|
|
|
|
|
/*jslint bitwise: true */
|
|
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
|
|
|
|
|
var root = typeof window === 'object' ? window : {};
|
|
|
|
|
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
|
|
|
|
if (NODE_JS) {
|
|
|
|
|
root = global;
|
|
|
|
|
}
|
|
|
|
|
var COMMON_JS = !root.JS_SHA3_TEST && typeof module == 'object' && module.exports;
|
|
|
|
|
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
|
|
|
|
var HEX_CHARS = '0123456789abcdef'.split('');
|
|
|
|
|
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
|
|
|
|
|
var KECCAK_PADDING = [1, 256, 65536, 16777216];
|
|
|
|
@ -31,13 +33,13 @@
|
|
|
|
|
var createOutputMethod = function (bits, padding, outputType) {
|
|
|
|
|
return function (message) {
|
|
|
|
|
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var createShakeOutputMethod = function (bits, padding, outputType) {
|
|
|
|
|
return function (message, outputBits) {
|
|
|
|
|
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var createMethod = function (bits, padding) {
|
|
|
|
@ -76,13 +78,15 @@
|
|
|
|
|
{name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var methods = {};
|
|
|
|
|
var methods = {}, methodNames = [];
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < algorithms.length; ++i) {
|
|
|
|
|
var algorithm = algorithms[i];
|
|
|
|
|
var bits = algorithm.bits;
|
|
|
|
|
for (var j = 0; j < bits.length; ++j) {
|
|
|
|
|
methods[algorithm.name +'_' + bits[j]] = algorithm.createMethod(bits[j], algorithm.padding);
|
|
|
|
|
var methodName = algorithm.name +'_' + bits[j];
|
|
|
|
|
methodNames.push(methodName);
|
|
|
|
|
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -102,7 +106,7 @@
|
|
|
|
|
for (var i = 0; i < 50; ++i) {
|
|
|
|
|
this.s[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Keccak.prototype.update = function (message) {
|
|
|
|
|
var notString = typeof message != 'string';
|
|
|
|
@ -191,7 +195,7 @@
|
|
|
|
|
HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
|
|
|
|
|
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
|
|
|
|
}
|
|
|
|
|
if (j % blockCount == 0) {
|
|
|
|
|
if (j % blockCount === 0) {
|
|
|
|
|
f(s);
|
|
|
|
|
i = 0;
|
|
|
|
|
}
|
|
|
|
@ -228,7 +232,7 @@
|
|
|
|
|
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
|
|
|
array[j] = s[i];
|
|
|
|
|
}
|
|
|
|
|
if (j % blockCount == 0) {
|
|
|
|
|
if (j % blockCount === 0) {
|
|
|
|
|
f(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -256,7 +260,7 @@
|
|
|
|
|
array[offset + 2] = (block >> 16) & 0xFF;
|
|
|
|
|
array[offset + 3] = (block >> 24) & 0xFF;
|
|
|
|
|
}
|
|
|
|
|
if (j % blockCount == 0) {
|
|
|
|
|
if (j % blockCount === 0) {
|
|
|
|
|
f(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -459,13 +463,13 @@
|
|
|
|
|
s[0] ^= RC[n];
|
|
|
|
|
s[1] ^= RC[n + 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (COMMON_JS) {
|
|
|
|
|
module.exports = methods;
|
|
|
|
|
} else if (root) {
|
|
|
|
|
for (var key in methods) {
|
|
|
|
|
root[key] = methods[key];
|
|
|
|
|
} else {
|
|
|
|
|
for (var i = 0; i < methodNames.length; ++i) {
|
|
|
|
|
root[methodNames[i]] = methods[methodNames[i]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}(this));
|
|
|
|
|
})();
|
|
|
|
|