Documentation

CatCryptCore.Crypto.KeyAgreement.MontgomeryLadder

Montgomery Ladder Algebraic Correctness #

Proves that the Montgomery double-and-add ladder, viewed as an iterated group operation on an abstract abelian group G, computes n · P for a scalar n processed bit-by-bit from MSB to LSB.

Scope #

This is the algebraic correctness of the ladder. It does not depend on:

What is proved #

For any abelian group G, any element P : G, and any natural number n with n.size bits, starting from the state (0 · P, 1 · P) and iterating the ladder step over the bits of n from MSB to LSB, the final state (R₀, R₁) satisfies R₀ = n · P and R₁ = (n + 1) · P.

This is the invariant-based correctness argument: standard folklore dating to Montgomery's 1987 paper, formalised here as a pure induction on bit length.

What is NOT proved #

References #

Ladder step #

def CatCrypt.Crypto.ECC.ladderStep {G : Type u_1} [AddCommGroup G] (acc : G × G) (b : Bool) :
G × G

One step of the Montgomery ladder, operating on a pair of group elements. The state (R₀, R₁) is intended to maintain the invariant R₀ = a · P, R₁ = (a + 1) · P for some running a; a single step with bit b updates a to 2 a + (if b then 1 else 0).

Equations
Instances For
    def CatCrypt.Crypto.ECC.ladderFold {G : Type u_1} [AddCommGroup G] (P : G) :
    List BoolG × G

    Running the ladder on a list of bits (head = MSB processed first).

    Equations
    Instances For

      Key invariant #

      def CatCrypt.Crypto.ECC.LadderInv {G : Type u_1} [AddCommGroup G] (P : G) (a : ) (st : G × G) :

      The invariant predicate: (R₀, R₁) = (a · P, (a + 1) · P).

      Equations
      Instances For
        theorem CatCrypt.Crypto.ECC.ladderInv_init {G : Type u_1} [AddCommGroup G] (P : G) :
        LadderInv P 0 (0, P)

        Initial state (0, P) satisfies the invariant with a = 0.

        theorem CatCrypt.Crypto.ECC.ladderStep_inv {G : Type u_1} [AddCommGroup G] (P : G) (a : ) (st : G × G) (b : Bool) (h : LadderInv P a st) :
        LadderInv P (2 * a + if b = true then 1 else 0) (ladderStep st b)

        Core step lemma: if (R₀, R₁) satisfies the invariant at scalar a, then ladderStep (R₀, R₁) b satisfies the invariant at scalar 2 a + (if b then 1 else 0).

        Scalar reconstruction from bits #

        Compute the natural number represented by a list of bits, MSB first. bitsToNat [b₂, b₁, b₀] = 4 b₂ + 2 b₁ + b₀ etc.

        Equations
        Instances For

          Main correctness theorem #

          theorem CatCrypt.Crypto.ECC.ladderFold_correct {G : Type u_1} [AddCommGroup G] (P : G) (bits : List Bool) :
          LadderInv P (bitsToNat bits) (ladderFold P bits)

          Montgomery ladder correctness (algebraic). Running ladderFold P on a list of bits (MSB first) produces a state (n · P, (n + 1) · P) where n = bitsToNat bits.

          theorem CatCrypt.Crypto.ECC.ladderFold_fst_eq_nsmul {G : Type u_1} [AddCommGroup G] (P : G) (bits : List Bool) :
          (ladderFold P bits).fst = bitsToNat bits P

          Corollary — scalar multiplication via ladder. The first component of ladderFold P bits equals (bitsToNat bits) • P. This is what the Montgomery ladder is supposed to compute.