std1.0.0-beta-7 SafeC docs

std :: crypto::tls

Struct std::TlsSession

#include <std/crypto/tls.h> source

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

§unsigned char write_key[TLS_KEY_LEN]source
§unsigned char write_iv[TLS_IV_LEN]source
§unsigned char read_key[TLS_KEY_LEN]source
§unsigned char read_iv[TLS_IV_LEN]source
§unsigned long long write_seqsource
§unsigned long long read_seqsource
§int handshake_donesource
§struct TlsTranscript transcriptsource

Methods

§static struct TlsSession new()source · definition

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 · definition

Encode 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 · definition

Decode 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 · definition

Build a TLS Alert record into out. Returns bytes written.

§void compute_nonce(unsigned char nonce[TLS_IV_LEN], int is_write) constsource · definition

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 · definition

Install traffic keys (called after key derivation in the handshake): resets both sequence numbers and switches to protected records (is_established() becomes 1).

§int is_established() constsource · definition

Is the session post-handshake (application data mode)?