DoxigAlpha

update

Add input to the hash state. This can be called any number of times.

Function parameters

Parameters

#
self:*Blake3
input_slice:[]const u8

An incremental hasher that can accept any number of writes.

Types

#
Blake3
An incremental hasher that can accept any number of writes.

Source

Implementation

#
pub fn update(self: *Blake3, input_slice: []const u8) void {
    var input = input_slice;
    while (input.len > 0) {
        // If the current chunk is complete, finalize it and reset the
        // chunk state. More input is coming, so this chunk is not ROOT.
        if (self.chunk_state.len() == CHUNK_LEN) {
            const chunk_cv = self.chunk_state.output().chainingValue();
            const total_chunks = self.chunk_state.chunk_counter + 1;
            self.addChunkChainingValue(chunk_cv, total_chunks);
            self.chunk_state = ChunkState.init(self.key, total_chunks, self.flags);
        }

        // Compress input bytes into the current chunk state.
        const want = CHUNK_LEN - self.chunk_state.len();
        const take = @min(want, input.len);
        self.chunk_state.update(input[0..take]);
        input = input[take..];
    }
}