| author | |
| committer | |
| log | a0501add57ff187193ddfa3c79b3d26cc96fa1d8 |
| tree | df657979485b15475935d5268edacb783bcf63f9 |
| parent | 7f8f2b16a0a523a1473b172e9f8a585087e879fc |
| parent | 345b71793664d8d69b04be1d81c22409ddcf54bd |
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 { | ... | @@ -794,6 +794,12 @@ fn AegisMac(comptime T: type) type { |
| 794 | out.* = self.state.finalizeMac(T.tag_length * 8, self.msg_len); | 794 | out.* = self.state.finalizeMac(T.tag_length * 8, self.msg_len); |
| 795 | } | 795 | } |
| 796 | 796 | ||
| 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 | |||
| 797 | /// Return an authentication tag for a message, a key and a nonce | 803 | /// Return an authentication tag for a message, a key and a nonce |
| 798 | pub fn createWithNonce(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8, nonce: *const [nonce_length]u8) void { | 804 | pub fn createWithNonce(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8, nonce: *const [nonce_length]u8) void { |
| 799 | var ctx = Mac.initWithNonce(key, nonce); | 805 | var ctx = Mac.initWithNonce(key, nonce); |
lib/std/crypto/ascon.zig+6| ... | @@ -673,6 +673,12 @@ pub const AsconHash256 = struct { | ... | @@ -673,6 +673,12 @@ pub const AsconHash256 = struct { |
| 673 | mem.writeInt(u64, out[i * 8 ..][0..8], h[i], .little); | 673 | mem.writeInt(u64, out[i * 8 ..][0..8], h[i], .little); |
| 674 | } | 674 | } |
| 675 | } | 675 | } |
| 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 | } | ||
| 676 | }; | 682 | }; |
| 677 | 683 | ||
| 678 | /// Ascon-XOF128 as specified in NIST SP 800-232 Section 5 | 684 | /// 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 { | ... | @@ -514,6 +514,12 @@ const pbkdf_prf = struct { |
| 514 | out.* = hash(self.sha2pass, sha2salt); | 514 | out.* = hash(self.sha2pass, sha2salt); |
| 515 | } | 515 | } |
| 516 | 516 | ||
| 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 | |||
| 517 | /// Matches OpenBSD function | 523 | /// Matches OpenBSD function |
| 518 | /// https://github.com/openbsd/src/blob/6df1256b7792691e66c2ed9d86a8c103069f9e34/lib/libutil/bcrypt_pbkdf.c#L98 | 524 | /// https://github.com/openbsd/src/blob/6df1256b7792691e66c2ed9d86a8c103069f9e34/lib/libutil/bcrypt_pbkdf.c#L98 |
| 519 | pub fn hash(sha2pass: [Sha512.digest_length]u8, sha2salt: [Sha512.digest_length]u8) [32]u8 { | 525 | 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 { | ... | @@ -138,6 +138,12 @@ pub fn Blake2s(comptime out_bits: usize) type { |
| 138 | out.* = @as(*[digest_length]u8, @ptrCast(&d.h)).*; | 138 | out.* = @as(*[digest_length]u8, @ptrCast(&d.h)).*; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 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 | |||
| 141 | fn round(d: *Self, b: *const [64]u8, last: bool) void { | 147 | fn round(d: *Self, b: *const [64]u8, last: bool) void { |
| 142 | var m: [16]u32 = undefined; | 148 | var m: [16]u32 = undefined; |
| 143 | var v: [16]u32 = undefined; | 149 | var v: [16]u32 = undefined; |
| ... | @@ -580,6 +586,12 @@ pub fn Blake2b(comptime out_bits: usize) type { | ... | @@ -580,6 +586,12 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 580 | out.* = @as(*[digest_length]u8, @ptrCast(&d.h)).*; | 586 | out.* = @as(*[digest_length]u8, @ptrCast(&d.h)).*; |
| 581 | } | 587 | } |
| 582 | 588 | ||
| 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 | |||
| 583 | fn round(d: *Self, b: *const [128]u8, last: bool) void { | 595 | fn round(d: *Self, b: *const [128]u8, last: bool) void { |
| 584 | var m: [16]u64 = undefined; | 596 | var m: [16]u64 = undefined; |
| 585 | var v: [16]u64 = undefined; | 597 | var v: [16]u64 = undefined; |
lib/std/crypto/cbc_mac.zig+6| ... | @@ -68,6 +68,12 @@ pub fn CbcMac(comptime BlockCipher: type) type { | ... | @@ -68,6 +68,12 @@ pub fn CbcMac(comptime BlockCipher: type) type { |
| 68 | // Partial blocks are implicitly zero-padded: buf[pos..] contains zeros from initialization. | 68 | // Partial blocks are implicitly zero-padded: buf[pos..] contains zeros from initialization. |
| 69 | self.cipher_ctx.encrypt(out, &self.buf); | 69 | self.cipher_ctx.encrypt(out, &self.buf); |
| 70 | } | 70 | } |
| 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 | } | ||
| 71 | }; | 77 | }; |
| 72 | } | 78 | } |
| 73 | 79 |
lib/std/crypto/cmac.zig+6| ... | @@ -73,6 +73,12 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -73,6 +73,12 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 73 | self.cipher_ctx.encrypt(out, &mac); | 73 | self.cipher_ctx.encrypt(out, &mac); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 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 | |||
| 76 | fn double(l: Block) Block { | 82 | fn double(l: Block) Block { |
| 77 | const Int = @Int(.unsigned, block_length * 8); | 83 | const Int = @Int(.unsigned, block_length * 8); |
| 78 | const l_ = mem.readInt(Int, &l, .big); | 84 | 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 { | ... | @@ -405,6 +405,12 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 405 | std.crypto.secureZero(Self, st[0..1]); | 405 | std.crypto.secureZero(Self, st[0..1]); |
| 406 | } | 406 | } |
| 407 | 407 | ||
| 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 | |||
| 408 | /// Compute the GHASH of a message. | 414 | /// Compute the GHASH of a message. |
| 409 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { | 415 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { |
| 410 | var st = Self.init(key); | 416 | 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 { | ... | @@ -54,6 +54,12 @@ pub fn Composition(comptime H1: type, comptime H2: type) type { |
| 54 | d.H1.update(&H2_digest); | 54 | d.H1.update(&H2_digest); |
| 55 | d.H1.final(out); | 55 | d.H1.final(out); |
| 56 | } | 56 | } |
| 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 | } | ||
| 57 | }; | 63 | }; |
| 58 | } | 64 | } |
| 59 | 65 |
lib/std/crypto/hmac.zig+6| ... | @@ -71,6 +71,12 @@ pub fn Hmac(comptime Hash: type) type { | ... | @@ -71,6 +71,12 @@ pub fn Hmac(comptime Hash: type) type { |
| 71 | ohash.update(&scratch); | 71 | ohash.update(&scratch); |
| 72 | ohash.final(out); | 72 | ohash.final(out); |
| 73 | } | 73 | } |
| 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 | } | ||
| 74 | }; | 80 | }; |
| 75 | } | 81 | } |
| 76 | 82 |
lib/std/crypto/md5.zig+6| ... | @@ -124,6 +124,12 @@ pub const Md5 = struct { | ... | @@ -124,6 +124,12 @@ pub const Md5 = struct { |
| 124 | } | 124 | } |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 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 | |||
| 127 | fn round(d: *Self, b: *const [64]u8) void { | 133 | fn round(d: *Self, b: *const [64]u8) void { |
| 128 | var s: [16]u32 = undefined; | 134 | var s: [16]u32 = undefined; |
| 129 | 135 |
lib/std/crypto/poly1305.zig+6| ... | @@ -187,6 +187,12 @@ pub const Poly1305 = struct { | ... | @@ -187,6 +187,12 @@ pub const Poly1305 = struct { |
| 187 | std.crypto.secureZero(Poly1305, st[0..1]); | 187 | std.crypto.secureZero(Poly1305, st[0..1]); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 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 | |||
| 190 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { | 196 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { |
| 191 | var st = Poly1305.init(key); | 197 | var st = Poly1305.init(key); |
| 192 | st.update(msg); | 198 | 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 | ... | @@ -86,6 +86,12 @@ pub fn Keccak(comptime f: u11, comptime output_bits: u11, comptime default_delim |
| 86 | self.st.pad(); | 86 | self.st.pad(); |
| 87 | self.st.squeeze(out[0..]); | 87 | self.st.squeeze(out[0..]); |
| 88 | } | 88 | } |
| 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 | } | ||
| 89 | }; | 95 | }; |
| 90 | } | 96 | } |
| 91 | 97 |