update method

  1. @override
BLAKE2s update(
  1. List<int> data, {
  2. int? length,
})
override

Updates the hash with the provided data.

Implementation

@override
BLAKE2s update(List<int> data, {int? length}) {
  if (_finished) {
    throw const CryptoException(
      "blake2s: can't update because hash was finished.",
    );
  }

  final int left = _blockSize - _bufferLength;
  int dataPos = 0;

  int dataLength = length ?? data.length;

  if (dataLength == 0) {
    return this;
  }

  // Finish buffer.
  if (dataLength > left) {
    for (int i = 0; i < left; i++) {
      _buffer[_bufferLength + i] = data[dataPos + i] & BinaryOps.mask8;
    }
    _processBlock(_blockSize);
    dataPos += left;
    dataLength -= left;
    _bufferLength = 0;
  }

  // Process data blocks.
  while (dataLength > _blockSize) {
    for (int i = 0; i < _blockSize; i++) {
      _buffer[i] = data[dataPos + i] & BinaryOps.mask8;
    }
    _processBlock(_blockSize);
    dataPos += _blockSize;
    dataLength -= _blockSize;
    _bufferLength = 0;
  }

  // Copy leftovers to buffer.
  for (int i = 0; i < dataLength; i++) {
    _buffer[_bufferLength + i] = data[dataPos + i] & BinaryOps.mask8;
  }
  _bufferLength += dataLength;

  return this;
}