ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
crypto_context_t Struct Reference

Endpoint cryptographic state for handshake, packet protection, authentication, and rekeying. More...

#include <include/ascii-chat/crypto/crypto.h>

Data Fields

uint8_t public_key [32]
uint8_t private_key [32]
uint8_t peer_public_key [32]
uint8_t shared_key [32]
uint8_t password_key [32]
uint8_t password_salt [32]
uint8_t nonce_size
uint8_t mac_size
uint8_t hmac_size
uint8_t encryption_key_size
uint8_t auth_challenge_size
uint16_t public_key_size
uint16_t private_key_size
uint16_t shared_key_size
uint16_t auth_public_key_size
uint16_t salt_size
uint16_t signature_size
bool initialized
bool has_password
bool key_exchange_complete
bool peer_key_received
bool handshake_complete
bool encrypt_data
uint8_t auth_nonce [32]
uint8_t auth_hmac [32]
uint64_t nonce_counter
uint8_t session_id [16]
uint64_t rekey_packet_count
time_t rekey_last_time
time_t rekey_last_request_time
bool rekey_in_progress
uint8_t rekey_failure_count
uint8_t temp_public_key [32]
uint8_t temp_private_key [32]
uint8_t temp_shared_key [32]
bool has_temp_key
uint64_t rekey_packet_threshold
time_t rekey_time_threshold
uint64_t bytes_encrypted
uint64_t bytes_decrypted
uint64_t rekey_count
struct crypto_session * session
 Endpoint cryptographic state for handshake, packet protection, authentication, and rekeying.
bool server_role
bool server_role_known

Detailed Description

Endpoint cryptographic state for handshake, packet protection, authentication, and rekeying.

The context owns ephemeral X25519 material, the derived shared and optional password keys, negotiated wire sizes, authentication nonces, packet counters, and temporary keys during a rotation. Transports borrow it when sealing or opening packets. It is initialized through the crypto API and destroyed with crypto_destroy() so secret fields are wiped rather than copied or freed by callers.

Note
Nonce generation: Nonces are constructed as session_id || counter where session_id is 16 bytes and counter fills the remaining bytes. This construction aims to avoid nonce reuse, not to detect replays.
Session ID: Randomly generated for each connection and again on rekey. It contributes to nonce uniqueness; the decryptor does not check it.
Nonce counter: Starts at 1 (0 is reserved for testing) and increments for each encryption operation. Prevents nonce reuse within a session.
Byte order: Client must convert network byte order to host byte order for crypto parameters. Server uses host byte order directly.
Key exchange formats:
  • Simple format: Only ephemeral public key (when server has no identity key)
  • Authenticated format: Ephemeral key + identity key + signature (when server has identity key)

Endpoint cryptographic state for handshake, packet protection, authentication, and rekeying.

The context owns ephemeral X25519 material, the derived shared and optional password keys, negotiated wire sizes, authentication nonces, packet counters, and temporary keys during a rotation. Transports borrow it when sealing or opening packets. It must be initialized through the crypto API and destroyed through crypto_destroy() so secret fields are wiped rather than copied or freed by callers.

Definition at line 126 of file include/ascii-chat/crypto/crypto.h.

Field Documentation

◆ auth_challenge_size

◆ auth_hmac

uint8_t crypto_context_t::auth_hmac[32]

Client's HMAC response (or expected on server)

Definition at line 162 of file include/ascii-chat/crypto/crypto.h.

◆ auth_nonce

uint8_t crypto_context_t::auth_nonce[32]

◆ auth_public_key_size

uint16_t crypto_context_t::auth_public_key_size

Authentication public key size (32 for Ed25519, 1952 for Dilithium3)

Definition at line 148 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_handshake_client_key_exchange(), crypto_handshake_server_start(), crypto_handshake_set_parameters(), and crypto_handshake_validate_packet_size().

◆ bytes_decrypted

uint64_t crypto_context_t::bytes_decrypted

Total bytes decrypted

Definition at line 187 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_decrypt(), crypto_destroy(), crypto_get_status(), and crypto_init().

◆ bytes_encrypted

uint64_t crypto_context_t::bytes_encrypted

Performance tracking Total bytes encrypted

Definition at line 186 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_destroy(), crypto_encrypt(), crypto_get_status(), and crypto_init().

◆ encrypt_data

◆ encryption_key_size

uint8_t crypto_context_t::encryption_key_size

Encryption key size (e.g., 32 for XSalsa20, 32 for AES-256)

Definition at line 141 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_decrypt(), crypto_derive_password_key(), crypto_encrypt(), crypto_handshake_set_parameters(), crypto_init(), and crypto_verify_password().

◆ handshake_complete

◆ has_password

◆ has_temp_key

◆ hmac_size

uint8_t crypto_context_t::hmac_size

◆ initialized

◆ key_exchange_complete

◆ mac_size

◆ nonce_counter

uint64_t crypto_context_t::nonce_counter

Security parameters Nonce counter (starts at 1, increments per encryption)

Definition at line 165 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_encrypt(), crypto_get_status(), crypto_init(), and crypto_rekey_commit().

◆ nonce_size

uint8_t crypto_context_t::nonce_size

Dynamic crypto parameters (negotiated during handshake) Nonce size (e.g., 24 for XSalsa20, 12 for ChaCha20)

Definition at line 138 of file include/ascii-chat/crypto/crypto.h.

Referenced by acip_packet_plan(), acip_packet_seal(), crypto_create_encrypted_packet(), crypto_decrypt(), crypto_encrypt(), crypto_handshake_set_parameters(), crypto_init(), and crypto_record_init().

◆ password_key

uint8_t crypto_context_t::password_key[32]

Password-derived key (optional additional layer) Argon2id-derived key from password

Definition at line 134 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_compute_auth_response(), crypto_decrypt(), crypto_derive_password_key(), crypto_destroy(), crypto_encrypt(), crypto_verify_auth_response(), and crypto_verify_password().

◆ password_salt

uint8_t crypto_context_t::password_salt[32]

Salt used for password derivation

Definition at line 135 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_derive_password_key(), and crypto_destroy().

◆ peer_key_received

bool crypto_context_t::peer_key_received

Whether peer's public key has been received

Definition at line 156 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_init(), and crypto_set_peer_public_key().

◆ peer_public_key

uint8_t crypto_context_t::peer_public_key[32]

Peer's ephemeral public key

Definition at line 130 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_session_lock(), and crypto_set_peer_public_key().

◆ private_key

uint8_t crypto_context_t::private_key[32]

Our ephemeral private key

Definition at line 129 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_destroy(), crypto_generate_keypair(), and crypto_set_peer_public_key().

◆ private_key_size

uint16_t crypto_context_t::private_key_size

Key exchange private key size (32 for X25519, 1568 for Kyber1024)

Definition at line 146 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_handshake_set_parameters(), and crypto_init().

◆ public_key

uint8_t crypto_context_t::public_key[32]

◆ public_key_size

◆ rekey_count

uint64_t crypto_context_t::rekey_count

Number of successful rekeys performed

Definition at line 188 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_get_rekey_status(), crypto_init(), crypto_record_init(), and crypto_rekey_commit().

◆ rekey_failure_count

uint8_t crypto_context_t::rekey_failure_count

Consecutive rekey failures (for exponential backoff)

Definition at line 173 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_get_rekey_status(), crypto_init(), crypto_rekey_abort(), crypto_rekey_commit(), and crypto_rekey_init().

◆ rekey_in_progress

◆ rekey_last_request_time

time_t crypto_context_t::rekey_last_request_time

Timestamp of last rekey request (for DDoS protection)

Definition at line 171 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_init().

◆ rekey_last_time

time_t crypto_context_t::rekey_last_time

Timestamp of last successful rekey (or initial handshake)

Definition at line 170 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_get_rekey_status(), crypto_init(), crypto_rekey_commit(), crypto_rekey_init(), and crypto_should_rekey().

◆ rekey_packet_count

uint64_t crypto_context_t::rekey_packet_count

Session rekeying state Packets encrypted since last rekey/handshake

Definition at line 169 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_encrypt(), crypto_get_rekey_status(), crypto_init(), crypto_rekey_commit(), crypto_rekey_init(), crypto_rekey_session_tick(), and crypto_should_rekey().

◆ rekey_packet_threshold

uint64_t crypto_context_t::rekey_packet_threshold

Configurable rekeying thresholds Rekey after N packets (default: 1,000,000)

Definition at line 182 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_get_rekey_status(), crypto_init(), crypto_rekey_session_tick(), and crypto_should_rekey().

◆ rekey_time_threshold

time_t crypto_context_t::rekey_time_threshold

Rekey after N seconds (default: 3600 = 1 hour)

Definition at line 183 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_get_rekey_status(), crypto_init(), crypto_rekey_session_tick(), and crypto_should_rekey().

◆ salt_size

uint16_t crypto_context_t::salt_size

◆ server_role

◆ server_role_known

◆ session

struct crypto_session* crypto_context_t::session

Endpoint cryptographic state for handshake, packet protection, authentication, and rekeying.

Owned shared record/rekey state; contexts are not copyable owners.

Definition at line 193 of file include/ascii-chat/crypto/crypto.h.

Referenced by acip_packet_encrypt(), crypto_record_commit_epoch(), crypto_record_open_sequence(), crypto_session_create(), crypto_session_destroy(), and crypto_session_lock().

◆ session_id

uint8_t crypto_context_t::session_id[16]

Random 16-byte nonce prefix, regenerated on rekey

Definition at line 166 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_init(), and crypto_rekey_commit().

◆ shared_key

◆ shared_key_size

uint16_t crypto_context_t::shared_key_size

Shared secret size (32 for X25519, 32 for Kyber1024)

Definition at line 147 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_handshake_set_parameters(), and crypto_init().

◆ signature_size

◆ temp_private_key

uint8_t crypto_context_t::temp_private_key[32]

◆ temp_public_key

uint8_t crypto_context_t::temp_public_key[32]

Temporary keys during rekeying transition New ephemeral public key (not yet active)

Definition at line 176 of file include/ascii-chat/crypto/crypto.h.

Referenced by crypto_rekey_abort(), crypto_rekey_commit(), crypto_rekey_init(), crypto_rekey_process_request(), and crypto_rekey_session_tick().

◆ temp_shared_key

uint8_t crypto_context_t::temp_shared_key[32]

The documentation for this struct was generated from the following file: