diff --git a/lib/cipherModes.js b/lib/cipherModes.js index 339915cc..67277efc 100644 --- a/lib/cipherModes.js +++ b/lib/cipherModes.js @@ -446,6 +446,9 @@ modes.ctr.prototype.start = function(options) { // use IV as first input this._iv = transformIV(options.iv, this.blockSize); this._inBlock = this._iv.slice(0); + if(options.counter) { + inc32(this._inBlock, options.counter); + } this._partialBytes = 0; }; @@ -988,9 +991,9 @@ function transformIV(iv, blockSize) { return iv; } -function inc32(block) { +function inc32(block, count) { // increment last 32 bits of block only - block[block.length - 1] = (block[block.length - 1] + 1) & 0xFFFFFFFF; + block[block.length - 1] = (block[block.length - 1] + (count || 1)) & 0xFFFFFFFF; } function from64To32(num) {