diff --git a/.gitignore b/.gitignore index de038d6..9b18914 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ build node_modules npm-debug.log +package-lock.json +yarn-error.log +yarn.lock diff --git a/.travis.yml b/.travis.yml index bfbdfc8..319dffc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,13 @@ os: - osx language: node_js node_js: + - "5" - "6" - "8" - "10" - "11" + - "12" + - "13" addons: apt: sources: diff --git a/appveyor.yml b/appveyor.yml index 175bb2d..7b49515 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,11 +3,11 @@ build: off skip_tags: true environment: matrix: - - nodejs_version: "4" - - nodejs_version: "5" - nodejs_version: "6" - nodejs_version: "7" - nodejs_version: "8" + - nodejs_version: "10" + - nodejs_version: "12" platform: - x86 - x64 diff --git a/lib/api/index.js b/lib/api/index.js index a91ab19..b014e91 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -1,13 +1,13 @@ 'use strict' -var createKeccak = require('./keccak') -var createShake = require('./shake') +const createKeccak = require('./keccak') +const createShake = require('./shake') module.exports = function (KeccakState) { - var Keccak = createKeccak(KeccakState) - var Shake = createShake(KeccakState) + const Keccak = createKeccak(KeccakState) + const Shake = createShake(KeccakState) return function (algorithm, options) { - var hash = typeof algorithm === 'string' ? algorithm.toLowerCase() : algorithm + const hash = typeof algorithm === 'string' ? algorithm.toLowerCase() : algorithm switch (hash) { case 'keccak224': return new Keccak(1152, 448, null, 224, options) case 'keccak256': return new Keccak(1088, 512, null, 256, options) diff --git a/lib/api/keccak.js b/lib/api/keccak.js index fe384e3..26053c5 100644 --- a/lib/api/keccak.js +++ b/lib/api/keccak.js @@ -1,7 +1,7 @@ 'use strict' -var Buffer = require('safe-buffer').Buffer -var Transform = require('stream').Transform -var inherits = require('inherits') +const Buffer = require('safe-buffer').Buffer +const Transform = require('stream').Transform +const inherits = require('inherits') module.exports = function (KeccakState) { function Keccak (rate, capacity, delimitedSuffix, hashBitLength, options) { @@ -21,7 +21,7 @@ module.exports = function (KeccakState) { inherits(Keccak, Transform) Keccak.prototype._transform = function (chunk, encoding, callback) { - var error = null + let error = null try { this.update(chunk, encoding) } catch (err) { @@ -32,7 +32,7 @@ module.exports = function (KeccakState) { } Keccak.prototype._flush = function (callback) { - var error = null + let error = null try { this.push(this.digest()) } catch (err) { @@ -57,7 +57,7 @@ module.exports = function (KeccakState) { this._finalized = true if (this._delimitedSuffix) this._state.absorbLastFewBits(this._delimitedSuffix) - var digest = this._state.squeeze(this._hashBitLength / 8) + let digest = this._state.squeeze(this._hashBitLength / 8) if (encoding !== undefined) digest = digest.toString(encoding) this._resetState() @@ -73,7 +73,7 @@ module.exports = function (KeccakState) { // because sometimes we need hash right now and little later Keccak.prototype._clone = function () { - var clone = new Keccak(this._rate, this._capacity, this._delimitedSuffix, this._hashBitLength, this._options) + const clone = new Keccak(this._rate, this._capacity, this._delimitedSuffix, this._hashBitLength, this._options) this._state.copy(clone._state) clone._finalized = this._finalized diff --git a/lib/api/shake.js b/lib/api/shake.js index 103d802..c8d6a96 100644 --- a/lib/api/shake.js +++ b/lib/api/shake.js @@ -1,7 +1,7 @@ 'use strict' -var Buffer = require('safe-buffer').Buffer -var Transform = require('stream').Transform -var inherits = require('inherits') +const Buffer = require('safe-buffer').Buffer +const Transform = require('stream').Transform +const inherits = require('inherits') module.exports = function (KeccakState) { function Shake (rate, capacity, delimitedSuffix, options) { @@ -20,7 +20,7 @@ module.exports = function (KeccakState) { inherits(Shake, Transform) Shake.prototype._transform = function (chunk, encoding, callback) { - var error = null + let error = null try { this.update(chunk, encoding) } catch (err) { @@ -52,7 +52,7 @@ module.exports = function (KeccakState) { this._state.absorbLastFewBits(this._delimitedSuffix) } - var data = this._state.squeeze(dataByteLength) + let data = this._state.squeeze(dataByteLength) if (encoding !== undefined) data = data.toString(encoding) return data @@ -64,7 +64,7 @@ module.exports = function (KeccakState) { } Shake.prototype._clone = function () { - var clone = new Shake(this._rate, this._capacity, this._delimitedSuffix, this._options) + const clone = new Shake(this._rate, this._capacity, this._delimitedSuffix, this._options) this._state.copy(clone._state) clone._finalized = this._finalized diff --git a/lib/keccak-state-reference.js b/lib/keccak-state-reference.js index 1694534..d6918e7 100644 --- a/lib/keccak-state-reference.js +++ b/lib/keccak-state-reference.js @@ -1,6 +1,6 @@ 'use strict' -var P1600_RHO_OFFSETS = [0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14] -var P1600_ROUND_CONSTANTS = [ +const P1600_RHO_OFFSETS = [0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14] +const P1600_ROUND_CONSTANTS = [ 0x00000001, 0x00000000, 0x00008082, 0x00000000, 0x0000808a, 0x80000000, @@ -28,7 +28,7 @@ var P1600_ROUND_CONSTANTS = [ ] function p1600 (state) { - for (var round = 0; round < 24; ++round) { + for (let round = 0; round < 24; ++round) { theta(state) rho(state) pi(state) @@ -39,23 +39,23 @@ function p1600 (state) { // steps function theta (s) { - var clo = [0, 0, 0, 0, 0] - var chi = [0, 0, 0, 0, 0] + const clo = [0, 0, 0, 0, 0] + const chi = [0, 0, 0, 0, 0] - for (var x = 0; x < 5; ++x) { - for (var y = 0; y < 5; ++y) { + for (let x = 0; x < 5; ++x) { + for (let y = 0; y < 5; ++y) { clo[x] ^= s[ilo(x, y)] chi[x] ^= s[ihi(x, y)] } } - for (x = 0; x < 5; ++x) { - var next = (x + 1) % 5 - var prev = (x + 4) % 5 - var dlo = rol64lo(clo[next], chi[next], 1) ^ clo[prev] - var dhi = rol64hi(clo[next], chi[next], 1) ^ chi[prev] + for (let x = 0; x < 5; ++x) { + const next = (x + 1) % 5 + const prev = (x + 4) % 5 + const dlo = rol64lo(clo[next], chi[next], 1) ^ clo[prev] + const dhi = rol64hi(clo[next], chi[next], 1) ^ chi[prev] - for (y = 0; y < 5; ++y) { + for (let y = 0; y < 5; ++y) { s[ilo(x, y)] ^= dlo s[ihi(x, y)] ^= dhi } @@ -63,10 +63,10 @@ function theta (s) { } function rho (s) { - for (var x = 0; x < 5; ++x) { - for (var y = 0; y < 5; ++y) { - var lo = rol64lo(s[ilo(x, y)], s[ihi(x, y)], P1600_RHO_OFFSETS[index(x, y)]) - var hi = rol64hi(s[ilo(x, y)], s[ihi(x, y)], P1600_RHO_OFFSETS[index(x, y)]) + for (let x = 0; x < 5; ++x) { + for (let y = 0; y < 5; ++y) { + const lo = rol64lo(s[ilo(x, y)], s[ihi(x, y)], P1600_RHO_OFFSETS[index(x, y)]) + const hi = rol64hi(s[ilo(x, y)], s[ihi(x, y)], P1600_RHO_OFFSETS[index(x, y)]) s[ilo(x, y)] = lo s[ihi(x, y)] = hi } @@ -74,12 +74,12 @@ function rho (s) { } function pi (s) { - var ts = s.slice() + const ts = s.slice() - for (var x = 0; x < 5; ++x) { - for (var y = 0; y < 5; ++y) { - var nx = (0 * x + 1 * y) % 5 - var ny = (2 * x + 3 * y) % 5 + for (let x = 0; x < 5; ++x) { + for (let y = 0; y < 5; ++y) { + const nx = (0 * x + 1 * y) % 5 + const ny = (2 * x + 3 * y) % 5 s[ilo(nx, ny)] = ts[ilo(x, y)] s[ihi(nx, ny)] = ts[ihi(x, y)] } @@ -87,16 +87,16 @@ function pi (s) { } function chi (s) { - var clo = [0, 0, 0, 0, 0] - var chi = [0, 0, 0, 0, 0] + const clo = [0, 0, 0, 0, 0] + const chi = [0, 0, 0, 0, 0] - for (var y = 0; y < 5; ++y) { - for (var x = 0; x < 5; ++x) { + for (let y = 0; y < 5; ++y) { + for (let x = 0; x < 5; ++x) { clo[x] = s[ilo(x, y)] ^ (~s[ilo((x + 1) % 5, y)] & s[ilo((x + 2) % 5, y)]) chi[x] = s[ihi(x, y)] ^ (~s[ihi((x + 1) % 5, y)] & s[ihi((x + 2) % 5, y)]) } - for (x = 0; x < 5; ++x) { + for (let x = 0; x < 5; ++x) { s[ilo(x, y)] = clo[x] s[ihi(x, y)] = chi[x] } @@ -115,7 +115,7 @@ function ihi (x, y) { return index(x, y) * 2 + 1 } function rol64lo (lo, hi, shift) { if (shift >= 32) { - var t = lo + const t = lo lo = hi hi = t shift -= 32 @@ -126,7 +126,7 @@ function rol64lo (lo, hi, shift) { function rol64hi (lo, hi, shift) { if (shift >= 32) { - var t = lo + const t = lo lo = hi hi = t shift -= 32 diff --git a/lib/keccak-state-unroll.js b/lib/keccak-state-unroll.js index 5732e95..790bdf4 100644 --- a/lib/keccak-state-unroll.js +++ b/lib/keccak-state-unroll.js @@ -1,132 +1,132 @@ 'use strict' -var P1600_ROUND_CONSTANTS = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648] +const P1600_ROUND_CONSTANTS = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648] exports.p1600 = function (s) { - for (var round = 0; round < 24; ++round) { + for (let round = 0; round < 24; ++round) { // theta - var lo0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40] - var hi0 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41] - var lo1 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42] - var hi1 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43] - var lo2 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44] - var hi2 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45] - var lo3 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46] - var hi3 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47] - var lo4 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48] - var hi4 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49] + const lo0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40] + const hi0 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41] + const lo1 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42] + const hi1 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43] + const lo2 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44] + const hi2 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45] + const lo3 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46] + const hi3 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47] + const lo4 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48] + const hi4 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49] - var lo = lo4 ^ (lo1 << 1 | hi1 >>> 31) - var hi = hi4 ^ (hi1 << 1 | lo1 >>> 31) - var t1slo0 = s[0] ^ lo - var t1shi0 = s[1] ^ hi - var t1slo5 = s[10] ^ lo - var t1shi5 = s[11] ^ hi - var t1slo10 = s[20] ^ lo - var t1shi10 = s[21] ^ hi - var t1slo15 = s[30] ^ lo - var t1shi15 = s[31] ^ hi - var t1slo20 = s[40] ^ lo - var t1shi20 = s[41] ^ hi + let lo = lo4 ^ (lo1 << 1 | hi1 >>> 31) + let hi = hi4 ^ (hi1 << 1 | lo1 >>> 31) + const t1slo0 = s[0] ^ lo + const t1shi0 = s[1] ^ hi + const t1slo5 = s[10] ^ lo + const t1shi5 = s[11] ^ hi + const t1slo10 = s[20] ^ lo + const t1shi10 = s[21] ^ hi + const t1slo15 = s[30] ^ lo + const t1shi15 = s[31] ^ hi + const t1slo20 = s[40] ^ lo + const t1shi20 = s[41] ^ hi lo = lo0 ^ (lo2 << 1 | hi2 >>> 31) hi = hi0 ^ (hi2 << 1 | lo2 >>> 31) - var t1slo1 = s[2] ^ lo - var t1shi1 = s[3] ^ hi - var t1slo6 = s[12] ^ lo - var t1shi6 = s[13] ^ hi - var t1slo11 = s[22] ^ lo - var t1shi11 = s[23] ^ hi - var t1slo16 = s[32] ^ lo - var t1shi16 = s[33] ^ hi - var t1slo21 = s[42] ^ lo - var t1shi21 = s[43] ^ hi + const t1slo1 = s[2] ^ lo + const t1shi1 = s[3] ^ hi + const t1slo6 = s[12] ^ lo + const t1shi6 = s[13] ^ hi + const t1slo11 = s[22] ^ lo + const t1shi11 = s[23] ^ hi + const t1slo16 = s[32] ^ lo + const t1shi16 = s[33] ^ hi + const t1slo21 = s[42] ^ lo + const t1shi21 = s[43] ^ hi lo = lo1 ^ (lo3 << 1 | hi3 >>> 31) hi = hi1 ^ (hi3 << 1 | lo3 >>> 31) - var t1slo2 = s[4] ^ lo - var t1shi2 = s[5] ^ hi - var t1slo7 = s[14] ^ lo - var t1shi7 = s[15] ^ hi - var t1slo12 = s[24] ^ lo - var t1shi12 = s[25] ^ hi - var t1slo17 = s[34] ^ lo - var t1shi17 = s[35] ^ hi - var t1slo22 = s[44] ^ lo - var t1shi22 = s[45] ^ hi + const t1slo2 = s[4] ^ lo + const t1shi2 = s[5] ^ hi + const t1slo7 = s[14] ^ lo + const t1shi7 = s[15] ^ hi + const t1slo12 = s[24] ^ lo + const t1shi12 = s[25] ^ hi + const t1slo17 = s[34] ^ lo + const t1shi17 = s[35] ^ hi + const t1slo22 = s[44] ^ lo + const t1shi22 = s[45] ^ hi lo = lo2 ^ (lo4 << 1 | hi4 >>> 31) hi = hi2 ^ (hi4 << 1 | lo4 >>> 31) - var t1slo3 = s[6] ^ lo - var t1shi3 = s[7] ^ hi - var t1slo8 = s[16] ^ lo - var t1shi8 = s[17] ^ hi - var t1slo13 = s[26] ^ lo - var t1shi13 = s[27] ^ hi - var t1slo18 = s[36] ^ lo - var t1shi18 = s[37] ^ hi - var t1slo23 = s[46] ^ lo - var t1shi23 = s[47] ^ hi + const t1slo3 = s[6] ^ lo + const t1shi3 = s[7] ^ hi + const t1slo8 = s[16] ^ lo + const t1shi8 = s[17] ^ hi + const t1slo13 = s[26] ^ lo + const t1shi13 = s[27] ^ hi + const t1slo18 = s[36] ^ lo + const t1shi18 = s[37] ^ hi + const t1slo23 = s[46] ^ lo + const t1shi23 = s[47] ^ hi lo = lo3 ^ (lo0 << 1 | hi0 >>> 31) hi = hi3 ^ (hi0 << 1 | lo0 >>> 31) - var t1slo4 = s[8] ^ lo - var t1shi4 = s[9] ^ hi - var t1slo9 = s[18] ^ lo - var t1shi9 = s[19] ^ hi - var t1slo14 = s[28] ^ lo - var t1shi14 = s[29] ^ hi - var t1slo19 = s[38] ^ lo - var t1shi19 = s[39] ^ hi - var t1slo24 = s[48] ^ lo - var t1shi24 = s[49] ^ hi + const t1slo4 = s[8] ^ lo + const t1shi4 = s[9] ^ hi + const t1slo9 = s[18] ^ lo + const t1shi9 = s[19] ^ hi + const t1slo14 = s[28] ^ lo + const t1shi14 = s[29] ^ hi + const t1slo19 = s[38] ^ lo + const t1shi19 = s[39] ^ hi + const t1slo24 = s[48] ^ lo + const t1shi24 = s[49] ^ hi // rho & pi - var t2slo0 = t1slo0 - var t2shi0 = t1shi0 - var t2slo16 = (t1shi5 << 4 | t1slo5 >>> 28) - var t2shi16 = (t1slo5 << 4 | t1shi5 >>> 28) - var t2slo7 = (t1slo10 << 3 | t1shi10 >>> 29) - var t2shi7 = (t1shi10 << 3 | t1slo10 >>> 29) - var t2slo23 = (t1shi15 << 9 | t1slo15 >>> 23) - var t2shi23 = (t1slo15 << 9 | t1shi15 >>> 23) - var t2slo14 = (t1slo20 << 18 | t1shi20 >>> 14) - var t2shi14 = (t1shi20 << 18 | t1slo20 >>> 14) - var t2slo10 = (t1slo1 << 1 | t1shi1 >>> 31) - var t2shi10 = (t1shi1 << 1 | t1slo1 >>> 31) - var t2slo1 = (t1shi6 << 12 | t1slo6 >>> 20) - var t2shi1 = (t1slo6 << 12 | t1shi6 >>> 20) - var t2slo17 = (t1slo11 << 10 | t1shi11 >>> 22) - var t2shi17 = (t1shi11 << 10 | t1slo11 >>> 22) - var t2slo8 = (t1shi16 << 13 | t1slo16 >>> 19) - var t2shi8 = (t1slo16 << 13 | t1shi16 >>> 19) - var t2slo24 = (t1slo21 << 2 | t1shi21 >>> 30) - var t2shi24 = (t1shi21 << 2 | t1slo21 >>> 30) - var t2slo20 = (t1shi2 << 30 | t1slo2 >>> 2) - var t2shi20 = (t1slo2 << 30 | t1shi2 >>> 2) - var t2slo11 = (t1slo7 << 6 | t1shi7 >>> 26) - var t2shi11 = (t1shi7 << 6 | t1slo7 >>> 26) - var t2slo2 = (t1shi12 << 11 | t1slo12 >>> 21) - var t2shi2 = (t1slo12 << 11 | t1shi12 >>> 21) - var t2slo18 = (t1slo17 << 15 | t1shi17 >>> 17) - var t2shi18 = (t1shi17 << 15 | t1slo17 >>> 17) - var t2slo9 = (t1shi22 << 29 | t1slo22 >>> 3) - var t2shi9 = (t1slo22 << 29 | t1shi22 >>> 3) - var t2slo5 = (t1slo3 << 28 | t1shi3 >>> 4) - var t2shi5 = (t1shi3 << 28 | t1slo3 >>> 4) - var t2slo21 = (t1shi8 << 23 | t1slo8 >>> 9) - var t2shi21 = (t1slo8 << 23 | t1shi8 >>> 9) - var t2slo12 = (t1slo13 << 25 | t1shi13 >>> 7) - var t2shi12 = (t1shi13 << 25 | t1slo13 >>> 7) - var t2slo3 = (t1slo18 << 21 | t1shi18 >>> 11) - var t2shi3 = (t1shi18 << 21 | t1slo18 >>> 11) - var t2slo19 = (t1shi23 << 24 | t1slo23 >>> 8) - var t2shi19 = (t1slo23 << 24 | t1shi23 >>> 8) - var t2slo15 = (t1slo4 << 27 | t1shi4 >>> 5) - var t2shi15 = (t1shi4 << 27 | t1slo4 >>> 5) - var t2slo6 = (t1slo9 << 20 | t1shi9 >>> 12) - var t2shi6 = (t1shi9 << 20 | t1slo9 >>> 12) - var t2slo22 = (t1shi14 << 7 | t1slo14 >>> 25) - var t2shi22 = (t1slo14 << 7 | t1shi14 >>> 25) - var t2slo13 = (t1slo19 << 8 | t1shi19 >>> 24) - var t2shi13 = (t1shi19 << 8 | t1slo19 >>> 24) - var t2slo4 = (t1slo24 << 14 | t1shi24 >>> 18) - var t2shi4 = (t1shi24 << 14 | t1slo24 >>> 18) + const t2slo0 = t1slo0 + const t2shi0 = t1shi0 + const t2slo16 = (t1shi5 << 4 | t1slo5 >>> 28) + const t2shi16 = (t1slo5 << 4 | t1shi5 >>> 28) + const t2slo7 = (t1slo10 << 3 | t1shi10 >>> 29) + const t2shi7 = (t1shi10 << 3 | t1slo10 >>> 29) + const t2slo23 = (t1shi15 << 9 | t1slo15 >>> 23) + const t2shi23 = (t1slo15 << 9 | t1shi15 >>> 23) + const t2slo14 = (t1slo20 << 18 | t1shi20 >>> 14) + const t2shi14 = (t1shi20 << 18 | t1slo20 >>> 14) + const t2slo10 = (t1slo1 << 1 | t1shi1 >>> 31) + const t2shi10 = (t1shi1 << 1 | t1slo1 >>> 31) + const t2slo1 = (t1shi6 << 12 | t1slo6 >>> 20) + const t2shi1 = (t1slo6 << 12 | t1shi6 >>> 20) + const t2slo17 = (t1slo11 << 10 | t1shi11 >>> 22) + const t2shi17 = (t1shi11 << 10 | t1slo11 >>> 22) + const t2slo8 = (t1shi16 << 13 | t1slo16 >>> 19) + const t2shi8 = (t1slo16 << 13 | t1shi16 >>> 19) + const t2slo24 = (t1slo21 << 2 | t1shi21 >>> 30) + const t2shi24 = (t1shi21 << 2 | t1slo21 >>> 30) + const t2slo20 = (t1shi2 << 30 | t1slo2 >>> 2) + const t2shi20 = (t1slo2 << 30 | t1shi2 >>> 2) + const t2slo11 = (t1slo7 << 6 | t1shi7 >>> 26) + const t2shi11 = (t1shi7 << 6 | t1slo7 >>> 26) + const t2slo2 = (t1shi12 << 11 | t1slo12 >>> 21) + const t2shi2 = (t1slo12 << 11 | t1shi12 >>> 21) + const t2slo18 = (t1slo17 << 15 | t1shi17 >>> 17) + const t2shi18 = (t1shi17 << 15 | t1slo17 >>> 17) + const t2slo9 = (t1shi22 << 29 | t1slo22 >>> 3) + const t2shi9 = (t1slo22 << 29 | t1shi22 >>> 3) + const t2slo5 = (t1slo3 << 28 | t1shi3 >>> 4) + const t2shi5 = (t1shi3 << 28 | t1slo3 >>> 4) + const t2slo21 = (t1shi8 << 23 | t1slo8 >>> 9) + const t2shi21 = (t1slo8 << 23 | t1shi8 >>> 9) + const t2slo12 = (t1slo13 << 25 | t1shi13 >>> 7) + const t2shi12 = (t1shi13 << 25 | t1slo13 >>> 7) + const t2slo3 = (t1slo18 << 21 | t1shi18 >>> 11) + const t2shi3 = (t1shi18 << 21 | t1slo18 >>> 11) + const t2slo19 = (t1shi23 << 24 | t1slo23 >>> 8) + const t2shi19 = (t1slo23 << 24 | t1shi23 >>> 8) + const t2slo15 = (t1slo4 << 27 | t1shi4 >>> 5) + const t2shi15 = (t1shi4 << 27 | t1slo4 >>> 5) + const t2slo6 = (t1slo9 << 20 | t1shi9 >>> 12) + const t2shi6 = (t1shi9 << 20 | t1slo9 >>> 12) + const t2slo22 = (t1shi14 << 7 | t1slo14 >>> 25) + const t2shi22 = (t1slo14 << 7 | t1shi14 >>> 25) + const t2slo13 = (t1slo19 << 8 | t1shi19 >>> 24) + const t2shi13 = (t1shi19 << 8 | t1slo19 >>> 24) + const t2slo4 = (t1slo24 << 14 | t1shi24 >>> 18) + const t2shi4 = (t1shi24 << 14 | t1slo24 >>> 18) // chi s[0] = t2slo0 ^ (~t2slo1 & t2slo2) diff --git a/lib/keccak.js b/lib/keccak.js index 3ce0818..64ecd94 100644 --- a/lib/keccak.js +++ b/lib/keccak.js @@ -1,6 +1,6 @@ 'use strict' -var Buffer = require('safe-buffer').Buffer -var keccakState = require('./keccak-state-unroll') +const Buffer = require('safe-buffer').Buffer +const keccakState = require('./keccak-state-unroll') function Keccak () { // much faster than `new Array(50)` @@ -18,14 +18,14 @@ function Keccak () { } Keccak.prototype.initialize = function (rate, capacity) { - for (var i = 0; i < 50; ++i) this.state[i] = 0 + for (let i = 0; i < 50; ++i) this.state[i] = 0 this.blockSize = rate / 8 this.count = 0 this.squeezing = false } Keccak.prototype.absorb = function (data) { - for (var i = 0; i < data.length; ++i) { + for (let i = 0; i < data.length; ++i) { this.state[~~(this.count / 4)] ^= data[i] << (8 * (this.count % 4)) this.count += 1 if (this.count === this.blockSize) { @@ -47,7 +47,7 @@ Keccak.prototype.absorbLastFewBits = function (bits) { Keccak.prototype.squeeze = function (length) { if (!this.squeezing) this.absorbLastFewBits(0x01) - var output = Buffer.alloc(length) + const output = Buffer.alloc(length) for (var i = 0; i < length; ++i) { output[i] = (this.state[~~(this.count / 4)] >>> (8 * (this.count % 4))) & 0xff this.count += 1 @@ -61,7 +61,7 @@ Keccak.prototype.squeeze = function (length) { } Keccak.prototype.copy = function (dest) { - for (var i = 0; i < 50; ++i) dest.state[i] = this.state[i] + for (let i = 0; i < 50; ++i) dest.state[i] = this.state[i] dest.blockSize = this.blockSize dest.count = this.count dest.squeezing = this.squeezing diff --git a/package.json b/package.json index dcf198f..9a656a5 100644 --- a/package.json +++ b/package.json @@ -38,20 +38,20 @@ "unit": "tape test/index.js" }, "dependencies": { - "bindings": "^1.2.1", - "inherits": "^2.0.3", - "nan": "^2.2.1", - "safe-buffer": "^5.1.0" + "bindings": "^1.5.0", + "inherits": "^2.0.4", + "nan": "^2.14.0", + "safe-buffer": "^5.2.0" }, "devDependencies": { - "browserify": "^14.1.0", - "nyc": "^11.0.2", - "proxyquire": "^1.7.10", - "standard": "^10.0.2", - "tape": "^4.5.1" + "browserify": "^16.5.0", + "nyc": "^14.1.1", + "proxyquire": "^2.1.3", + "standard": "^14.3.1", + "tape": "^4.11.0" }, "engines": { - "node": ">=6.0.0" + "node": ">=5.12.0" }, "gypfile": true, "browser": { diff --git a/test/js-keccak.js b/test/js-keccak.js index 1351972..9a6bfcf 100644 --- a/test/js-keccak.js +++ b/test/js-keccak.js @@ -76,7 +76,7 @@ test('rol64lo', (t) => { [0b10000000000000000000000000000000, 0b00000000000000000000000000000000, 63, '0b01000000000000000000000000000000'] ] - for (let fixture of fixtures) { + for (const fixture of fixtures) { t.equal(to32bin(keccakState._rol64lo(fixture[0], fixture[1], fixture[2])), fixture[3]) } @@ -94,7 +94,7 @@ test('rol64hi', (t) => { [0b00000000000000000000000000000000, 0b10000000000000000000000000000000, 63, '0b01000000000000000000000000000000'] ] - for (let fixture of fixtures) { + for (const fixture of fixtures) { t.equal(to32bin(keccakState._rol64hi(fixture[0], fixture[1], fixture[2])), fixture[3]) } diff --git a/test/vectors-keccak.js b/test/vectors-keccak.js index c17f1b3..442a4f4 100644 --- a/test/vectors-keccak.js +++ b/test/vectors-keccak.js @@ -15,7 +15,7 @@ module.exports = (name, createHash) => { const vector = vectors[i] const data = Buffer.from(vector.input, 'hex') - for (let hash of ['keccak224', 'keccak256', 'keccak384', 'keccak512']) { + for (const hash of ['keccak224', 'keccak256', 'keccak384', 'keccak512']) { test(`${name} ${hash} vector#${i}`, (t) => { t.equal(createHash(hash).update(data).digest('hex'), vector[hash]) t.end() diff --git a/util/keccak-state-unroll.js b/util/keccak-state-unroll.js index c9441f7..26893b5 100644 --- a/util/keccak-state-unroll.js +++ b/util/keccak-state-unroll.js @@ -70,8 +70,8 @@ process.stdout.write(` `) for (let x = 0; x < 5; ++x) { - let next = (x + 1) % 5 - let prev = (x + 4) % 5 + const next = (x + 1) % 5 + const prev = (x + 4) % 5 process.stdout.write(` ${x === 0 ? 'var ' : ''}lo = lo${prev} ^ ${genROL64LO(`lo${next}`, `hi${next}`, 1)}`)