Documentation

CatCryptCore.Examples.ShamirSecretSharing

Shamir t-out-of-n Secret Sharing: Reconstruction and Perfect Privacy #

Shamir's secret-sharing scheme over the finite field ZMod p (p prime): a secret s is shared by sampling a uniformly random polynomial f of degree < t with f(0) = s, and handing party i the point f(xᵢ) at a distinct, nonzero evaluation point xᵢ. Reconstruction from any t shares is Lagrange interpolation; perfect privacy says any t-1 shares are jointly uniform and independent of s.

We model a degree-< t polynomial by its constant coefficient s (the secret) together with d := t-1 free coefficients a : Fin d → ZMod p (the coefficients of X¹, …, X^d). Sharing at a point q is then shareVal s a q = s + ∑ᵢ aᵢ · q^{i+1}, which is exactly the evaluation of the polynomial build s a = C s + ∑ᵢ C aᵢ · X^{i+1} at q (shareVal_eq_eval).

Main definitions #

Main results #

The privacy coupling avoids inverting a Vandermonde matrix: the difference of the two secrets is absorbed by translating the free-coefficient vector by the free coefficients of (s₁ - s₀) · L, where L is the degree-< t polynomial that is 1 at 0 and 0 at every revealed point (vanishPoly). Since translation is a bijection of the sampling space, advantage_zero_of_rHoare collapses the advantage to 0. This mirrors the poly_bij construction of the SSProve-Rocq proof, adapted to a coefficient-vector coupling.

References #

The scheme #

def CatCrypt.Examples.ShamirSecretSharing.shareVal {p : } [Fact (Nat.Prime p)] {d : } (s : ZMod p) (a : Fin dZMod p) (q : ZMod p) :

The share of a degree-< d+1 polynomial with constant term s and free coefficients a (the coefficients of X¹, …, X^d), evaluated at q.

Equations
Instances For
    noncomputable def CatCrypt.Examples.ShamirSecretSharing.build {p : } [Fact (Nat.Prime p)] {d : } (s : ZMod p) (a : Fin dZMod p) :

    The underlying polynomial C s + ∑ᵢ C aᵢ · X^{i+1}.

    Equations
    Instances For
      theorem CatCrypt.Examples.ShamirSecretSharing.shareVal_eq_eval {p : } [Fact (Nat.Prime p)] {d : } (s : ZMod p) (a : Fin dZMod p) (q : ZMod p) :

      shareVal is the evaluation of build.

      The polynomial has degree at most d (i.e. < t = d+1).

      theorem CatCrypt.Examples.ShamirSecretSharing.shareVal_zero {p : } [Fact (Nat.Prime p)] {d : } (s : ZMod p) (a : Fin dZMod p) :
      shareVal s a 0 = s

      The constant term is the secret: shareVal s a 0 = s.

      Reconstruction (general t-out-of-n) #

      theorem CatCrypt.Examples.ShamirSecretSharing.shamir_reconstruct {p : } [Fact (Nat.Prime p)] {d : } (x : Fin (d + 1)ZMod p) (hx : Function.Injective x) (s : ZMod p) (a : Fin dZMod p) :
      Polynomial.eval 0 ((Lagrange.interpolate Finset.univ x) fun (j : Fin (d + 1)) => shareVal s a (x j)) = s

      Reconstruction. For any t = d+1 distinct evaluation points x, Lagrange interpolation through the shares shareVal s a (x j) recovers the secret s = f(0). This is the correctness of Shamir reconstruction from any t shares.

      The vanishing polynomial for the privacy coupling #

      noncomputable def CatCrypt.Examples.ShamirSecretSharing.vanishPoly {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) :

      L: the degree-< t polynomial equal to 1 at 0 and 0 at every revealed point rp j. Built as (∏ⱼ (0 - rp j))⁻¹ · ∏ⱼ (X - rp j).

      Equations
      Instances For
        theorem CatCrypt.Examples.ShamirSecretSharing.vanishPoly_eval {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (q : ZMod p) :
        Polynomial.eval q (vanishPoly rp) = (∏ j : Fin d, (0 - rp j))⁻¹ * j : Fin d, (q - rp j)
        theorem CatCrypt.Examples.ShamirSecretSharing.prod_zero_sub_ne {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) :
        j : Fin d, (0 - rp j) 0
        theorem CatCrypt.Examples.ShamirSecretSharing.vanishPoly_eval_zero {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) :
        theorem CatCrypt.Examples.ShamirSecretSharing.vanishPoly_coeff_zero {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) :
        (vanishPoly rp).coeff 0 = 1

        The free-coefficient sum identity #

        theorem CatCrypt.Examples.ShamirSecretSharing.freeSum {p : } [Fact (Nat.Prime p)] {d : } (f : Polynomial (ZMod p)) (hf : f.natDegree d) (q : ZMod p) :
        i : Fin d, f.coeff (i + 1) * q ^ (i + 1) = Polynomial.eval q f - f.coeff 0

        For a polynomial of degree ≤ d, the "free-coefficient sum" ∑ᵢ f.coeff (i+1) · q^{i+1} equals f(q) - f.coeff 0.

        The translation vector and the share-equality identity #

        noncomputable def CatCrypt.Examples.ShamirSecretSharing.transVec {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (s0 s1 : ZMod p) :
        Fin dZMod p

        The free-coefficient translation absorbing the secret difference s₁ - s₀.

        Equations
        Instances For
          theorem CatCrypt.Examples.ShamirSecretSharing.shareVal_translate {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) (s0 s1 : ZMod p) (a : Fin dZMod p) (j : Fin d) :
          shareVal s1 (a + transVec rp s0 s1) (rp j) = shareVal s0 a (rp j)

          Share-equality under translation. Sharing s₁ with the translated free coefficients a + transVec produces the same revealed shares as sharing s₀ with a. This is the information-theoretic core of privacy.

          The privacy game #

          noncomputable def CatCrypt.Examples.ShamirSecretSharing.PrivGame {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (s0 s1 : ZMod p) (b : Bool) :
          Core.SPComp (Fin dZMod p)

          The (t-1)-share privacy game. The corrupted parties hold their shares at the d = t-1 revealed points rp of one of two secrets: PrivGame rp s₀ s₁ true shares s₀, PrivGame rp s₀ s₁ false shares s₁.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            noncomputable def CatCrypt.Examples.ShamirSecretSharing.PrivAdv {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (s0 s1 : ZMod p) (A : (Fin dZMod p)Core.SPComp Bool) :

            Privacy advantage: the corrupted parties' distinguishing probability between (t-1) shares of s₀ and of s₁.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem CatCrypt.Examples.ShamirSecretSharing.priv_coupling {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) (s0 s1 : ZMod p) :

              Coupling: for any t-1 nonzero revealed points, the two privacy games are equidistributed. Translating the uniformly sampled free-coefficient vector by transVec (a bijection of the sampling space) keeps every revealed share fixed while switching the secret from s₀ to s₁.

              theorem CatCrypt.Examples.ShamirSecretSharing.shamir_perfect_privacy {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) (s0 s1 : ZMod p) (A : (Fin dZMod p)Core.SPComp Bool) :
              PrivAdv rp s0 s1 A = 0

              Shamir (t-1)-share perfect privacy. For any t-1 nonzero evaluation points, any two secrets s₀, s₁, and any adversary A, the privacy advantage is exactly 0: any t-1 shares are uniform and independent of the secret.

              Reflection into the Package / UC Stack #

              The shallow shamir_perfect_privacy bounds a single distinguisher applied to the two privacy-game bodies. This section lifts it to a composable statement about deep nominal packages linked with an arbitrary adversary package, following the stack shallow game → rawCode% → NomPackage.ofOracle → DeepNomAdvantage → sdist → UC via the shared CatCryptCore.Deep.ReflectUCHelpers combinators. The privacy game samples a free-coefficient vector then returns the revealed shares (heap-independent), so the shallow coupling priv_coupling (for nonzero revealed points hrp) upgrades to a full SPComp equality of the two reflected bodies (spcomp_eq_of_isPure_coupling), and the whole stack follows with no purity bridge on the adversary.

              noncomputable def CatCrypt.Examples.ShamirSecretSharing.shamirGameRaw {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (s0 s1 : ZMod p) (b : Bool) :

              The reflected (t-1)-share privacy-game body for bit b: sample a uniform free-coefficient vector a and reveal the shares at the corrupted points.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem CatCrypt.Examples.ShamirSecretSharing.shamirGameRaw_eval_shallow {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (s0 s1 : ZMod p) (b : Bool) :
                (shamirGameRaw rp s0 s1 b).eval = PrivGame rp s0 s1 b

                The reflected body evaluates back to the shallow privacy game.

                theorem CatCrypt.Examples.ShamirSecretSharing.shamir_game_isPure {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (s0 s1 : ZMod p) (b : Bool) :
                (PrivGame rp s0 s1 b).IsPure

                The privacy game is heap-independent (a uniform coefficient sample then pure share reveals).

                theorem CatCrypt.Examples.ShamirSecretSharing.shamirGameRaw_eval_eq {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) (s0 s1 : ZMod p) :

                The two reflected bodies (shares of s0 vs. s1) have equal evaluations: for nonzero revealed points the coupling priv_coupling upgrades to SPComp equality.

                noncomputable def CatCrypt.Examples.ShamirSecretSharing.shamirGameTrue {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (s0 s1 : ZMod p) :

                Real privacy game as an oracle-exporting nominal package (shares s0).

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  noncomputable def CatCrypt.Examples.ShamirSecretSharing.shamirGameFalse {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (s0 s1 : ZMod p) :

                  Ideal privacy game as an oracle-exporting nominal package (shares s1).

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem CatCrypt.Examples.ShamirSecretSharing.shamir_deepnom_zero {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) (s0 s1 : ZMod p) (A : Deep.NomPackage) :

                    Zero deep-nominal advantage against every adversary package (nonzero points).

                    theorem CatCrypt.Examples.ShamirSecretSharing.shamir_sdist_zero {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) (s0 s1 : ZMod p) :

                    Statistical distance zero between the two linked-game families.

                    theorem CatCrypt.Examples.ShamirSecretSharing.shamir_nompkg_secure {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) (s0 s1 : ZMod p) :

                    Package-level perfect privacy (NomPkgSecure).

                    theorem CatCrypt.Examples.ShamirSecretSharing.shamir_uc {p : } [Fact (Nat.Prime p)] {d : } (rp : Fin dZMod p) (hrp : ∀ (j : Fin d), rp j 0) (s0 s1 : ZMod p) :
                    Crypto.UCEmulates 0 { hon := Deep.NomPackage, out := Bool, leak := Empty, sim_if := Empty, view := Bool } (fun (A : { hon := Deep.NomPackage, out := Bool, leak := Empty, sim_if := Empty, view := Bool }.hon) => Core.SPComp.map Sum.inl (Crypto.runPkg (A.pkg.link (shamirGameTrue rp s0 s1).pkg))) fun (A : { hon := Deep.NomPackage, out := Bool, leak := Empty, sim_if := Empty, view := Bool }.hon) => Core.SPComp.map Sum.inl (Crypto.runPkg (A.pkg.link (shamirGameFalse rp s0 s1).pkg))

                    Perfect UC emulation of the linked-game families over the trivial-leak interface (out = Bool, leak = Empty) with the identity simulator (composition plumbing).