diff --git a/src/aes.js b/src/aes.js index df7e1b2..aaf6e92 100644 --- a/src/aes.js +++ b/src/aes.js @@ -76,15 +76,18 @@ */ var AES = C_algo.AES = BlockCipher.extend({ _doReset: function () { - if (this._nRounds) return; + // Skip reset of nRounds has been set before and key did not change + if (this._nRounds && this._keyPriorReset === this._key) { + return; + } // Shortcuts - var key = this._key; + var key = this._keyPriorReset = this._key; var keyWords = key.words; var keySize = key.sigBytes / 4; // Compute number of rounds - var nRounds = this._nRounds = keySize + 6 + var nRounds = this._nRounds = keySize + 6; // Compute number of key schedule rows var ksRows = (nRounds + 1) * 4;