Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In CTR mode, support to encrypt/decrypt from the middle of a message #1077

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/cipherModes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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) {
Expand Down