Skip to content

Commit

Permalink
On BlockCipher reset, don't recreate _mode, just re-init.
Browse files Browse the repository at this point in the history
Crypto functions that need to reset their cipher a lot (such as CMAC) waste
a lot of time repeatedly re-creating the encryptor/decryptor.
  • Loading branch information
pkaminski committed Oct 27, 2016
1 parent 8940297 commit 39f543f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cipher-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,15 @@ CryptoJS.lib.Cipher || (function (undefined) {
var modeCreator = mode.createEncryptor;
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
var modeCreator = mode.createDecryptor;

// Keep at least one block in the buffer for unpadding
this._minBufferSize = 1;
}
this._mode = modeCreator.call(mode, this, iv && iv.words);
if (this._mode && this._modeCreator == modeCreator) {
this._mode.init(this, iv && iv.words);
} else {
this._mode = modeCreator.call(mode, this, iv && iv.words);
this._modeCreator = modeCreator;
}
},

_doProcessBlock: function (words, offset) {
Expand Down

0 comments on commit 39f543f

Please sign in to comment.