processBlock method

  1. @override
int processBlock(
  1. Uint8List inp,
  2. int inpOff,
  3. Uint8List out,
  4. int outOff,
)
override

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');
  }

  _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;
}