DoxigAlpha

hkdfExpandLabel

Function parameters

Parameters

#
Hkdf:type
key:[Hkdf.prk_length]u8
label:[]const u8
context:[]const u8
len:usize

Type definitions in this namespace

Types

#
ApplicationCipher
Encryption parameters for application traffic.
Decoder
An abstraction to ensure that protocol-parsing code does not perform an

Functions in this namespace

Functions

#

= 5

Values

#
max_ciphertext_len
= max_ciphertext_inner_record_len + 256
max_ciphertext_record_len
= max_ciphertext_len + record_header_len
hello_retry_request_sequence
= [32]u8{ 0xCF, 0x21, 0xAD, 0x74, 0xE5, 0x9A, 0x61, 0x11, 0xBE, 0x1D, 0x8C, 0x02, 0x1E, 0x65, 0xB8, 0x91, 0xC2, 0xA2, 0x11, 0x16, 0x7A, 0xBB, 0x8C, 0x5E, 0x07, 0x9E, 0x09, 0xE2, 0xC8, 0xA8, 0x33, 0x9C, }
close_notify_alert
= [_]u8{ @intFromEnum(Alert.Level.warning), @intFromEnum(Alert.Description.close_notify), }

Source

Implementation

#
pub fn hkdfExpandLabel(
    comptime Hkdf: type,
    key: [Hkdf.prk_length]u8,
    label: []const u8,
    context: []const u8,
    comptime len: usize,
) [len]u8 {
    const max_label_len = 255;
    const max_context_len = 255;
    const tls13 = "tls13 ";
    var buf: [2 + 1 + tls13.len + max_label_len + 1 + max_context_len]u8 = undefined;
    mem.writeInt(u16, buf[0..2], len, .big);
    buf[2] = @as(u8, @intCast(tls13.len + label.len));
    buf[3..][0..tls13.len].* = tls13.*;
    var i: usize = 3 + tls13.len;
    @memcpy(buf[i..][0..label.len], label);
    i += label.len;
    buf[i] = @as(u8, @intCast(context.len));
    i += 1;
    @memcpy(buf[i..][0..context.len], context);
    i += context.len;

    var result: [len]u8 = undefined;
    Hkdf.expand(&result, buf[0..i], key);
    return result;
}