class

Beryl::TLS::RecordProtection

Inherits Reference < Object

One direction of record protection (RFC 9846 §5.2 and §5.3): the AEAD keyed from a traffic secret, its IV, and the sequence number.

protection = Beryl::TLS::RecordProtection.new(CipherSuite::TLS_AES_128_GCM_SHA256, traffic_secret)
record = protection.seal(ContentType::ApplicationData, "hello".to_slice)
protection_of_peer.open(record[0, 5], record[5..]) # => {ContentType::ApplicationData, Bytes}

Constants

HEADER_BYTESIZE = 5

The record header: type, legacy version, length.

LARGEST_CIPHERTEXT_BYTESIZE = 16640

The largest TLSCiphertext fragment (§5.2).

LARGEST_INNER_PLAINTEXT_BYTESIZE = 16385

The largest TLSInnerPlaintext: 2^14 bytes of content and its type.

Constructors

new(cipher_suite : CipherSuite, traffic_secret : Bytes)
Source

Instance methods

cipher_suite
Source
open(header : Bytes, ciphertext : Bytes) : Tuple(ContentType, Bytes) | Nil

Opens the record with header and ciphertext. Returns the inner content type and content, or nil when the record fails authentication; raises for a record with no content type.

Source
seal(content_type : ContentType, content : Bytes, padding_bytesize : Int32 = 0) : Bytes

Returns a whole protected record (header and ciphertext) carrying content of content_type, with padding_bytesize zero bytes of padding (§5.4).

Source
sequence_number
Source
tag_bytesize

The tag size of every TLS 1.3 AEAD.

Source
wipe

Wipes the key material this direction holds: the AEAD's key and everything derived from it, the IV and the last nonce. A wiped direction raises Crypto::KeyWiped on seal and open.

Source