netio/tls/keysched.rs#
Source: lib/netio/tls/keysched.rs
keysched -- the TLS 1.3 key schedule (RFC 8446 7.1) with the hash of the cipher suite (SHA-256
or SHA-384): HKDF-Expand-Label, Derive-Secret, traffic keys and finished keys; the TLS 1.2 PRF
(RFC 5246 5) with SHA-256 or SHA-384; the running transcript hash of a handshake
Every function computes with the hash it is given (HMAC of any HashAlg); the TLS suites use
SHA-256 and SHA-384, and the Transcript keeps those two only
type Secret = Vec<u8>a secret of the schedule (as long as the hash: 32 or 48 bytes)fn expand_label(h: HashAlg, secret: &[u8], label: &str, context: &[u8], out: &mut [u8])HKDF-Expand-Label(secret, label, context, len);outat most 255 blocks of the hash (panics beyond)fn derive(h: HashAlg, secret: &[u8], label: &str, hash: &[u8]) -> SecretDerive-Secret(secret, label, transcript hash)fn extract(h: HashAlg, salt: &[u8], ikm: &[u8]) -> SecretHKDF-Extract (RFC 5869 2.2): HMAC(salt, ikm); an empty salt is the same as zeros of the hash's length (HMAC pads its key with zeros)fn empty_hash(h: HashAlg) -> Vec<u8>the hash of no messagesfn early_secret(h: HashAlg, psk: &[u8]) -> Secretthe early secret of a pre-shared key (RFC 8446 7.1): HKDF-Extract(0, PSK)fn binder_key(h: HashAlg, early: &[u8]) -> Secretthe binder key of a resumption PSK ("res binder", RFC 8446 4.2.11.2) from its early secretstruct Schedulethe secrets of one handshakehash: HashAlgearly: Secret-- the early secret (of the PSK, or of zeros)handshake: Secretmaster: Secret
impl Schedule
fn new(h: HashAlg, psk: Option<&[u8]>, shared: &[u8]) -> Schedulefrom the pre-shared key (None: zeros) and the (EC)DHE / hybrid shared secretfn binder_key(&self, external: bool) -> Secretthe binder key of a resumption PSK ("res binder") or an external one ("ext binder")fn traffic_keys_len(h: HashAlg, secret: &[u8], key_len: usize) -> (Vec<u8>, [u8; 12])the AEAD key (of key_len bytes) and IV of a traffic secretfn prf12(h: HashAlg, secret: &[u8], label: &str, seed: &[u8], out: &mut [u8])TLS 1.2: PRF(secret, label, seed) with P_SHA256, or P_SHA384 for the SHA-384 suitesfn finished(h: HashAlg, base: &[u8], transcript: &[u8]) -> Vec<u8>verify_data of a Finished message (and a PSK binder: the binder key asbase)fn update(h: HashAlg, secret: &[u8]) -> Secretthe next traffic secret (KeyUpdate)struct Transcriptthe transcript hash of a handshake: both hashes until the cipher suite picks one
impl Transcript
fn new() -> Transcriptfn update(&mut self, m: &[u8])fn hash(&self, h: HashAlg) -> Vec<u8>the hash so far withh: SHA-256 or SHA-384 while it is kept, else emptyfn keep(&mut self, h: HashAlg)keep onlyhfrom here on (the suite is chosen); a hash other than these two keeps none