Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

final

Sha1.final
pub fn final(d: *Sha1, out: *[digest_length]u8) void

File

lib/std/crypto/Sha1.zig:68

Code

pub fn final(d: *Sha1, out: *[digest_length]u8) void {
    // The buffer here will never be completely full.
    @memset(d.buf[d.buf_len..], 0);

    // Append padding bits.
    d.buf[d.buf_len] = 0x80;
    d.buf_len += 1;

    // > 448 mod 512 so need to add an extra round to wrap around.
    if (64 - d.buf_len < 8) {
        d.round(d.buf[0..]);
        @memset(d.buf[0..], 0);
    }

    // Append message length.
    var i: usize = 1;
    var len = d.total_len >> 5;
    d.buf[63] = @as(u8, @intCast(d.total_len & 0x1f)) << 3;
    while (i < 8) : (i += 1) {
        d.buf[63 - i] = @as(u8, @intCast(len & 0xff));
        len >>= 8;
    }

    d.round(d.buf[0..]);

    for (d.s, 0..) |s, j| {
        mem.writeInt(u32, out[4 * j ..][0..4], s, .big);
    }
}