encryptBlock method
Encrypt exactly 1 block (16 bytes)
Implementation
@override
List<int> encryptBlock(List<int> src, [List<int>? dst]) {
final out = dst ?? List<int>.filled(blockSize, 0);
if (src.length != blockSize) {
throw ArgumentException.invalidOperationArguments(
"encryptBlock",
name: "src",
reason: "Invalid source bytes length.",
);
}
if (out.length != blockSize) {
throw ArgumentException.invalidOperationArguments(
"encryptBlock",
name: "dst",
reason: "Invalid destination bytes length.",
);
}
// CBC: XOR plaintext with previous ciphertext
for (int i = 0; i < blockSize; i++) {
_tmpBlock[i] = (src[i] ^ _prevBlock[i]).toU8;
}
// Encrypt XORed block
_cipher.encryptBlock(_tmpBlock, out);
// Update previous block for next round
_prevBlock.setAll(0, out);
return out;
}