authorgravatar for zhaozg@gmail.comGeorge Zhao <zhaozg@gmail.com> 2023-07-17 18:02:57+08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-17 10:02:57+00:00
log9abe39264724934f3d3f657912d5ac62d97c26a8
tree9138ad9719aa8d7dcc44bc2ac6525bd09c3c5a20
parenta576082170b66087f92c09cc1c7315d43e04b39c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

close #16250

1 files changed, 11 insertions(+), 0 deletions(-)

lib/std/crypto/sha1.zig+11
......@@ -80,6 +80,11 @@ pub const Sha1 = struct {
8080 d.total_len += b.len;
8181 }
8282
83 pub fn peek(d: Self) [digest_length]u8 {
84 var copy = d;
85 return copy.finalResult();
86 }
87
8388 pub fn final(d: *Self, out: *[digest_length]u8) void {
8489 // The buffer here will never be completely full.
8590 @memset(d.buf[d.buf_len..], 0);
......@@ -110,6 +115,12 @@ pub const Sha1 = struct {
110115 }
111116 }
112117
118 pub fn finalResult(d: *Self) [digest_length]u8 {
119 var result: [digest_length]u8 = undefined;
120 d.final(&result);
121 return result;
122 }
123
113124 fn round(d: *Self, b: *const [64]u8) void {
114125 var s: [16]u32 = undefined;
115126