std :: crypto::tls
Struct std::TlsSession
struct TlsSession {
unsigned char write_key[TLS_KEY_LEN];
unsigned char write_iv[TLS_IV_LEN];
unsigned char read_key[TLS_KEY_LEN];
unsigned char read_iv[TLS_IV_LEN];
unsigned long long write_seq;
unsigned long long read_seq;
int handshake_done;
struct TlsTranscript transcript;
}TLS session — holds traffic keys and sequence numbers.
Fields
Methods
A fresh session: zero keys, seq = 0, handshake_done = 0.
unsigned long encode_record(
unsigned char content_type,
[]const unsigned char payload,
[]unsigned char out,
)source · definitionEncode one record into out: plaintext before install_keys, then
AES-256-GCM sealed (outer type application_data, 16-byte tag).
Returns bytes written; 0 if it doesn't fit out_cap (no sequence
number is consumed then) or payload_len > TLS_MAX_RECORD_LEN.
unsigned long decode_record(
[]const unsigned char data,
&unsigned char content_type_out,
[]unsigned char out,
)source · definitionDecode one record from data (raw bytes from network). Sets
*content_type_out and writes the payload into out. Protected
records are authenticated first: a forged or corrupted record, like
insufficient data, returns 0 without advancing read_seq.
unsigned long build_alert(unsigned char level, unsigned char desc, []unsigned char out)source · definitionBuild a TLS Alert record into out. Returns bytes written.
XOR the IV with the sequence number per TLS 1.3 §5.3.
Writes TLS_IV_LEN bytes into nonce.
is_write != 0 selects write_iv; 0 selects read_iv.
void install_keys(
const unsigned char write_key[TLS_KEY_LEN],
const unsigned char write_iv[TLS_IV_LEN],
const unsigned char read_key[TLS_KEY_LEN],
const unsigned char read_iv[TLS_IV_LEN],
)source · definitionInstall traffic keys (called after key derivation in the handshake): resets both sequence numbers and switches to protected records (is_established() becomes 1).
Is the session post-handshake (application data mode)?