quic_aead_ctx (quic v3.3.0)
View SourceSummary
Functions
Open: takes Ciphertext||Tag; returns Plaintext | error. The whole thing is passed in so the length check lives in one place: both the NIF and the OTP path need the tag split off, and neither may be handed input too short to hold one.
Seal: returns Ciphertext||Tag.
Drop the cached contexts of keys that are being discarded, so the key schedules go with the keys (RFC 9001 Section 4.9). Takes either the two key records of a discarded packet-number space, one key record (0-RTT holds a single pair of directions in one record set), or undefined. Erases both the NIF-path entries and, through quic_aead:forget_ctx/4, the OTP-path cipher contexts the default implementation caches; see quic_aead:aead_ctx/3 and ecb_ctx/2.
Drop the AEAD contexts of keys whose header-protection context must survive: on a key update the new keys keep the same HP key (RFC 9001 Sections 5.4 and 6.1), so dropping it would evict the context the live keys use on every packet. Only the AEAD contexts and cache entries of the retired keys go.
One ECB block for AES header protection (mask source).
What a context cache is keyed by in place of the key, so the process dictionary, which crash reports and sys:get_status/1 print, holds no key. Two independent 32-bit hashes of a random key collide with probability 2^-64.
Fused short-header receive: header unprotection, PN reconstruction and AEAD open in one NIF call. Returns {ok, PN, UnprotectedFirstByte, Plaintext}, error on authentication failure, or fallback (NIF missing, ChaCha, or the packet's key phase differs from ExpectedPhase - the caller then runs the generic path with key selection).
Batched open_packet over a train of short-header datagrams (FirstByte + DCID + PN + ciphertext + tag each). Returns the opened prefix; a shorter list than Datagrams means the remainder must be run through the generic per-packet path. fallback when the NIF is unavailable or the cipher is ChaCha.
Seal a run of short-header packets with consecutive PNs in one NIF call (header build + nonce + AEAD + header protection fused). Returns {ok, [WirePacket]} or fallback when the NIF is not loaded, the cipher is ChaCha (its HP is not ECB) or the NIF rejects the input - callers then take the per-packet path.
Functions
Open: takes Ciphertext||Tag; returns Plaintext | error. The whole thing is passed in so the length check lives in one place: both the NIF and the OTP path need the tag split off, and neither may be handed input too short to hold one.
Seal: returns Ciphertext||Tag.
-spec discard([{#crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}, #crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}} | #crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}] | {#crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}, #crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}} | #crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305} | undefined) -> ok.
Drop the cached contexts of keys that are being discarded, so the key schedules go with the keys (RFC 9001 Section 4.9). Takes either the two key records of a discarded packet-number space, one key record (0-RTT holds a single pair of directions in one record set), or undefined. Erases both the NIF-path entries and, through quic_aead:forget_ctx/4, the OTP-path cipher contexts the default implementation caches; see quic_aead:aead_ctx/3 and ecb_ctx/2.
-spec discard_aead([{#crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}, #crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}} | #crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}] | {#crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}, #crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305}} | #crypto_keys{key :: binary(), iv :: binary(), hp :: binary(), cipher :: aes_128_gcm | aes_256_gcm | chacha20_poly1305} | undefined) -> ok.
Drop the AEAD contexts of keys whose header-protection context must survive: on a key update the new keys keep the same HP key (RFC 9001 Sections 5.4 and 6.1), so dropping it would evict the context the live keys use on every packet. Only the AEAD contexts and cache entries of the retired keys go.
One ECB block for AES header protection (mask source).
-spec key_id(binary()) -> {non_neg_integer(), non_neg_integer()}.
What a context cache is keyed by in place of the key, so the process dictionary, which crash reports and sys:get_status/1 print, holds no key. Two independent 32-bit hashes of a random key collide with probability 2^-64.
-spec open_packet(atom(), binary(), binary(), binary(), non_neg_integer() | undefined, 0 | 1, binary(), binary()) -> {ok, non_neg_integer(), byte(), binary()} | error | fallback.
Fused short-header receive: header unprotection, PN reconstruction and AEAD open in one NIF call. Returns {ok, PN, UnprotectedFirstByte, Plaintext}, error on authentication failure, or fallback (NIF missing, ChaCha, or the packet's key phase differs from ExpectedPhase - the caller then runs the generic path with key selection).
-spec open_run(atom(), binary(), binary(), binary(), non_neg_integer() | undefined, 0 | 1, non_neg_integer(), [binary()]) -> {ok, [{non_neg_integer(), byte(), [term()] | {raw, binary()}}]} | fallback.
Batched open_packet over a train of short-header datagrams (FirstByte + DCID + PN + ciphertext + tag each). Returns the opened prefix; a shorter list than Datagrams means the remainder must be run through the generic per-packet path. fallback when the NIF is unavailable or the cipher is ChaCha.
-spec protect_run(atom(), binary(), binary(), binary(), non_neg_integer(), byte(), binary(), [iodata()]) -> {ok, [binary()]} | fallback.
Seal a run of short-header packets with consecutive PNs in one NIF call (header build + nonce + AEAD + header protection fused). Returns {ok, [WirePacket]} or fallback when the NIF is not loaded, the cipher is ChaCha (its HP is not ECB) or the NIF rejects the input - callers then take the per-packet path.