processBytes method
void
processBytes()
override
Process len
bytes of data given by inp
and starting at offset inpOff
.
The resulting cipher text is put in out
beginning at position outOff
.
Implementation
@override
void processBytes(
Uint8List inp, int inpOff, int len, Uint8List out, int outOff) {
if (!_initialised) {
throw StateError('ChaCha20 not initialized: please call init() first');
}
if ((inpOff + len) > inp.length) {
throw ArgumentError(
'Input buffer too short or requested length too long');
}
if ((outOff + len) > out.length) {
throw ArgumentError(
'Output buffer too short or requested length too long');
}
for (var i = 0; i < len; i++) {
if (_keyStreamOffset == 0) {
generateKeyStream(_keyStream);
if (++_state[12] == 0) {
++_state[13];
}
}
out[i + outOff] = clip8(_keyStream[_keyStreamOffset] ^ inp[i + inpOff]);
_keyStreamOffset = (_keyStreamOffset + 1) & 63;
}
}