~/bend-docscommunity

tls13.bend checks

raw source on the hub · import element-tls13@0.1.0.0/tls13.bend as Tls13

8 imports
import Base
import element-crypto@0.1.0.0/suite.bend as Suite
import element-crypto@0.1.0.0/sha256.bend as Sha256
import element-crypto@0.1.0.0/hmac.bend as Hmac
import element-crypto@0.1.0.0/chacha20.bend as ChaCha
import element-crypto@0.1.0.0/poly1305.bend as Poly
import element-crypto@0.1.0.0/gcm.bend as Gcm
import element-crypto@0.1.0.0/x25519.bend as X

Types

type Inner source · line 232 · raw

Data

Strip the zero padding and the content type from a decrypted record.

type Msgs source · line 282 · raw

Data

Split a byte stream into whole handshake messages (type, u24 length, body). Returns the messages and the leftover bytes of an incomplete one.

Definitions

def u8 source · line 21 · raw

@+n:U32 -> List<&2, U32>

def u16 source · line 24 · raw

@+n:U32 -> List<&2, U32>

def u24 source · line 27 · raw

@+n:U32 -> List<&2, U32>

def len source · line 30 · raw

@xs:List<&2, U32> -> U32

def vec8 source · line 33 · raw

@+xs:List<&2, U32> -> List<&2, U32>

def vec16 source · line 36 · raw

@+xs:List<&2, U32> -> List<&2, U32>

def vec24 source · line 39 · raw

@+xs:List<&2, U32> -> List<&2, U32>

def cat source · line 42 · raw

@xss:List<&2, List<&2, U32>> -> List<&2, U32>

def nth source · line 45 · raw

@xs:List<&2, U32> -> @n:Nat -> U32

def get16 source · line 48 · raw

@+xs:List<&2, U32> -> @+i:Nat -> U32

def get24 source · line 51 · raw

@+xs:List<&2, U32> -> @+i:Nat -> U32

def slice source · line 54 · raw

@+xs:List<&2, U32> -> @+from:U32 -> @+n:U32 -> List<&2, U32>

def zeros source · line 57 · raw

@n:Nat -> List<&2, U32>

def ascii source · line 60 · raw

@s:String -> List<&2, U32>

def hash source · line 63 · raw

@+xs:List<&2, U32> -> List<&2, U32>

def expand_label source · line 68 · raw

@+secret:List<&2, U32> -> @+label:String -> @+ctx:List<&2, U32> -> @+n:U32 -> List<&2, U32>

def derive_secret source · line 71 · raw

@+secret:List<&2, U32> -> @+label:String -> @+transcript:List<&2, U32> -> List<&2, U32>

def early_secret source · line 74 · raw

List<&2, U32>

def handshake_secret source · line 77 · raw

@+ecdhe:List<&2, U32> -> List<&2, U32>

def master_secret source · line 80 · raw

@+hs:List<&2, U32> -> List<&2, U32>

def traffic_key source · line 83 · raw

@+secret:List<&2, U32> -> @+n:U32 -> List<&2, U32>

def traffic_iv source · line 86 · raw

@+secret:List<&2, U32> -> List<&2, U32>

def verify_data source · line 90 · raw

@+base:List<&2, U32> -> @+transcript:List<&2, U32> -> List<&2, U32>

Finished (4.4.4): HMAC over the transcript hash with the "finished" key.

def handshake source · line 95 · raw

@+typ:U32 -> @+body:List<&2, U32> -> List<&2, U32>

def ext source · line 98 · raw

@+typ:U32 -> @+body:List<&2, U32> -> List<&2, U32>

def client_hello source · line 112 · raw

@+host:String -> @+random:List<&2, U32> -> @+session:List<&2, U32> -> @+pub:List<&2, U32> -> List<&2, U32>

ClientHello (4.1.2) offering TLS 1.3, then TLS 1.2 for servers that speak nothing newer (tls/tls12.bend), x25519 only. Suites: AES-128-GCM then ChaCha20-Poly1305 for 1.3; ECDHE with the same two AEADs for 1.2. Signature algorithms are the ones x509 verifies: ecdsa_secp256r1_sha256, ecdsa_secp384r1_sha384, rsa_pss_rsae_sha256/384/512, and rsa_pkcs1_sha256/384/512 (certificates, and TLS 1.2 ServerKeyExchange). For 1.2 also ec_point_formats (uncompressed), extended_master_secret and an empty renegotiation_info, as Chrome sends them. supported_groups lists secp256r1 and secp384r1 after x25519: a TLS 1.2 server may present an ECDSA certificate only on a curve the client lists (RFC 8422 5.1), and TLS 1.2 ECDHE runs on x25519 or P-256. The 1.3 key share is x25519.

def find_ext source · line 131 · raw

@fuel:Nat -> @+exts:List<&2, U32> -> @+want:U32 -> List<&2, U32>

ServerHello: find the x25519 key_share (extension 51) and the chosen version (43). Returns the server's public key, or Nil if absent.

def sh_extensions source · line 143 · raw

@+sh:List<&2, U32> -> List<&2, U32>

ServerHello body offsets: version 2, random 32, session_id vec8, cipher 2, compression 1, extensions vec16.

def sh_cipher source · line 149 · raw

@+sh:List<&2, U32> -> U32

def sh_key_share source · line 153 · raw

@+sh:List<&2, U32> -> List<&2, U32>

def sh_version source · line 157 · raw

@+sh:List<&2, U32> -> U32

def sh_legacy source · line 161 · raw

@+sh:List<&2, U32> -> U32

ServerHello's legacy_version (0x0303 for both 1.2 and 1.3) and random.

def sh_random source · line 164 · raw

@+sh:List<&2, U32> -> List<&2, U32>

def ext_present source · line 167 · raw

@fuel:Nat -> @+exts:List<&2, U32> -> @+want:U32 -> Bool

def sh_ems source · line 179 · raw

@+sh:List<&2, U32> -> Bool

extended_master_secret (RFC 7627) echoed by a TLS 1.2 server

def is_hrr source · line 184 · raw

@+sh:List<&2, U32> -> Bool

HelloRetryRequest has this fixed "random" (4.1.3).

def nonce source · line 190 · raw

@+iv:List<&2, U32> -> @+seq:U32 -> List<&2, U32>

nonce = iv XOR (64-bit sequence number, left-padded to 12 bytes)

def record source · line 193 · raw

@+typ:U32 -> @+body:List<&2, U32> -> List<&2, U32>

def key_len source · line 197 · raw

@+suite:U32 -> U32

The suite's traffic key length: 16 for AES-128-GCM, 32 for ChaCha20.

def is_suite source · line 200 · raw

@+suite:U32 -> Bool

def seal_go source · line 205 · raw

@gcm:Bool -> @+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+pt:List<&2, U32> -> List<&2, U32>

The AEAD follows the key: a 16-byte key is AES-128-GCM, else ChaCha20- Poly1305. Keys carry the suite, so no record state has to.

def open_go source · line 212 · raw

@gcm:Bool -> @+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+ct:List<&2, U32> -> Maybe<&2, List<&2, U32>>

def seal source · line 219 · raw

@+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+pt:List<&2, U32> -> List<&2, U32>

def open source · line 222 · raw

@+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+ct:List<&2, U32> -> Maybe<&2, List<&2, U32>>

def protect source · line 226 · raw

@+key:List<&2, U32> -> @+iv:List<&2, U32> -> @+seq:U32 -> @+typ:U32 -> @+content:List<&2, U32> -> List<&2, U32>

5.2: the inner plaintext is content | type; the record header is the AAD.

def head_zero source · line 235 · raw

@xs:List<&2, U32> -> Bool

def drop_zeros source · line 245 · raw

@rev:List<&2, U32> -> @zero:Bool -> List<&2, U32>

Drop the trailing zero padding (the list is reversed, so it is leading here). zero says whether the head is zero; it is computed by the caller, so only one branch ever runs (a Bool.pick would recurse on every call).

def inner_from source · line 256 · raw

@rev:List<&2, U32> -> Inner

def strip_go source · line 263 · raw

@+rev:List<&2, U32> -> Inner

def inner_of source · line 266 · raw

@m:Maybe<&2, List<&2, U32>> -> Maybe<&2, Inner>

def unprotect source · line 275 · raw

@+key:List<&2, U32> -> @+iv:List<&2, U32> -> @+seq:U32 -> @+hdr:List<&2, U32> -> @+body:List<&2, U32> -> Maybe<&2, Inner>

Decrypt one record body (after the 5-byte header hdr); None if the tag does not verify.

def whole_msg source · line 285 · raw

@+bs:List<&2, U32> -> Bool

def split_msgs_go source · line 289 · raw

@fuel:Nat -> @+bs:List<&2, U32> -> @+acc:List<&2, List<&2, U32>> -> @go:Bool -> Msgs

go: a whole message is at the front (computed by the caller, see drop_zeros).

def split_msgs source · line 302 · raw

@fuel:Nat -> @+bs:List<&2, U32> -> @+acc:List<&2, List<&2, U32>> -> Msgs

def msg_type source · line 305 · raw

@+m:List<&2, U32> -> U32