finish method
Finalizes the hash computation and stores the hash state in the provided List<int>
out
.
This function completes the hash computation, finalizes the state, and stores the resulting
hash in the provided out
List<int>
. If the hash has already been finished, this method
will return the existing state without re-computing.
Parameters:
out
: TheList<int>
in which the hash digest is stored.
Returns the current instance of the hash algorithm.
Implementation
@override
SerializableHash finish(List<int> out) {
if (!_finished) {
final bytesHashed = _bytesHashed;
final left = _bufferLength;
final bitLenHi = (bytesHashed ~/ 0x20000000) & 0xFFFFFFFF;
final bitLenLo = bytesHashed << 3;
final padLength = (bytesHashed % 64 < 56) ? 64 : 128;
_buffer[left] = 0x80;
for (var i = left + 1; i < padLength - 8; i++) {
_buffer[i] = 0;
}
writeUint32BE(bitLenHi, _buffer, padLength - 8);
writeUint32BE(bitLenLo, _buffer, padLength - 4);
_hashBlocks(_temp, _state, _buffer, 0, padLength);
_finished = true;
}
for (var i = 0; i < getDigestLength ~/ 4; i++) {
writeUint32BE(_state[i], out, i * 4);
}
return this;
}