process method

  1. @override
BuBytes process(
  1. List<int> src, [
  2. List<int>? dst
])

XORs src with the keystream (encrypt and decrypt are the same operation in CTR mode), writing src.length bytes into dst if given (dst must hold at least src.length bytes — GCM and Fortuna pass a longer buffer and fill the tail themselves).

Implementation

@override
BuBytes process(List<int> src, [List<int>? dst]) {
  final out = BuBytes.unsafeMutable(dst ?? List<int>.filled(src.length, 0));
  if (out.length < src.length) {
    throw CoreErrors.invalidOperationArguments(
      "process",
      name: "dst",
      reason: "Invalid destination bytes length.",
    );
  }
  for (var i = 0; i < src.length; i++) {
    if (_bufpos == _buffer.length) {
      _fillBuffer();
    }
    out[i] = (src[i] & BinaryOps.mask8) ^ _buffer[_bufpos++];
  }
  return out;
}