std.crypto: add finalResult and peek api for Sha1 (#16426)

close #16250
This commit is contained in:
George Zhao
2023-07-17 18:02:57 +08:00
committed by GitHub
parent a576082170
commit 9abe392647

View File

@@ -80,6 +80,11 @@ pub const Sha1 = struct {
d.total_len += b.len;
}
pub fn peek(d: Self) [digest_length]u8 {
var copy = d;
return copy.finalResult();
}
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
@memset(d.buf[d.buf_len..], 0);
@@ -110,6 +115,12 @@ pub const Sha1 = struct {
}
}
pub fn finalResult(d: *Self) [digest_length]u8 {
var result: [digest_length]u8 = undefined;
d.final(&result);
return result;
}
fn round(d: *Self, b: *const [64]u8) void {
var s: [16]u32 = undefined;