JFLib

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::HashAlg the hash of a suite's key schedule (TLS 1.3) or PRF (TLS 1.2)

  • struct Cipher one direction's keys

impl Cipher

  • fn new(key: [u8; 32], iv: [u8; 12]) -> Cipher TLS 1.3 with ChaCha20-Poly1305

  • fn 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 suite

  • fn seal(&mut self, ty: u8, content: &[u8]) -> Vec<u8> a protected record of content of type ty

  • fn open(&mut self, hdr: &[u8; 5], body: &[u8]) -> Result<(u8, Vec<u8>), OpenError> open a protected record body (header given) -> (type, content)

  • enum OpenError why a protected record did not open

    • Mac -- 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

Source: docs/API.md in the JFLib repository.