finish method

  1. @override
BLAKE2b finish(
  1. List<int> out
)
override

Finalizes the BLAKE2b hash, producing the hash digest and writing it to the given output List<int>.

If the hash was already finished, this method simply returns the digest. Otherwise, it completes the hash computation, marking it as finished.

Parameters:

  • out: The List<int> where the hash digest will be written.

Returns:

  • The BLAKE2b instance with the finalized hash state. The hash digest is also written to the provided List<int> 'out'.

Implementation

@override
BLAKE2b finish(List<int> out) {
  if (!_finished) {
    for (int i = _bufferLength; i < _blockSize; i++) {
      _buffer[i] = 0;
    }

    // Set last block flag.
    _flag[0] = mask32;
    _flag[1] = mask32;

    // Set last node flag if the last node in the tree.
    if (_lastNode) {
      _flag[2] = mask32;
      _flag[3] = mask32;
    }

    _processBlock(_bufferLength);
    _finished = true;
  }

  List<int> tmp = List<int>.filled(64, 0);
  for (int i = 0; i < 16; i++) {
    writeUint32LE(_state[i], tmp, i * 4);
  }
  out.setRange(0, out.length, tmp);
  return this;
}