class

Beryl::TLS::KeySchedule

Inherits Reference < Object

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.

Source

Class methods

derive_secret(hash_algorithm : HashAlgorithm, secret : Bytes, label : String, transcript_digest : Bytes) : Bytes

Derive-Secret (§7.1), given the transcript hash already taken.

Source
expand_label(hash_algorithm : HashAlgorithm, secret : Bytes, label : String, context : Bytes, bytesize : Int32) : Bytes

HKDF-Expand-Label (§7.1): label gets the tls13 prefix.

Source
export_keying_material(hash_algorithm : HashAlgorithm, exporter_master_secret : Bytes, label : String, context : Bytes, bytesize : Int32) : Bytes

Returns the exported keying material (§7.5).

Source
finished_key(hash_algorithm : HashAlgorithm, base_key : Bytes) : Bytes

Returns the Finished key of a traffic secret (§4.4.4).

Source
finished_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.

Source
finished_verify_data(hash_algorithm : HashAlgorithm, base_key : Bytes, transcript_digest : Bytes) : Bytes

Returns the Finished verify_data over transcript_digest (§4.4.4).

Source
next_application_traffic_secret(hash_algorithm : HashAlgorithm, traffic_secret : Bytes) : Bytes

Returns the next application traffic secret (traffic upd, §7.2).

Source
resumption_pre_shared_key(hash_algorithm : HashAlgorithm, resumption_master_secret : Bytes, ticket_nonce : Bytes) : Bytes

Returns the PSK a NewSessionTicket stands for (§4.6.1).

Source
traffic_key_and_iv(hash_algorithm : HashAlgorithm, traffic_secret : Bytes, key_bytesize : Int32) : Tuple(Bytes, Bytes)

Returns the AEAD key and IV of a traffic secret (§7.3).

Source

Instance methods

client_application_traffic_secret(transcript_digest : Bytes) : Bytes

c ap traffic, over the transcript through the server Finished.

Source
client_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.

Source
client_handshake_traffic_secret(transcript_digest : Bytes) : Bytes

c hs traffic, over the transcript through the ServerHello.

Source
early_secret

The early secret, for specs and for the binder of an external PSK.

Source
enter_handshake_stage(shared_secret : Bytes) : Nil

Mixes in the (EC)DHE shared secret and moves to the handshake stage.

Source
enter_master_stage

Moves to the master stage.

Source
exporter_master_secret(transcript_digest : Bytes) : Bytes

exp master, over the transcript through the server Finished.

Source
hash_algorithm
Source
resumption_binder_key

The key the PSK binders are computed under (res binder, §7.1).

Source
resumption_master_secret(transcript_digest : Bytes) : Bytes

res master, over the transcript through the client Finished.

Source
server_application_traffic_secret(transcript_digest : Bytes) : Bytes

s ap traffic, over the transcript through the server Finished.

Source
server_handshake_traffic_secret(transcript_digest : Bytes) : Bytes

s hs traffic, over the transcript through the ServerHello.

Source
wipe

Wipes whatever stage secret is still held.

Source