first
This commit is contained in:
40
node_modules/crypto-es/lib/mode-ctr.js
generated
vendored
Normal file
40
node_modules/crypto-es/lib/mode-ctr.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
BlockCipherMode,
|
||||
} from './cipher-core.js';
|
||||
|
||||
/**
|
||||
* Counter block mode.
|
||||
*/
|
||||
export class CTR extends BlockCipherMode {
|
||||
}
|
||||
CTR.Encryptor = class extends CTR {
|
||||
processBlock(words, offset) {
|
||||
const _words = words;
|
||||
|
||||
// Shortcuts
|
||||
const cipher = this._cipher;
|
||||
const { blockSize } = cipher;
|
||||
const iv = this._iv;
|
||||
let counter = this._counter;
|
||||
|
||||
// Generate keystream
|
||||
if (iv) {
|
||||
this._counter = iv.slice(0);
|
||||
counter = this._counter;
|
||||
|
||||
// Remove IV for subsequent blocks
|
||||
this._iv = undefined;
|
||||
}
|
||||
const keystream = counter.slice(0);
|
||||
cipher.encryptBlock(keystream, 0);
|
||||
|
||||
// Increment counter
|
||||
counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0;
|
||||
|
||||
// Encrypt
|
||||
for (let i = 0; i < blockSize; i += 1) {
|
||||
_words[offset + i] ^= keystream[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
CTR.Decryptor = CTR.Encryptor;
|
||||
Reference in New Issue
Block a user