Files
heros/node_modules/crypto-es/lib/mode-ofb.js
2024-07-17 16:14:14 +08:00

37 lines
756 B
JavaScript

import {
BlockCipherMode,
} from './cipher-core.js';
/**
* Output Feedback block mode.
*/
export class OFB extends BlockCipherMode {
}
OFB.Encryptor = class extends OFB {
processBlock(words, offset) {
const _words = words;
// Shortcuts
const cipher = this._cipher;
const { blockSize } = cipher;
const iv = this._iv;
let keystream = this._keystream;
// Generate keystream
if (iv) {
this._keystream = iv.slice(0);
keystream = this._keystream;
// Remove IV for subsequent blocks
this._iv = undefined;
}
cipher.encryptBlock(keystream, 0);
// Encrypt
for (let i = 0; i < blockSize; i += 1) {
_words[offset + i] ^= keystream[i];
}
}
};
OFB.Decryptor = OFB.Encryptor;