11#if (DETWS_ENABLE_HTTP3 || DETWS_ENABLE_DTLS)
19const Tls13Kdf TLS13_KDF = {
"tls13 "};
20const Tls13Kdf DTLS13_KDF = {
"dtls13"};
25void empty_hash(uint8_t out[TLS13_SECRET_LEN])
31void 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 quic_hkdf_expand_label(secret, label, out, out_len, kdf->label_prefix);
37void 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 quic_hkdf_expand_label_ctx(secret, label, transcript_hash, TLS13_SECRET_LEN, out, TLS13_SECRET_LEN,
45void tls13_ks_early(
const Tls13Kdf *kdf, Tls13KeySchedule *ks)
50 uint8_t zeros[TLS13_SECRET_LEN];
51 memset(zeros, 0,
sizeof(zeros));
52 quic_hkdf_extract(
nullptr, 0, zeros,
sizeof(zeros), ks->early_secret);
55void 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 tls13_derive_secret(ks->kdf, ks->early_secret,
"derived", eh, derived);
63 quic_hkdf_extract(derived,
sizeof(derived), ecdhe, ecdhe_len, ks->handshake_secret);
65 tls13_derive_secret(ks->kdf, ks->handshake_secret,
"c hs traffic", ch_sh_hash, ks->client_hs_traffic);
66 tls13_derive_secret(ks->kdf, ks->handshake_secret,
"s hs traffic", ch_sh_hash, ks->server_hs_traffic);
69void 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 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 quic_hkdf_extract(derived,
sizeof(derived), zeros,
sizeof(zeros), ks->master_secret);
80 tls13_derive_secret(ks->kdf, ks->master_secret,
"c ap traffic", ch_sfin_hash, ks->client_ap_traffic);
81 tls13_derive_secret(ks->kdf, ks->master_secret,
"s ap traffic", ch_sfin_hash, ks->server_ap_traffic);
84void 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 quic_hkdf_expand_label(base_secret,
"finished", finished_key,
sizeof(finished_key), kdf->label_prefix);
90 ssh_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 ssh_hmac_sha256(const uint8_t *key, size_t key_len, const uint8_t *data, size_t len, uint8_t mac[SSH_HMAC_SHA256_LEN])
Compute HMAC-SHA2-256 over a single contiguous buffer.
HMAC-SHA2-256 (RFC 2104 + FIPS 198-1).
void ssh_sha256(const uint8_t *data, size_t len, uint8_t digest[SSH_SHA256_DIGEST_LEN])
One-shot SHA-256: hash len bytes and write the digest.
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.