diff --git a/aes.js b/aes.js index 2dc7d69..ea0d080 100644 --- a/aes.js +++ b/aes.js @@ -113,14 +113,14 @@ class Aes { * * @private */ - static shiftRows(s, Nb) { - const t = new Array(4); - for (let r=1; r<4; r++) { - for (let c=0; c<4; c++) t[c] = s[r][(c+r)%Nb]; // shift into temp copy - for (let c=0; c<4; c++) s[r][c] = t[c]; // and copy back - } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES): - return s; // see asmaes.sourceforge.net/rijndael/rijndaelImplementation.pdf +static shiftRows(s, Nb) { + const t = new Array(4); + for (let r = 1; r < 4; r++) { + for (let c = 0; c < 4; c++) t[c] = s[r][(c + r) % Nb]; + for (let c = 0; c < 4; c++) s[r][c] = t[c]; } + return s; +} /** @@ -128,26 +128,28 @@ class Aes { * * @private */ - static mixColumns(s, Nb) { - for (let c=0; c0x100000000 ? 1 : 0); // carry top bit if lo > 2^32 - - return new Sha512.Long(hi >>> 0, lo >>> 0); - } - +add(that) { + const lo = this.lo + that.lo; + const carry = lo >= 0x100000000 ? 1 : 0; + const hi = this.hi + that.hi + carry; + return new Sha512.Long(hi >>> 0, lo >>> 0); +} and(that) { // & return new Sha512.Long(this.hi & that.hi, this.lo & that.lo); } @@ -257,7 +256,7 @@ Sha512.Long = class { } shr(n) { // >>> - if (n == 0) return this; + if (n == 0) return this; // no shit needed if (n == 32) return new Sha512.Long(0, this.hi); if (n > 32) return new Sha512.Long(0, this.hi >>> n-32); /* n < 32 */ return new Sha512.Long(this.hi >>> n, this.lo >>> n | this.hi << (32-n));