authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-01 22:54:32+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-01 22:54:32+02:00
loga0501add57ff187193ddfa3c79b3d26cc96fa1d8
treedf657979485b15475935d5268edacb783bcf63f9
parent7f8f2b16a0a523a1473b172e9f8a585087e879fc
parent345b71793664d8d69b04be1d81c22409ddcf54bd

Merge pull request 'std.crypto: add missing finalResult methods' (#36918) from nektro/fork-zig:nektro-patch-43911 into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36918 Reviewed-by: Frank Denis <jedisct1@noreply.codeberg.org>

12 files changed, 78 insertions(+), 0 deletions(-)

lib/std/crypto/aegis.zig+6
......@@ -794,6 +794,12 @@ fn AegisMac(comptime T: type) type {
794794 out.* = self.state.finalizeMac(T.tag_length * 8, self.msg_len);
795795 }
796796
797 pub fn finalResult(d: *Mac) [mac_length]u8 {
798 var result: [mac_length]u8 = undefined;
799 d.final(&result);
800 return result;
801 }
802
797803 /// Return an authentication tag for a message, a key and a nonce
798804 pub fn createWithNonce(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8, nonce: *const [nonce_length]u8) void {
799805 var ctx = Mac.initWithNonce(key, nonce);
lib/std/crypto/ascon.zig+6
......@@ -673,6 +673,12 @@ pub const AsconHash256 = struct {
673673 mem.writeInt(u64, out[i * 8 ..][0..8], h[i], .little);
674674 }
675675 }
676
677 pub fn finalResult(d: *AsconHash256) [digest_length]u8 {
678 var result: [digest_length]u8 = undefined;
679 d.final(&result);
680 return result;
681 }
676682};
677683
678684/// Ascon-XOF128 as specified in NIST SP 800-232 Section 5
lib/std/crypto/bcrypt.zig+6
......@@ -514,6 +514,12 @@ const pbkdf_prf = struct {
514514 out.* = hash(self.sha2pass, sha2salt);
515515 }
516516
517 pub fn finalResult(d: *Self) [mac_length]u8 {
518 var result: [mac_length]u8 = undefined;
519 d.final(&result);
520 return result;
521 }
522
517523 /// Matches OpenBSD function
518524 /// https://github.com/openbsd/src/blob/6df1256b7792691e66c2ed9d86a8c103069f9e34/lib/libutil/bcrypt_pbkdf.c#L98
519525 pub fn hash(sha2pass: [Sha512.digest_length]u8, sha2salt: [Sha512.digest_length]u8) [32]u8 {
lib/std/crypto/blake2.zig+12
......@@ -138,6 +138,12 @@ pub fn Blake2s(comptime out_bits: usize) type {
138138 out.* = @as(*[digest_length]u8, @ptrCast(&d.h)).*;
139139 }
140140
141 pub fn finalResult(d: *Self) [digest_length]u8 {
142 var result: [digest_length]u8 = undefined;
143 d.final(&result);
144 return result;
145 }
146
141147 fn round(d: *Self, b: *const [64]u8, last: bool) void {
142148 var m: [16]u32 = undefined;
143149 var v: [16]u32 = undefined;
......@@ -580,6 +586,12 @@ pub fn Blake2b(comptime out_bits: usize) type {
580586 out.* = @as(*[digest_length]u8, @ptrCast(&d.h)).*;
581587 }
582588
589 pub fn finalResult(d: *Self) [digest_length]u8 {
590 var result: [digest_length]u8 = undefined;
591 d.final(&result);
592 return result;
593 }
594
583595 fn round(d: *Self, b: *const [128]u8, last: bool) void {
584596 var m: [16]u64 = undefined;
585597 var v: [16]u64 = undefined;
lib/std/crypto/cbc_mac.zig+6
......@@ -68,6 +68,12 @@ pub fn CbcMac(comptime BlockCipher: type) type {
6868 // Partial blocks are implicitly zero-padded: buf[pos..] contains zeros from initialization.
6969 self.cipher_ctx.encrypt(out, &self.buf);
7070 }
71
72 pub fn finalResult(d: *Self) [mac_length]u8 {
73 var result: [mac_length]u8 = undefined;
74 d.final(&result);
75 return result;
76 }
7177 };
7278}
7379
lib/std/crypto/cmac.zig+6
......@@ -73,6 +73,12 @@ pub fn Cmac(comptime BlockCipher: type) type {
7373 self.cipher_ctx.encrypt(out, &mac);
7474 }
7575
76 pub fn finalResult(d: *Self) [mac_length]u8 {
77 var result: [mac_length]u8 = undefined;
78 d.final(&result);
79 return result;
80 }
81
7682 fn double(l: Block) Block {
7783 const Int = @Int(.unsigned, block_length * 8);
7884 const l_ = mem.readInt(Int, &l, .big);
lib/std/crypto/ghash_polyval.zig+6
......@@ -405,6 +405,12 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
405405 std.crypto.secureZero(Self, st[0..1]);
406406 }
407407
408 pub fn finalResult(d: *Self) [mac_length]u8 {
409 var result: [mac_length]u8 = undefined;
410 d.final(&result);
411 return result;
412 }
413
408414 /// Compute the GHASH of a message.
409415 pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void {
410416 var st = Self.init(key);
lib/std/crypto/hash_composition.zig+6
......@@ -54,6 +54,12 @@ pub fn Composition(comptime H1: type, comptime H2: type) type {
5454 d.H1.update(&H2_digest);
5555 d.H1.final(out);
5656 }
57
58 pub fn finalResult(d: *Self) [digest_length]u8 {
59 var result: [digest_length]u8 = undefined;
60 d.final(&result);
61 return result;
62 }
5763 };
5864}
5965
lib/std/crypto/hmac.zig+6
......@@ -71,6 +71,12 @@ pub fn Hmac(comptime Hash: type) type {
7171 ohash.update(&scratch);
7272 ohash.final(out);
7373 }
74
75 pub fn finalResult(d: *Self) [mac_length]u8 {
76 var result: [mac_length]u8 = undefined;
77 d.final(&result);
78 return result;
79 }
7480 };
7581}
7682
lib/std/crypto/md5.zig+6
......@@ -124,6 +124,12 @@ pub const Md5 = struct {
124124 }
125125 }
126126
127 pub fn finalResult(d: *Self) [digest_length]u8 {
128 var result: [digest_length]u8 = undefined;
129 d.final(&result);
130 return result;
131 }
132
127133 fn round(d: *Self, b: *const [64]u8) void {
128134 var s: [16]u32 = undefined;
129135
lib/std/crypto/poly1305.zig+6
......@@ -187,6 +187,12 @@ pub const Poly1305 = struct {
187187 std.crypto.secureZero(Poly1305, st[0..1]);
188188 }
189189
190 pub fn finalResult(d: *Poly1305) [mac_length]u8 {
191 var result: [mac_length]u8 = undefined;
192 d.final(&result);
193 return result;
194 }
195
190196 pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void {
191197 var st = Poly1305.init(key);
192198 st.update(msg);
lib/std/crypto/sha3.zig+6
......@@ -86,6 +86,12 @@ pub fn Keccak(comptime f: u11, comptime output_bits: u11, comptime default_delim
8686 self.st.pad();
8787 self.st.squeeze(out[0..]);
8888 }
89
90 pub fn finalResult(d: *Self) [digest_length]u8 {
91 var result: [digest_length]u8 = undefined;
92 d.final(&result);
93 return result;
94 }
8995 };
9096}
9197