Implemented Hkdf and Hmac and added a digest length property to all of them to get closer to the zig stdlib implementation

This commit is contained in:
Gu://em_ 2026-07-08 01:00:39 +02:00
parent 1b98394fe4
commit 150c5b2e38
3 changed files with 37 additions and 13 deletions

View file

@ -1,18 +1,17 @@
pub const Implementation = struct {
hash: *const fn (buffer: []const u8, out: []u8) void,
hash_length: comptime_int,
hash: *const fn (buffer: []const u8, out: *[Implementation.hash_length]u8) void,
};
pub const defaultImplementation = struct {
const Sha256 = @import("std").crypto.hash.sha2.Sha256;
const HASH_LEN = 32; // In bytes
pub const hash_len = Sha256.digest_length;
pub fn hash(buffer: []const u8, out: []u8) !void {
if (out.len < HASH_LEN) {
return error.BufferTooShort;
}
pub fn hash(buffer: []const u8, out: *[hash_len]u8) !void {
Sha256.hash(buffer, out, .{});
}
};