From 7ff3a3c828767485c141d0e8dc0dfa7eae96fc31 Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Thu, 27 Oct 2016 03:12:06 +0200 Subject: [PATCH] Only skip _doReset if _key has not been changed since last reset. --- src/aes.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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;