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.
TupleHashLike
sha3.TupleHashLike
fnTupleHashLike(comptimesecurity_level: u11, comptimedefault_delim: u8, comptimerounds: u5) type
fnTupleHashLike(comptimesecurity_level: u11, comptimedefault_delim: u8, comptimerounds: u5) type {
constCShaker = CShakeLike(security_level, default_delim, rounds, "TupleHash");
returnstruct {
constSelf = @This();
/// The output length, in bytes.pubconstdigest_length = CShaker.digest_length;
/// The block length, or rate, in bytes.pubconstblock_length = CShaker.block_length;
cshaker: CShaker,
xof_mode: bool = false,
/// TupleHash options can include a context string.pubconstOptions = struct {
context: ?[]constu8 = null,
};
/// Initialize a state for the TupleHash function, with an optional context./// If the context is going to be reused, the structure can be initialized once, and cloned for each message./// This is more efficient than reinitializing the state for each message at the cost of a small amount of memory.////// A key can be optionally added to the context to create a keyed TupleHash function, similar to KMAC.pubfninitWithOptions(options: Options) Self {
constcshaker = CShaker.init(.{ .context = options.context });
returnSelf{
.cshaker = cshaker,
};
}
/// Initialize a state for the MAC function.pubfninit() Self {
returninitWithOptions(.{});
}
/// Add data to the state, separated from previous updates.pubfnupdate(self: *Self, b: []constu8) void {
constencoded_b_len = NistLengthEncoding.encode(.left, b.len);
self.cshaker.update(encoded_b_len.slice());
self.cshaker.update(b);
}
/// Return an authentication tag for the current state.pubfnfinal(self: *Self, out: []u8) void {
constencoded_out_len = NistLengthEncoding.encode(.right, out.len);
self.cshaker.update(encoded_out_len.slice());
self.cshaker.final(out);
}
/// Align the input to a block boundary.pubfnfillBlock(self: *Self) void {
self.cshaker.fillBlock();
}
/// 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.xof_mode) {
constencoded_out_len = comptimeNistLengthEncoding.encode(.right, 0);
self.update(encoded_out_len.slice());
self.xof_mode = true;
}
self.cshaker.squeeze(out);
}
};
}