processBytes method

Uint8List processBytes(
  1. Uint8List inputBytes
)

Returns a new Uint8List with transformed inputBytes. This can encrypt and decrypt, since they are the same for Chacha20.

Implementation

Uint8List processBytes(Uint8List inputBytes) {
  chaCha20();
  Uint8List outputBytes = Uint8List(inputBytes.length);
  Uint8List nextChaChaBytes = chaChaState.buffer.asUint8List();

  for (int j = 0; j < outputBytes.length; j++) {
    outputBytes[j] = inputBytes[j] ^ nextChaChaBytes[j % 64];

    if (j % 64 == 0) {
      chaCha20();
      nextChaChaBytes = chaChaState.buffer.asUint8List();
    }
  }

  return outputBytes;
}