mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 22:33:08 +00:00
std/crypto: make Hkdf functions public
This commit is contained in:
parent
9ca9819488
commit
c387f1340f
@ -20,14 +20,14 @@ pub const HkdfSha512 = Hkdf(hmac.sha2.HmacSha512);
|
|||||||
pub fn Hkdf(comptime Hmac: type) type {
|
pub fn Hkdf(comptime Hmac: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
/// Return a master key from a salt and initial keying material.
|
/// Return a master key from a salt and initial keying material.
|
||||||
fn extract(salt: []const u8, ikm: []const u8) [Hmac.mac_length]u8 {
|
pub fn extract(salt: []const u8, ikm: []const u8) [Hmac.mac_length]u8 {
|
||||||
var prk: [Hmac.mac_length]u8 = undefined;
|
var prk: [Hmac.mac_length]u8 = undefined;
|
||||||
Hmac.create(&prk, ikm, salt);
|
Hmac.create(&prk, ikm, salt);
|
||||||
return prk;
|
return prk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Derive a subkey from a master key `prk` and a subkey description `ctx`.
|
/// Derive a subkey from a master key `prk` and a subkey description `ctx`.
|
||||||
fn expand(out: []u8, ctx: []const u8, prk: [Hmac.mac_length]u8) void {
|
pub fn expand(out: []u8, ctx: []const u8, prk: [Hmac.mac_length]u8) void {
|
||||||
assert(out.len < Hmac.mac_length * 255); // output size is too large for the Hkdf construction
|
assert(out.len < Hmac.mac_length * 255); // output size is too large for the Hkdf construction
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
var counter = [1]u8{1};
|
var counter = [1]u8{1};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user