Documentation

Complexity.Crypto.Computational.Homomorphic.GSW.Sampling

Finite sampling for the GSW construction #

Residues are sampled from exactly w fair bits. Each integer error is the difference of two independent counts of η fair bits, so every supported error has magnitude at most η. The actual key-generation and encryption programs feed these independent draws to the GSW formulas. Their correctness holds for every supported draw under an explicit strict margin.

This exact noise distribution is a construction choice. No Gaussian equivalence, LWE hardness, encryption security, complete native algorithm certificate or bootstrappability is asserted.

Main definitions #

Main results #

References #

Sample one residue from w independent fair bits.

Instances For
    @[simp]

    The fair-bit residue sampler is exactly uniform, including at width zero.

    noncomputable def Cslib.Crypto.Homomorphic.GSW.sampleVector (count w : ℕ) :
    ProbComp (Fin count → ZMod (2 ^ w))

    Sample independent residues into a length-indexed vector.

    Instances For
      noncomputable def Cslib.Crypto.Homomorphic.GSW.sampleMatrix (rows cols w : ℕ) :
      ProbComp (Matrix (Fin rows) (Fin cols) (ZMod (2 ^ w)))

      Sample independent rows of independent residues.

      Instances For
        noncomputable def Cslib.Crypto.Homomorphic.GSW.sampleCoins (n m w : ℕ) :
        ProbComp (Matrix (Fin (n + 1) × Fin w) (Fin m) Bool)

        Sample every entry of the binary encryption matrix independently.

        Instances For

          The separately sampled secret, public-matrix part and integer errors.

          • secret : Fin n → ZMod (2 ^ w)

            Uniform secret entries.

          • publicPart : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))

            Uniform public matrix entries.

          • error : Fin m → ℤ

            Independent bounded integer errors.

          Instances For
            noncomputable def Cslib.Crypto.Homomorphic.GSW.sampleKeyInputs (n m w η : ℕ) :

            Draw the three inputs independently, using the specified finite error distribution.

            Instances For
              theorem Cslib.Crypto.Homomorphic.GSW.eval_sampleKeyInputs (n m w η : ℕ) :
              (sampleKeyInputs n m w η).eval = do let secret ← Probability.PMF.uniformOfFintype (Fin n → ZMod (2 ^ w)) let publicPart ← Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) let error ← ProbComp.eval (OracleComp.replicateFin m (Probability.sampleCenteredBinomial η)) pure { secret := secret, publicPart := publicPart, error := error }

              The complete joint law retains the independence of the secret, public part and errors.

              theorem Cslib.Crypto.Homomorphic.GSW.mem_support_sampleKeyInputs_iff (n m w η : ℕ) (inputs : KeyInputs n m w) :
              inputs ∈ (sampleKeyInputs n m w η).eval.support ↔ ∀ (i : Fin m), (inputs.error i).natAbs ≤ η

              Every secret and public part is possible; the exact error restriction is coordinatewise.

              noncomputable def Cslib.Crypto.Homomorphic.GSW.keyGen (n m w η : ℕ) :
              ProbComp (Matrix (Fin m) (Fin (n + 1)) (ZMod (2 ^ w)) × (Fin n → ZMod (2 ^ w)))

              Generate the actual public matrix and retain the sampled secret.

              Instances For
                noncomputable def Cslib.Crypto.Homomorphic.GSW.encrypt {n m w : ℕ} (A : Matrix (Fin m) (Fin (n + 1)) (ZMod (2 ^ w))) (μ : Bool) :

                Encrypt a Boolean message using only the public matrix and independently sampled coins.

                Instances For
                  theorem Cslib.Crypto.Homomorphic.GSW.mem_support_encrypt_iff {n m w : ℕ} (A : Matrix (Fin m) (Fin (n + 1)) (ZMod (2 ^ w))) (μ : Bool) (C : Ciphertext n w) :
                  C ∈ (encrypt A μ).eval.support ↔ ∃ (coins : Matrix (Fin (n + 1) × Fin w) (Fin m) Bool), encryptWithCoins A μ coins = C

                  A supported ciphertext is precisely an encryption with some binary coin matrix.

                  theorem Cslib.Crypto.Homomorphic.GSW.keyGen_encrypt_correct {n m w η : ℕ} (hw : 0 < w) (hmargin : 4 * (m * η) < 2 ^ w) {keys : Matrix (Fin m) (Fin (n + 1)) (ZMod (2 ^ w)) × (Fin n → ZMod (2 ^ w))} (hkeys : keys ∈ (keyGen n m w η).eval.support) (μ : Bool) {C : Ciphertext n w} (hC : C ∈ (encrypt keys.1 μ).eval.support) :
                  decrypt keys.2 C = μ

                  Every generated key and every supported fresh ciphertext are correct under the strict margin.

                  theorem Cslib.Crypto.Homomorphic.GSW.keyGen_nand_correct {n m w η : ℕ} (hw : 0 < w) (hmargin : 4 * ((1 + (n + 1) * w) * (m * η)) < 2 ^ w) {keys : Matrix (Fin m) (Fin (n + 1)) (ZMod (2 ^ w)) × (Fin n → ZMod (2 ^ w))} (hkeys : keys ∈ (keyGen n m w η).eval.support) (μ₁ μ₂ : Bool) {C₁ C₂ : Ciphertext n w} (hC₁ : C₁ ∈ (encrypt keys.1 μ₁).eval.support) (hC₂ : C₂ ∈ (encrypt keys.1 μ₂).eval.support) :
                  decrypt keys.2 (nand C₁ C₂) = !(μ₁ && μ₂)

                  NAND of any two supported fresh ciphertexts is correct for every generated key.