Elliptic arithmetic notes / 00

Roadmap for a C curve library

An elliptic-curve library builds field arithmetic from machine words, represents points by field coordinates, and computes scalar multiples through point addition and doubling. Protocols specify how those operations are used and validated.

These notes continue the bignum arithmetic series. The bignum layer defines 32-bit words, radix \(B=2^{32}\), half-word product decomposition, Montgomery reduction, canonicalization, and constant-time C idioms. The elliptic layer uses that substrate to implement the group law on a curve over a finite field.

The reference text is Hankerson, Menezes, and Vanstone, Guide to Elliptic Curve Cryptography: finite-field arithmetic in Chapter 2, point formulas and scalar multiplication in Chapter 3, domain-parameter and protocol checks in Chapter 4, and implementation/security issues in Chapter 5.

Reference map

Source material Covered here Bignum dependency
Chapter 2, prime-field arithmetic, reduction, inversion Articles 01, 05, 09, 11 Montgomery arithmetic, prime fields
Chapter 3.1, curve equations, group law, order, group structure Articles 01, 02, 08 fixed-width field operations and canonical comparison
Chapter 3.2, projective/Jacobian coordinates and operation counts Articles 03, 04 field multiplication, squaring, inversion avoidance
Chapter 3.3, binary, NAF, window, fixed-base scalar multiplication Articles 06, 07, 12 constant-time tables and limb-level selects
Chapter 4.2-4.3, domain parameters, public-key validation Articles 08, 09, 10 modular arithmetic for subgroup/order checks
Chapter 4.4-4.6, ECDSA, ECIES, ECDH-style needs Article 10 scalar arithmetic and point multiplication
Chapter 5.1 and 5.3, software and secure implementation Articles 05, 07, 12 C undefined behavior, timing discipline, testing

The C library target is a short-Weierstrass curve over a prime field. The reference book also treats binary fields and Koblitz curves, which require different field operations and scalar-multiplication techniques.

Library boundary

For a fixed curve over \(\mathbb F_p\) with \(p>3\),

\[E: y^2=x^3+ax+b,\qquad 4a^3+27b^2\ne 0 \pmod p,\]

the arithmetic layer should expose:

  1. field operations on canonical or explicitly lazy residues;
  2. affine and Jacobian point representations;
  3. point validation and subgroup-related checks for public data;
  4. scalar multiplication routines whose control flow, memory addresses, and instruction timing satisfy the stated leakage contract for secret scalars and intermediate points.

The protocol layer determines nonce generation, transcript binding, key derivation, signature encoding, and invalid-input handling. It calls the arithmetic layer with the input and leakage contracts required by each protocol step.

Two concrete running examples

Toy curve for exact inspection. Over \(\mathbb F_{17}\), the curve

\[E: y^2=x^3+2x+2\]

is nonsingular because \(4\cdot 2^3+27\cdot 2^2=140\equiv 4\pmod {17}\). This curve has 19 points, so it illustrates infinity and inverse pairs but has no nonidentity point with \(y=0\): such a point would have order 2. Article 04 uses a second toy curve with a point of order 2 to test that doubling case.

Implementation-scale prime. The teaching and implementation-test model for P-256 represents a 256-bit field element as eight little-endian uint32_t words with \(B=2^{32}\). Every 32-by-32 product is decomposed into 16-bit partial products before carry propagation. The elliptic formulas see only the field API, but the field proof must match this word representation.

SageMath as oracle

SageMath supplies exact algebra and test vectors. Word-size bounds establish that the C operations realize those values; compiler and trace checks establish the intended leakage behavior.

p = 17
F = GF(p)
E = EllipticCurve(F, [2, 2])
P = E(5, 1)
print(E.discriminant() != 0)
print(2*P)
print(19*P == 0*P)

Article route

Articles Purpose
01-02 Prime fields, curve equations, affine points, and the group law.
03-04 Projective/Jacobian representation and point formulas suitable for C.
05-07 Field API boundaries, scalar multiplication, and side-channel discipline.
08-10 Validation, standard parameters, and protocol arithmetic needs.
11-12 SageMath testing and a minimal C library layout.