Documentation

Cryptlib.Primitives.KEM.MLKEM.MLKEM

ML-KEM: keygen/encaps/decaps and the KEM.KEM instance #

keygen/encaps/decaps are FIPS 203 Algorithms 19-21, written against Primitives.primitives so that variants such as hedged encapsulation can change them locally.

Reliable s states that the draw from s decapsulates correctly. It is not characterized in terms of the sampled noise.

keygen / encaps / decaps #

def Cryptlib.Primitives.KEM.FIPS203.keygen (ps : MLKEM.ParameterSet) (d z : MLKEM.Seed32) :
MLKEM.EncapsulationKey (params ps) (encoding ps) × MLKEM.DecapsulationKey (params ps) (encoding ps)

ML-KEM.KeyGen_internal.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    def Cryptlib.Primitives.KEM.FIPS203.encaps (ps : MLKEM.ParameterSet) (ek : MLKEM.EncapsulationKey (params ps) (encoding ps)) (m : MLKEM.Message) :
    MLKEM.SharedSecret × MLKEM.Ciphertext (params ps) (encoding ps)

    ML-KEM.Encaps_internal.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      def Cryptlib.Primitives.KEM.FIPS203.decaps (ps : MLKEM.ParameterSet) (dk : MLKEM.DecapsulationKey (params ps) (encoding ps)) (c : MLKEM.Ciphertext (params ps) (encoding ps)) :
      MLKEM.SharedSecret

      ML-KEM.Decaps_internal. Compares ciphertexts by their ByteArray encodings.

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

        FIPS 203 §7.2/§7.3 input-validation checks #

        The internal algorithms above do not validate keys; callers run these checks first.

        def Cryptlib.Primitives.KEM.FIPS203.checkEncapsulationKey (ps : MLKEM.ParameterSet) (ek : MLKEM.EncapsulationKey (params ps) (encoding ps)) :

        FIPS 203 §7.2 modulus check: tHatEncoded survives a decode/encode round trip.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def Cryptlib.Primitives.KEM.FIPS203.checkDecapsulationKey (ps : MLKEM.ParameterSet) (dk : MLKEM.DecapsulationKey (params ps) (encoding ps)) :

          FIPS 203 §7.3 hash check: dk.ekHash = H(ekPKE).

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

            keygen/encaps outputs are well-formed #

            theorem Cryptlib.Primitives.KEM.FIPS203.keygen_ek_wf (ps : MLKEM.ParameterSet) (d z : MLKEM.Seed32) :
            (tBytes ps (keygen ps d z).1.tHatEncoded).size = 384 * (params ps).k
            theorem Cryptlib.Primitives.KEM.FIPS203.keygen_dk_wf (ps : MLKEM.ParameterSet) (d z : MLKEM.Seed32) :
            (tBytes ps (keygen ps d z).2.dkPKE.sHatEncoded).size = 384 * (params ps).k ∧ (tBytes ps (keygen ps d z).2.ekPKE.tHatEncoded).size = 384 * (params ps).k

            State: a SHAKE-256 stream of 32-byte blocks from one 32-byte seed #

            The i-th 32-byte block derived from seed.

            Equations
            Instances For
              @[reducible, inline]

              Counter plus the original seed.

              Equations
              Instances For

                The KEM.KEM instance #

                def Cryptlib.Primitives.KEM.FIPS203.Reliable (ps : MLKEM.ParameterSet) (s : State) :

                The next draw from s, encapsulated against any key pair, decapsulates correctly.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def Cryptlib.Primitives.KEM.FIPS203.derivePublicKeyM (ps : MLKEM.ParameterSet) (sk : PrivateKey ps) :
                    Equations
                    Instances For
                      theorem Cryptlib.Primitives.KEM.FIPS203.honestRoundTripM (ps : MLKEM.ParameterSet) (sk : PrivateKey ps) (s : State) (hrel : Reliable ps s) (c : CT ps) (k : Vector UInt8 32) (s' : State) (hc : encapM ps (derivePublicKeyM ps sk) s = EStateM.Result.ok (c, k) s') (t : State) :
                      ∃ (t' : State), decapM ps sk c t = EStateM.Result.ok k t'

                      Round trip from a Reliable state. Uses simp only on hc; injection times out on the CT subtype.

                      theorem Cryptlib.Primitives.KEM.FIPS203.decodePrivateKey_totalM (ps : MLKEM.ParameterSet) (v : Vector UInt8 (params ps).secretKeyBytes) :
                      ∃ (sk : PrivateKey ps), decodePrivateKey ps v = some sk
                      def Cryptlib.Primitives.KEM.FIPS203.kem (ps : MLKEM.ParameterSet) :

                      ML-KEM with the expanded FIPS 203 private key.

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

                        Seed-format private keys #

                        kemSeed stores the private key as the seed (d, z), encoded ek ‖ d ‖ z, and re-expands it on use. Everything else is as in kem.

                        @[reducible, inline]
                        Equations
                        Instances For

                          The expanded decapsulation key for a seed, recomputed on every call.

                          Equations
                          Instances For
                            theorem Cryptlib.Primitives.KEM.FIPS203.honestRoundTripFromSeed (ps : MLKEM.ParameterSet) (sk : SeedPrivateKey) (s : State) :
                            Reliable ps s → ∀ (c : CT ps) (k : Vector UInt8 32) (s' : State), encapM ps (derivePublicKeyFromSeed ps sk) s = EStateM.Result.ok (c, k) s' → ∀ (t : State), ∃ (t' : State), decapMFromSeed ps sk c t = EStateM.Result.ok k t'
                            def Cryptlib.Primitives.KEM.FIPS203.encodePrivateKeyFromSeed (ps : MLKEM.ParameterSet) (sk : SeedPrivateKey) :
                            Vector UInt8 ((params ps).publicKeyBytes + 64)
                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def Cryptlib.Primitives.KEM.FIPS203.decodePrivateKeyFromSeed (ps : MLKEM.ParameterSet) (v : Vector UInt8 ((params ps).publicKeyBytes + 64)) :
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                theorem Cryptlib.Primitives.KEM.FIPS203.decodePrivateKeyFromSeed_total (ps : MLKEM.ParameterSet) (v : Vector UInt8 ((params ps).publicKeyBytes + 64)) :
                                def Cryptlib.Primitives.KEM.FIPS203.kemSeed (ps : MLKEM.ParameterSet) :

                                ML-KEM with the ek ‖ d ‖ z seed private key.

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