quic_aead_ctx (quic v1.10.0)

View Source

Summary

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.

One ECB block for AES header protection (mask source).

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

aead_decrypt(Cipher, Key, Nonce, CiphertextWithTag, AAD)

-spec aead_decrypt(atom(), binary(), binary(), binary(), binary()) -> binary() | error.

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.

aead_encrypt(Cipher, Key, Nonce, Plaintext, AAD)

-spec aead_encrypt(atom(), binary(), binary(), binary(), binary()) -> binary().

Seal: returns Ciphertext||Tag.

hp_block(Cipher, Key, Sample)

-spec hp_block(aes_128_ecb | aes_256_ecb, binary(), binary()) -> binary().

One ECB block for AES header protection (mask source).

open_packet(Cipher, Key, IV, HP, LargestRecv, ExpectedPhase, Header, EncPayload)

-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).

open_run(Cipher, Key, IV, HP, LargestRecv, ExpectedPhase, DcidLen, Datagrams)

-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.

protect_run(Cipher, Key, IV, HP, PN0, FirstByteBase, DCID, Payloads)

-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.