Documentation

Cryptlib.Primitives.KEM.MLKEM.Encoding

ML-KEM: fixed-width wire types #

VCVio's key and ciphertext types wrapped in subtypes that fix their encoded sizes, so that decode ∘ encode = id holds. The Encoded* fields are ByteArray only up to unfolding, so tBytes/uBytes/vBytes cast them explicitly. Each decode* is split into a plain decode*Val and a well-formedness theorem; proving the round trip under the subtype directly exceeds maxRecDepth.

theorem Cryptlib.Primitives.KEM.FIPS203.secretKeyBytes_eq (ps : MLKEM.ParameterSet) :
(params ps).secretKeyBytes = 384 * (params ps).k + (384 * (params ps).k + (32 + (32 + 32)))
theorem Cryptlib.Primitives.KEM.FIPS203.ciphertextBytes_eq (ps : MLKEM.ParameterSet) :
(params ps).ciphertextBytes = 32 * (params ps).du * (params ps).k + 32 * (params ps).dv
def Cryptlib.Primitives.KEM.FIPS203.tBytes (ps : MLKEM.ParameterSet) (x : (encoding ps).EncodedTHat) :

x : encoding.EncodedTHat, as a plain ByteArray.

Equations
Instances For
    def Cryptlib.Primitives.KEM.FIPS203.bytesT (ps : MLKEM.ParameterSet) (x : ByteArray) :
    (encoding ps).EncodedTHat

    The reverse of tBytes.

    Equations
    Instances For
      theorem Cryptlib.Primitives.KEM.FIPS203.tBytes_bytesT (ps : MLKEM.ParameterSet) (x : ByteArray) :
      tBytes ps (bytesT ps x) = x
      theorem Cryptlib.Primitives.KEM.FIPS203.bytesT_tBytes (ps : MLKEM.ParameterSet) (x : (encoding ps).EncodedTHat) :
      bytesT ps (tBytes ps x) = x
      def Cryptlib.Primitives.KEM.FIPS203.uBytes (ps : MLKEM.ParameterSet) (x : (encoding ps).EncodedU) :

      x : encoding.EncodedU, as a plain ByteArray.

      Equations
      Instances For
        def Cryptlib.Primitives.KEM.FIPS203.bytesU (ps : MLKEM.ParameterSet) (x : ByteArray) :
        (encoding ps).EncodedU
        Equations
        Instances For
          theorem Cryptlib.Primitives.KEM.FIPS203.uBytes_bytesU (ps : MLKEM.ParameterSet) (x : ByteArray) :
          uBytes ps (bytesU ps x) = x
          theorem Cryptlib.Primitives.KEM.FIPS203.bytesU_uBytes (ps : MLKEM.ParameterSet) (x : (encoding ps).EncodedU) :
          bytesU ps (uBytes ps x) = x
          def Cryptlib.Primitives.KEM.FIPS203.vBytes (ps : MLKEM.ParameterSet) (x : (encoding ps).EncodedV) :

          x : encoding.EncodedV, as a plain ByteArray.

          Equations
          Instances For
            def Cryptlib.Primitives.KEM.FIPS203.bytesV (ps : MLKEM.ParameterSet) (x : ByteArray) :
            (encoding ps).EncodedV
            Equations
            Instances For
              theorem Cryptlib.Primitives.KEM.FIPS203.vBytes_bytesV (ps : MLKEM.ParameterSet) (x : ByteArray) :
              vBytes ps (bytesV ps x) = x
              theorem Cryptlib.Primitives.KEM.FIPS203.bytesV_vBytes (ps : MLKEM.ParameterSet) (x : (encoding ps).EncodedV) :
              bytesV ps (vBytes ps x) = x
              @[reducible, inline]
              abbrev Cryptlib.Primitives.KEM.FIPS203.PublicKey (ps : MLKEM.ParameterSet) :

              An encapsulation key whose tHatEncoded is 384 * k bytes.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[reducible, inline]
                abbrev Cryptlib.Primitives.KEM.FIPS203.PrivateKey (ps : MLKEM.ParameterSet) :

                A decapsulation key whose two encoded polynomial vectors are 384 * k bytes each.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  @[reducible, inline]
                  abbrev Cryptlib.Primitives.KEM.FIPS203.CT (ps : MLKEM.ParameterSet) :

                  A ciphertext whose uEncoded/vEncoded are 32 * du * k/32 * dv bytes.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    PublicKey #

                    def Cryptlib.Primitives.KEM.FIPS203.encodePublicKey (ps : MLKEM.ParameterSet) (pk : PublicKey ps) :
                    Vector UInt8 (params ps).publicKeyBytes
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      PrivateKey #

                      def Cryptlib.Primitives.KEM.FIPS203.encodePrivateKey (ps : MLKEM.ParameterSet) (sk : PrivateKey ps) :
                      Vector UInt8 (params ps).secretKeyBytes
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        CT (ciphertext) #

                        def Cryptlib.Primitives.KEM.FIPS203.encodeCiphertext (ps : MLKEM.ParameterSet) (c : CT ps) :
                        Vector UInt8 (params ps).ciphertextBytes
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For