processBlock method
Process a whole block of data given by inp
and starting at offset
inpOff
.
The resulting cipher text is put in out
beginning at position outOff
.
This method returns the total bytes processed (which is the same as the block size of the algorithm).
Implementation
@override
int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) {
if ((inpOff + blockSize) > inp.length) {
throw ArgumentError('Input buffer too short');
}
if ((outOff + blockSize) > out.length) {
throw ArgumentError('Output buffer too short');
}
if (_firstStep) {
_firstStep = false;
_underlyingCipher.processBlock(_ofbV!, 0, _ofbOutV!, 0);
_n3 = _bytesToint(_ofbOutV, 0);
_n4 = _bytesToint(_ofbOutV, 4);
}
_n3 += C2;
_n4 += C1;
_intTobytes(_n3, _ofbV, 0);
_intTobytes(_n4, _ofbV, 4);
_underlyingCipher.processBlock(_ofbV!, 0, _ofbOutV!, 0);
// XOR the ofbV with the plaintext producing the cipher text (and the next input block).
for (var i = 0; i < blockSize; i++) {
out[outOff + i] = _ofbOutV![i] ^ inp[inpOff + i];
}
// change over the input block.
var offset = _ofbV!.length - blockSize;
_ofbV!.setRange(0, offset, _ofbV!.sublist(blockSize));
_ofbV!.setRange(offset, _ofbV!.length, _ofbOutV!);
return blockSize;
}