Documentation

Cryptlib.Primitives.NIKE.X25519

X25519 as a group operation #

Scalar multiplication on Curve25519, using Mathlib's WeierstrassCurve.Affine.Point for the group law (y² = x³ + 486662x² + x is already in Weierstrass form). Public keys and shared secrets are 32-byte RFC 7748 u-coordinates; liftX recovers a point from a u-coordinate.

Axioms: p_prime and liftX_isSome_of_exists.

The base field #

2^255 - 19 is prime. Taken as an axiom.

The group #

def Cryptlib.Primitives.NIKE.X25519.curve :
WeierstrassCurve.Affine (ZMod X25519Common.p)

Curve25519 y² = x³ + 486662x² + x as a Weierstrass curve in affine coordinates.

Equations
Instances For
    @[reducible, inline]

    The points of Curve25519, including the point at infinity.

    Equations
    Instances For
      Equations
      Instances For

        Curve25519 is nonsingular, so the curve equation is the only condition for a point.

        Build a point from coordinates that pass the curve check.

        Equations
        Instances For

          The x-coordinate, 0 at infinity.

          Equations
          Instances For

            The basepoint #

            The y-coordinate of the standard basepoint x = 9, as a natural number.

            Equations
            Instances For

              Commutativity #

              The Diffie-Hellman identity.

              Encoding field elements #

              32 bytes, little-endian.

              A field element as 32 little-endian bytes.

              Equations
              Instances For

                Little-endian bytes back to a field element.

                Equations
                Instances For

                  Encoding points #

                  0x04 ‖ x ‖ y, or 65 zero bytes for the point at infinity.

                  Parse without checking that the encoding is canonical.

                  Equations
                  Instances For

                    Parse and reject non-canonical encodings (coordinates ≥ p).

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

                      RFC 7748 interface #

                      A u-coordinate is lifted to a point by square root: p ≡ 5 mod 8, so a root of a is a^((p+3)/8), possibly times √-1. The candidate is checked against the curve equation.

                      √-1 in ZMod p, i.e. 2^((p-1)/4).

                      Equations
                      Instances For

                        Recover a point from its u-coordinate, or none if u is on the quadratic twist.

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

                          liftX succeeds on every x-coordinate of a curve point. Taken as an axiom.

                          liftX preserves the x-coordinate.

                          The NIKE scheme #

                          Public keys and shared secrets are both x-coordinates in ZMod p.

                          The clamped scalar of a private key, as a natural number. Not reduced modulo p: clamped scalars can exceed p.

                          Equations
                          Instances For

                            An x-coordinate is safe when it lifts to a curve point.

                            Equations
                            Instances For

                              Recover the point a safe x-coordinate represents.

                              Equations
                              Instances For

                                toPoint returns a point with the given x-coordinate.

                                Every curve point's x-coordinate is safe.

                                32-byte little-endian decoding, rejecting values ≥ p.

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

                                  Commutativity of groupActionX #

                                  toPoint picks one of the points sharing an x-coordinate. The x-coordinate of a scalar multiple does not depend on which: the other point is the negation, or for x = 0 a point of order 2.

                                  Natural-number scalar multiplication commutes with negation.

                                  Scalar multiples of the identity are the identity.

                                  The finite point (0, 0), given it's on the curve.

                                  Equations
                                  Instances For

                                    The point (0, 0) is its own negative.

                                    theorem Cryptlib.Primitives.NIKE.X25519.nsmul_eq_zero_or_self {R : Point} (hRR : R + R = 0) (n : ℕ) :
                                    n • R = 0 ∨ n • R = R

                                    Every scalar multiple of a point R with R + R = 0 is 0 or R.

                                    theorem Cryptlib.Primitives.NIKE.X25519.xCoord_smul_zero {y : ZMod X25519Common.p} (h : curve.Nonsingular 0 y) (n : ℕ) :
                                    xCoord (n • WeierstrassCurve.Affine.Point.some 0 y h) = 0

                                    Scalar multiples of a point with x-coordinate 0 have x-coordinate 0.

                                    Points with equal x-coordinates have scalar multiples with equal x-coordinates.

                                    The Diffie-Hellman identity for groupActionX.

                                    groupActionX always returns a safe x-coordinate.

                                    theorem Cryptlib.Primitives.NIKE.X25519.groupActionX_comm (sk₁ sk₂ : X25519Common.PrivateKey) (x : ZMod X25519Common.p) (h : SafeX x) :
                                    groupActionX sk₁ (groupActionX sk₂ x h) ⋯ = groupActionX sk₂ (groupActionX sk₁ x h) ⋯

                                    Group actions by two private keys commute on any safe x-coordinate.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      def Cryptlib.Primitives.NIKE.X25519.x25519 (scalarBytes uCoordBytes : Vector UInt8 32) :

                                      RFC 7748 X25519, computed by scalar multiplication in the group. none when the input u-coordinate is not on the curve.

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