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 standard library. Private Function
fnEMSA_PSS_VERIFY(msg: []const []constu8, em: []constu8, emBit: usize, sLen: usize, comptimeHash: type) VerifyError!void {
// 1. If the length of M is greater than the input limitation for// the hash function (2^61 - 1 octets for SHA-1), output// "inconsistent" and stop.// All the cryptographic hash functions in the standard library have a limit of >= 2^61 - 1.// Even then, this check is only there for paranoia. In the context of TLS certificates, emBit cannot exceed 4096.if (emBit >= 1 << 61) returnerror.InvalidSignature;
// emLen = \ceil(emBits/8)constemLen = ((emBit - 1) / 8) + 1;
std.debug.assert(emLen == em.len);
// 2. Let mHash = Hash(M), an octet string of length hLen.varmHash: [Hash.digest_length]u8 = undefined;
{
varhasher: Hash = .init(.{});
for (msg) |part| hasher.update(part);
hasher.final(&mHash);
}
// 3. If emLen < hLen + sLen + 2, output "inconsistent" and stop.if (emLen < Hash.digest_length + sLen + 2) {
returnerror.InvalidSignature;
}
// 4. If the rightmost octet of EM does not have hexadecimal value// 0xbc, output "inconsistent" and stop.if (em[em.len - 1] != 0xbc) {
returnerror.InvalidSignature;
}
// 5. Let maskedDB be the leftmost emLen - hLen - 1 octets of EM,// and let H be the next hLen octets.constmaskedDB = em[0..(emLen - Hash.digest_length - 1)];
consth = em[(emLen - Hash.digest_length - 1)..(emLen - 1)][0..Hash.digest_length];
// 6. If the leftmost 8emLen - emBits bits of the leftmost octet in// maskedDB are not all equal to zero, output "inconsistent" and// stop.constzero_bits = emLen * 8 - emBit;
varmask: u8 = maskedDB[0];
vari: usize = 0;
while (i < 8 - zero_bits) : (i += 1) {
mask = mask >> 1;
}
if (mask != 0) {
returnerror.InvalidSignature;
}
// 7. Let dbMask = MGF(H, emLen - hLen - 1).constmgf_len = emLen - Hash.digest_length - 1;
varmgf_out_buf: [512]u8 = undefined;
if (mgf_len > mgf_out_buf.len) { // Modulus > 4096 bitsreturnerror.InvalidSignature;
}
constmgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length];
vardbMask = tryMGF1(Hash, mgf_out, h, mgf_len);
// 8. Let DB = maskedDB \xor dbMask.i = 0;
while (i < dbMask.len) : (i += 1) {
dbMask[i] = maskedDB[i] ^ dbMask[i];
}
// 9. Set the leftmost 8emLen - emBits bits of the leftmost octet// in DB to zero.i = 0;
mask = 0;
while (i < 8 - zero_bits) : (i += 1) {
mask = mask << 1;
mask += 1;
}
dbMask[0] = dbMask[0] & mask;
// 10. If the emLen - hLen - sLen - 2 leftmost octets of DB are not// zero or if the octet at position emLen - hLen - sLen - 1 (the// leftmost position is "position 1") does not have hexadecimal// value 0x01, output "inconsistent" and stop.if (dbMask[mgf_len - sLen - 2] != 0x00) {
returnerror.InvalidSignature;
}
if (dbMask[mgf_len - sLen - 1] != 0x01) {
returnerror.InvalidSignature;
}
// 11. Let salt be the last sLen octets of DB.constsalt = dbMask[(mgf_len - sLen)..];
// 12. Let// M' = (0x)00 00 00 00 00 00 00 00 || mHash || salt ;// M' is an octet string of length 8 + hLen + sLen with eight// initial zero octets.if (sLen > Hash.digest_length) { // A seed larger than the hash length would be uselessreturnerror.InvalidSignature;
}
varm_p_buf: [8 + Hash.digest_length + Hash.digest_length]u8 = undefined;
varm_p = m_p_buf[0 .. 8 + Hash.digest_length + sLen];
@memmove(m_p[0..8], @as(*const [8]u8, &@splat(0)));
@memmove(m_p[8..][0..Hash.digest_length], &mHash);
@memmove(m_p[(8 + Hash.digest_length)..], salt);
// 13. Let H' = Hash(M'), an octet string of length hLen.varh_p: [Hash.digest_length]u8 = undefined;
Hash.hash(m_p, &h_p, .{});
// 14. If H = H', output "consistent". Otherwise, output// "inconsistent".if (!std.mem.eql(u8, h, &h_p)) {
returnerror.InvalidSignature;
}
}