netio/tls/record.rs#
Source: lib/netio/tls/record.rs
record -- the TLS record layer: TLS 1.3 (RFC 8446) and, for public servers, TLS 1.2 (RFC
5246 with AEAD suites only: RFC 5288 / 5289 AES-GCM, RFC 7905 ChaCha20-Poly1305)
plaintext record type | 0x0303 | length | fragment (handshake before keys,
alerts, CCS)
TLS 1.3 protected 23 | 0x0303 | length | AEAD(content ‖ type ‖ zero padding)
nonce = IV xor sequence number, additional data = the record header
TLS 1.2 protected type | 0x0303 | length | [explicit nonce (GCM)] AEAD(content)
additional data = sequence ‖ type ‖ 0x0303 ‖ content length;
GCM nonce = 4-byte salt ‖ explicit 8 bytes (we send the sequence),
ChaCha20 nonce = IV xor sequence number
CHANGE_CIPHER_SPEC: u8 = 20
ALERT: u8 = 21
HANDSHAKE: u8 = 22
APPLICATION_DATA: u8 = 23
/// the largest plaintext fragment
MAX_PLAIN: usize = 1 << 14
/// the largest record body on the wire (protected: plaintext + type + tag, some slack)
MAX_RECORD: usize = MAX_PLAIN + 256
/// the cipher suites (TLS 1.3, then TLS 1.2 ECDHE)
TLS_AES_128_GCM_SHA256: u16 = 0x1301
TLS_AES_256_GCM_SHA384: u16 = 0x1302
TLS_CHACHA20_POLY1305_SHA256: u16 = 0x1303
ECDHE_ECDSA_AES128_GCM: u16 = 0xC02B
ECDHE_ECDSA_AES256_GCM: u16 = 0xC02C
ECDHE_RSA_AES128_GCM: u16 = 0xC02F
ECDHE_RSA_AES256_GCM: u16 = 0xC030
ECDHE_RSA_CHACHA20: u16 = 0xCCA8
ECDHE_ECDSA_CHACHA20: u16 = 0xCCA9
fn key_iv_len(suite: u16) -> Option<(usize, usize)>key and IV lengths of a suite (TLS 1.2: the IV is the implicit part)fn suite_hash(suite: u16) -> crypto::HashAlgthe hash of a suite's key schedule (TLS 1.3) or PRF (TLS 1.2)struct Cipherone direction's keys
impl Cipher
fn new(key: [u8; 32], iv: [u8; 12]) -> CipherTLS 1.3 with ChaCha20-Poly1305fn for_suite(suite: u16, key: &[u8], iv: &[u8], v12: bool) -> Option<Cipher>the keys of a suite (key and IV of key_iv_len); None for an unknown suitefn seal(&mut self, ty: u8, content: &[u8]) -> Vec<u8>a protected record ofcontentof typetyfn open(&mut self, hdr: &[u8; 5], body: &[u8]) -> Result<(u8, Vec<u8>), OpenError>open a protected record body (header given) -> (type, content)enum OpenErrorwhy a protected record did not openMac-- it does not authenticate (bad_record_mac)Overflow-- more than a record may hold (record_overflow)NoType-- only padding, no content type (unexpected_message)
fn plain(ty: u8, content: &[u8]) -> Vec<u8>a plaintext record