The TLS 1.3 key schedule (RFC 9846 §7.1): the early, handshake and
master secrets, and every secret, key and Finished value derived from
them.
schedule = Beryl::TLS::KeySchedule.new(HashAlgorithm::SHA256)
schedule.enter_handshake_stage(ecdhe_shared_secret)
client_secret = schedule.client_handshake_traffic_secret(transcript_digest)
key, iv = Beryl::TLS::KeySchedule.traffic_key_and_iv(HashAlgorithm::SHA256, client_secret, 16)
Each stage's secret is wiped when the next one is entered; the secrets
handed out are the caller's to wipe.
Constants
IV_BYTESIZE = 12
The size of an AEAD nonce for every TLS 1.3 suite (§5.3).
Constructors
new(hash_algorithm :
HashAlgorithm, pre_shared_key :
Bytes |
Nil = nil)
Starts the schedule with the early secret, from pre_shared_key when
resuming and from a string of zeros otherwise.
SourceClass methods
derive_secret(hash_algorithm :
HashAlgorithm, secret :
Bytes, label :
String, transcript_digest :
Bytes) :
Bytes Derive-Secret (§7.1), given the transcript hash already taken.
SourceHKDF-Expand-Label (§7.1): label gets the tls13 prefix.
Sourceexport_keying_material(hash_algorithm :
HashAlgorithm, exporter_master_secret :
Bytes, label :
String, context :
Bytes, bytesize :
Int32) :
Bytes Returns the exported keying material (§7.5).
Sourcefinished_key(hash_algorithm :
HashAlgorithm, base_key :
Bytes) :
Bytes Returns the Finished key of a traffic secret (§4.4.4).
Sourcefinished_matches?(hash_algorithm :
HashAlgorithm, base_key :
Bytes, transcript_digest :
Bytes, verify_data :
Bytes) :
Bool Returns whether verify_data is the Finished value over
transcript_digest, compared in constant time.
Sourcefinished_verify_data(hash_algorithm :
HashAlgorithm, base_key :
Bytes, transcript_digest :
Bytes) :
Bytes Returns the Finished verify_data over transcript_digest (§4.4.4).
Sourcenext_application_traffic_secret(hash_algorithm :
HashAlgorithm, traffic_secret :
Bytes) :
Bytes Returns the next application traffic secret (traffic upd, §7.2).
Sourceresumption_pre_shared_key(hash_algorithm :
HashAlgorithm, resumption_master_secret :
Bytes, ticket_nonce :
Bytes) :
Bytes Returns the PSK a NewSessionTicket stands for (§4.6.1).
SourceReturns the AEAD key and IV of a traffic secret (§7.3).
SourceInstance methods
client_application_traffic_secret(transcript_digest :
Bytes) :
Bytes c ap traffic, over the transcript through the server Finished.
Sourceclient_early_traffic_secret(client_hello_digest :
Bytes) :
Bytes The client's early traffic secret (c e traffic). Beryl never sends
or accepts 0-RTT data; this exists so RFC 8448 §4 can be checked.
Sourceclient_handshake_traffic_secret(transcript_digest :
Bytes) :
Bytes c hs traffic, over the transcript through the ServerHello.
Sourceearly_secret
The early secret, for specs and for the binder of an external PSK.
Sourceenter_handshake_stage(shared_secret :
Bytes) :
Nil Mixes in the (EC)DHE shared secret and moves to the handshake stage.
Sourceenter_master_stage
Moves to the master stage.
Sourceexporter_master_secret(transcript_digest :
Bytes) :
Bytes exp master, over the transcript through the server Finished.
Sourceresumption_binder_key
The key the PSK binders are computed under (res binder, §7.1).
Sourceresumption_master_secret(transcript_digest :
Bytes) :
Bytes res master, over the transcript through the client Finished.
Sourceserver_application_traffic_secret(transcript_digest :
Bytes) :
Bytes s ap traffic, over the transcript through the server Finished.
Sourceserver_handshake_traffic_secret(transcript_digest :
Bytes) :
Bytes s hs traffic, over the transcript through the ServerHello.
Sourcewipe
Wipes whatever stage secret is still held.
Source