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 #
Curve25519 y² = x³ + 486662x² + x as a Weierstrass curve in affine coordinates.
Equations
- Cryptlib.Primitives.NIKE.X25519.curve = { a₁ := 0, a₂ := 486662, a₃ := 0, a₄ := 1, a₆ := 0 }
Instances For
The points of Curve25519, including the point at infinity.
Instances For
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
- Cryptlib.Primitives.NIKE.X25519.mkPoint h = WeierstrassCurve.Affine.Point.some x y ⋯
Instances For
The x-coordinate, 0 at infinity.
Equations
- Cryptlib.Primitives.NIKE.X25519.xCoord WeierstrassCurve.Affine.Point.zero = 0
- Cryptlib.Primitives.NIKE.X25519.xCoord (WeierstrassCurve.Affine.Point.some x_1 y h) = x_1
Instances For
The basepoint #
The y-coordinate of the standard basepoint x = 9, as a natural number.
Equations
- Cryptlib.Primitives.NIKE.X25519.basepointYNat = 14781619447589544791020593568409986887264606134616475288964881837755586237401
Instances For
The y-coordinate of the standard basepoint x = 9.
Equations
Instances For
The standard basepoint of X25519, as a group element.
Equations
Instances For
Commutativity #
Encoding field elements #
32 bytes, little-endian.
A field element as 32 little-endian bytes.
Equations
- Cryptlib.Primitives.NIKE.X25519.encodeField z = List.map UInt8.ofNat (Nat.digits 256 z.val ++ List.replicate (32 - (Nat.digits 256 z.val).length) 0)
Instances For
Little-endian bytes back to a field element.
Equations
- Cryptlib.Primitives.NIKE.X25519.decodeField bs = ↑(Nat.ofDigits 256 (List.map UInt8.toNat bs))
Instances For
Encoding points #
0x04 ‖ x ‖ y, or 65 zero bytes for the point at infinity.
Equations
- Cryptlib.Primitives.NIKE.X25519.encodePoint WeierstrassCurve.Affine.Point.zero = 0 :: List.replicate 64 0
- Cryptlib.Primitives.NIKE.X25519.encodePoint (WeierstrassCurve.Affine.Point.some x_1 y h) = 4 :: (Cryptlib.Primitives.NIKE.X25519.encodeField x_1 ++ Cryptlib.Primitives.NIKE.X25519.encodeField y)
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
- Cryptlib.Primitives.NIKE.X25519.sqrtMinusOne = ↑19681161376707505956807079304988542015446066515923890162744021073123829784752
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.
Equations
Instances For
Equations
Instances For
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
Equations
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.
Scalar multiples of the identity are the identity.
The finite point (0, 0), given it's on the curve.
Equations
- Cryptlib.Primitives.NIKE.X25519.zeroZeroPoint h = WeierstrassCurve.Affine.Point.some 0 0 h
Instances For
The point (0, 0) is its own negative.
Scalar multiples of a point with x-coordinate 0 have x-coordinate 0.
The Diffie-Hellman identity for groupActionX.
groupActionX always returns a safe x-coordinate.
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
A u-coordinate as 32 little-endian bytes.
Equations
Instances For
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.