[Pkg-javascript-commits] [node-browserify-aes] 23/43: aes: G does not need to be prototyped
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Sep 7 14:41:58 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-browserify-aes.
commit b17f514a49c9652f9d1911bec273ccf7063ac9c9
Author: Daniel Cousens <github at dcousens.com>
Date: Fri May 19 12:59:58 2017 +1000
aes: G does not need to be prototyped
---
aes.js | 95 +++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 51 insertions(+), 44 deletions(-)
diff --git a/aes.js b/aes.js
index 997ef4c..a0f59ef 100644
--- a/aes.js
+++ b/aes.js
@@ -23,49 +23,52 @@ function scrubVec (v) {
}
}
-function Global () {
- this.SBOX = []
- this.INV_SBOX = []
- this.SUB_MIX = [[], [], [], []]
- this.INV_SUB_MIX = [[], [], [], []]
- this.init()
- this.RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]
-}
-
-Global.prototype.init = function () {
- var d, i, sx, t, x, x2, x4, x8, xi, _i
- d = (function () {
- var _i, _results
- _results = []
- for (i = _i = 0; _i < 256; i = ++_i) {
- if (i < 128) {
- _results.push(i << 1)
- } else {
- _results.push((i << 1) ^ 0x11b)
- }
+var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]
+var G = (function () {
+ // Compute double table
+ var d = new Array(256)
+ for (var j = 0; j < 256; j++) {
+ if (j < 128) {
+ d[j] = j << 1
+ } else {
+ d[j] = (j << 1) ^ 0x11b
}
- return _results
- })()
- x = 0
- xi = 0
- for (i = _i = 0; _i < 256; i = ++_i) {
- sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4)
+ }
+
+ var SBOX = []
+ var INV_SBOX = []
+ var SUB_MIX = [[], [], [], []]
+ var INV_SUB_MIX = [[], [], [], []]
+
+ // Walk GF(2^8)
+ var x = 0
+ var xi = 0
+ for (var i = 0; i < 256; ++i) {
+ // Compute sbox
+ var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4)
sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63
- this.SBOX[x] = sx
- this.INV_SBOX[sx] = x
- x2 = d[x]
- x4 = d[x2]
- x8 = d[x4]
- t = (d[sx] * 0x101) ^ (sx * 0x1010100)
- this.SUB_MIX[0][x] = (t << 24) | (t >>> 8)
- this.SUB_MIX[1][x] = (t << 16) | (t >>> 16)
- this.SUB_MIX[2][x] = (t << 8) | (t >>> 24)
- this.SUB_MIX[3][x] = t
+ SBOX[x] = sx
+ INV_SBOX[sx] = x
+
+ // Compute multiplication
+ var x2 = d[x]
+ var x4 = d[x2]
+ var x8 = d[x4]
+
+ // Compute sub bytes, mix columns tables
+ var t = (d[sx] * 0x101) ^ (sx * 0x1010100)
+ SUB_MIX[0][x] = (t << 24) | (t >>> 8)
+ SUB_MIX[1][x] = (t << 16) | (t >>> 16)
+ SUB_MIX[2][x] = (t << 8) | (t >>> 24)
+ SUB_MIX[3][x] = t
+
+ // Compute inv sub bytes, inv mix columns tables
t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100)
- this.INV_SUB_MIX[0][sx] = (t << 24) | (t >>> 8)
- this.INV_SUB_MIX[1][sx] = (t << 16) | (t >>> 16)
- this.INV_SUB_MIX[2][sx] = (t << 8) | (t >>> 24)
- this.INV_SUB_MIX[3][sx] = t
+ INV_SUB_MIX[0][sx] = (t << 24) | (t >>> 8)
+ INV_SUB_MIX[1][sx] = (t << 16) | (t >>> 16)
+ INV_SUB_MIX[2][sx] = (t << 8) | (t >>> 24)
+ INV_SUB_MIX[3][sx] = t
+
if (x === 0) {
x = xi = 1
} else {
@@ -73,10 +76,14 @@ Global.prototype.init = function () {
xi ^= d[d[xi]]
}
}
- return true
-}
-var G = new Global()
+ return {
+ SBOX: SBOX,
+ INV_SBOX: INV_SBOX,
+ SUB_MIX: SUB_MIX,
+ INV_SUB_MIX: INV_SUB_MIX
+ }
+})()
AES.blockSize = 4 * 4
@@ -104,7 +111,7 @@ AES.prototype._doReset = function () {
}
for (k = keySize; k < ksRows; k++) {
- this._keySchedule[k] = (t = this._keySchedule[k - 1], (k % keySize) === 0 ? (t = (t << 8) | (t >>> 24), t = (G.SBOX[t >>> 24] << 24) | (G.SBOX[(t >>> 16) & 0xff] << 16) | (G.SBOX[(t >>> 8) & 0xff] << 8) | G.SBOX[t & 0xff], t ^= G.RCON[(k / keySize) | 0] << 24) : keySize > 6 && k % keySize === 4 ? t = (G.SBOX[t >>> 24] << 24) | (G.SBOX[(t >>> 16) & 0xff] << 16) | (G.SBOX[(t >>> 8) & 0xff] << 8) | G.SBOX[t & 0xff] : void 0, this._keySchedule[k - keySize] ^ t)
+ this._keySchedule[k] = (t = this._keySchedule[k - 1], (k % keySize) === 0 ? (t = (t << 8) | (t >>> 24), t = (G.SBOX[t >>> 24] << 24) | (G.SBOX[(t >>> 16) & 0xff] << 16) | (G.SBOX[(t >>> 8) & 0xff] << 8) | G.SBOX[t & 0xff], t ^= RCON[(k / keySize) | 0] << 24) : keySize > 6 && k % keySize === 4 ? t = (G.SBOX[t >>> 24] << 24) | (G.SBOX[(t >>> 16) & 0xff] << 16) | (G.SBOX[(t >>> 8) & 0xff] << 8) | G.SBOX[t & 0xff] : void 0, this._keySchedule[k - keySize] ^ t)
}
var invKeySchedule = []
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browserify-aes.git
More information about the Pkg-javascript-commits
mailing list