val payload_encrypt (a: ea) (k: AEAD.kv a) (siv: iv_t a) (h: header{~(is_retry h)}) (plain: pbytes)
    : GTot (cbytes)
val payload_encrypt (a: ea) (k: AEAD.kv a) (siv: iv_t a) (h: header{~(is_retry h)}) (plain: pbytes)
    : GTot (cbytes)
let payload_encrypt
  (a: ea)
  (k: AEAD.kv a)
  (siv: iv_t a)
  (h: header { ~ (is_retry h) })
  (plain: pbytes)
: GTot (cbytes)
=
  let aad = Parse.format_header h in
  let iv = iv_for_encrypt_decrypt a siv h in
  Seq.seq_reveal (AEAD.encrypt #a k iv (Seq.seq_hide aad) (Seq.seq_hide plain))
module QUIC.Spec

open QUIC.Spec.Lemmas
open QUIC.Spec.Header.Base

module Seq = QUIC.Secret.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module H = Spec.Agile.Hash
module HD = Spec.Hash.Definitions
module Cipher = Spec.Agile.Cipher
module AEAD = Spec.Agile.AEAD
module HKDF = Spec.Agile.HKDF
module Parse = QUIC.Spec.Header.Parse
module H = QUIC.Spec.Header
module Secret = QUIC.Secret.Int

/// encryption of a packet

let iv_for_encrypt_decrypt
  (a: ea)
  (siv: iv_t a)
  (h: header { ~ (is_retry h) })
: GTot (iv_t a)
=
  let pn_len = Secret.v (pn_length h) - 1 in
  let seqn = packet_number h in
  let _ = assert_norm(pow2 62 < pow2 (8 `op_Multiply` 12)) in
  let pnb = FStar.Endianness.n_to_be 12 (Secret.v seqn) in
  Seq.seq_hide #Secret.U8 (xor_inplace pnb (Seq.seq_reveal siv) 0)
/
Spec.Hash.Definitions.fst.checked Spec.Agile.HKDF.fsti.checked Spec.Agile.Hash.fsti.checked Spec.Agile.Cipher.fsti.checked Spec.Agile.AEAD.fsti.checked QUIC.Spec.Lemmas.fst.checked QUIC.Spec.Header.Parse.fsti.checked QUIC.Spec.Header.Base.fst.checked QUIC.Spec.Header.fsti.checked QUIC.Secret.Seq.fsti.checked QUIC.Secret.Int.fsti.checked prims.fst.checked FStar.UInt8.fsti.checked FStar.UInt32.fsti.checked FStar.Pervasives.fsti.checked FStar.Math.Lemmas.fst.checked FStar.Endianness.fsti.checked
QUIC.Spec.fst

    a: QUIC.Spec.Crypto.ea ->
    k: Spec.Agile.AEAD.kv a ->
    siv: QUIC.Spec.iv_t a ->
    h: QUIC.Spec.Header.Base.header{~(QUIC.Spec.Header.Base.is_retry h)} ->
    plain: QUIC.Spec.Crypto.pbytes
  -> Prims.GTot QUIC.Spec.Crypto.cbytes
QUIC.Spec.Crypto.ea Spec.Agile.AEAD.kv QUIC.Spec.iv_t QUIC.Spec.Header.Base.header Prims.l_not Prims.b2t QUIC.Spec.Header.Base.is_retry QUIC.Spec.Crypto.pbytes QUIC.Secret.Seq.seq_reveal Lib.IntTypes.U8 Lib.IntTypes.SEC Spec.Agile.AEAD.encrypt QUIC.Secret.Seq.seq_hide QUIC.Spec.iv_for_encrypt_decrypt QUIC.Spec.Base.lbytes QUIC.Spec.Header.Base.header_len QUIC.Spec.Header.Parse.format_header QUIC.Spec.Crypto.cbytes
let payload_encrypt (a: ea) (k: AEAD.kv a) (siv: iv_t a) (h: header{~(is_retry h)}) (plain: pbytes)
    : GTot (cbytes) =
  
let aad = Parse.format_header h in
let iv = iv_for_encrypt_decrypt a siv h in
Seq.seq_reveal (AEAD.encrypt #a k iv (Seq.seq_hide aad) (Seq.seq_hide plain))