11#if (PC_ENABLE_HTTP3 || PC_ENABLE_DTLS)
19const Tls13Kdf TLS13_KDF = {
"tls13 "};
20const Tls13Kdf DTLS13_KDF = {
"dtls13"};
25void empty_hash(uint8_t out[TLS13_SECRET_LEN])
31void pc_tls13_kdf_expand_label(
const Tls13Kdf *kdf,
const uint8_t secret[TLS13_SECRET_LEN],
const char *label,
32 uint8_t *out,
size_t out_len)
34 pc_hkdf_expand_label(secret, label, out, out_len, kdf->label_prefix);
37void pc_tls13_derive_secret(
const Tls13Kdf *kdf,
const uint8_t secret[TLS13_SECRET_LEN],
const char *label,
38 const uint8_t transcript_hash[TLS13_SECRET_LEN], uint8_t out[TLS13_SECRET_LEN])
41 pc_hkdf_expand_label_ctx(secret, label, transcript_hash, TLS13_SECRET_LEN, out, TLS13_SECRET_LEN,
45void pc_tls13_ks_early(
const Tls13Kdf *kdf, Tls13KeySchedule *ks)
50 uint8_t zeros[TLS13_SECRET_LEN];
51 memset(zeros, 0,
sizeof(zeros));
52 pc_hkdf_extract(
nullptr, 0, zeros,
sizeof(zeros), ks->early_secret);
55void pc_tls13_ks_handshake(Tls13KeySchedule *ks,
const uint8_t *ecdhe,
const uint8_t ch_sh_hash[TLS13_SECRET_LEN],
59 uint8_t eh[TLS13_SECRET_LEN];
61 uint8_t derived[TLS13_SECRET_LEN];
62 pc_tls13_derive_secret(ks->kdf, ks->early_secret,
"derived", eh, derived);
63 pc_hkdf_extract(derived,
sizeof(derived), ecdhe, ecdhe_len, ks->handshake_secret);
65 pc_tls13_derive_secret(ks->kdf, ks->handshake_secret,
"c hs traffic", ch_sh_hash, ks->client_hs_traffic);
66 pc_tls13_derive_secret(ks->kdf, ks->handshake_secret,
"s hs traffic", ch_sh_hash, ks->server_hs_traffic);
69void pc_tls13_ks_master(Tls13KeySchedule *ks,
const uint8_t ch_sfin_hash[TLS13_SECRET_LEN])
72 uint8_t eh[TLS13_SECRET_LEN];
74 uint8_t derived[TLS13_SECRET_LEN];
75 pc_tls13_derive_secret(ks->kdf, ks->handshake_secret,
"derived", eh, derived);
76 uint8_t zeros[TLS13_SECRET_LEN];
77 memset(zeros, 0,
sizeof(zeros));
78 pc_hkdf_extract(derived,
sizeof(derived), zeros,
sizeof(zeros), ks->master_secret);
80 pc_tls13_derive_secret(ks->kdf, ks->master_secret,
"c ap traffic", ch_sfin_hash, ks->client_ap_traffic);
81 pc_tls13_derive_secret(ks->kdf, ks->master_secret,
"s ap traffic", ch_sfin_hash, ks->server_ap_traffic);
84void pc_tls13_finished_mac(
const Tls13Kdf *kdf,
const uint8_t base_secret[TLS13_SECRET_LEN],
85 const uint8_t transcript_hash[TLS13_SECRET_LEN], uint8_t out[TLS13_SECRET_LEN])
88 uint8_t finished_key[TLS13_SECRET_LEN];
89 pc_hkdf_expand_label(base_secret,
"finished", finished_key,
sizeof(finished_key), kdf->label_prefix);
90 pc_hmac_sha256(finished_key,
sizeof(finished_key), transcript_hash, TLS13_SECRET_LEN, out);
HKDF-SHA256 (RFC 5869) and TLS 1.3 HKDF-Expand-Label (RFC 8446 sec 7.1).
void pc_hmac_sha256(const uint8_t *key, size_t key_len, const uint8_t *data, size_t len, uint8_t mac[PC_HMAC_SHA256_LEN])
Compute HMAC-SHA2-256 over a single contiguous buffer.
HMAC-SHA2-256 (RFC 2104 + FIPS 198-1) - streaming context and one-shot API.
void pc_sha256(const uint8_t *data, size_t len, uint8_t digest[PC_SHA256_DIGEST_LEN])
One-shot SHA-256: hash len bytes of data into digest (32 bytes).
SHA-256 (FIPS 180-4) - streaming context and one-shot API.
TLS 1.3 key schedule (RFC 8446 sec 7.1) for the QUIC handshake.