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.
ShakeLike
sha3.ShakeLike
fnShakeLike(comptimesecurity_level: u11, comptimedefault_delim: u8, comptimerounds: u5) type
fnShakeLike(comptimesecurity_level: u11, comptimedefault_delim: u8, comptimerounds: u5) type {
constf = 1600;
constState = KeccakState(f, security_level * 2, rounds);
returnstruct {
constSelf = @This();
st: State,
buf: [State.rate]u8 = undefined,
offset: usize = 0,
padded: bool = false,
/// The recommended output length, in bytes.pubconstdigest_length = security_level / 8 * 2;
/// The block length, or rate, in bytes.pubconstblock_length = State.rate;
/// The delimiter can be overwritten in the options.pubconstOptions = struct { delim: u8 = default_delim };
/// Initialize a SHAKE extensible hash function.pubfninit(options: Options) Self {
returnSelf{ .st = .{ .delim = options.delim } };
}
/// Hash a slice of bytes./// `out` can be any length.pubfnhash(bytes: []constu8, out: []u8, options: Options) void {
varst = Self.init(options);
st.update(bytes);
st.squeeze(out);
}
/// Absorb a slice of bytes into the state.pubfnupdate(self: *Self, bytes: []constu8) void {
self.st.absorb(bytes);
}
/// Squeeze a slice of bytes from the state./// `out` can be any length, and the function can be called multiple times.pubfnsqueeze(self: *Self, out_: []u8) void {
if (!self.padded) {
self.st.pad();
self.padded = true;
}
varout = out_;
if (self.offset > 0) {
constleft = self.buf.len - self.offset;
if (left > 0) {
constn = @min(left, out.len);
@memcpy(out[0..n], self.buf[self.offset..][0..n]);
out = out[n..];
self.offset += n;
if (out.len == 0) {
return;
}
}
}
constfull_blocks = out[0 .. out.len - out.len % State.rate];
if (full_blocks.len > 0) {
self.st.squeeze(full_blocks);
out = out[full_blocks.len..];
}
if (out.len > 0) {
self.st.squeeze(self.buf[0..]);
@memcpy(out[0..], self.buf[0..out.len]);
self.offset = out.len;
}
}
/// Return the hash of the absorbed bytes./// `out` can be of any length, but the function must not be called multiple times (use `squeeze` for that purpose instead).pubfnfinal(self: *Self, out: []u8) void {
self.squeeze(out);
self.st.st.clear(0, State.rate);
}
/// Align the input to a block boundary.pubfnfillBlock(self: *Self) void {
self.st.fillBlock();
}
};
}