Elliptic arithmetic notes / 09

Standard curves and parameters

A named parameter set fixes the field, curve equation, base point, and subgroup order. The implementation chooses internal coordinates; the protocol specifies encodings and validation rules.

Named parameter sets allow libraries to specialize reduction and point formulas while retaining fixed, testable constants.

P-256-style short Weierstrass curves

NIST P-256 uses a prime field and a short-Weierstrass equation with \(a=-3\). The \(a=-3\) shape supports the efficient Jacobian doubling formula described earlier. Its generalized Mersenne prime supports specialized reduction through a sparse relation for \(2^{256}\) modulo \(p\).

typedef struct { uint32_t v[8]; } fe256_t;

static const fe256_t p256_p = { .v = {
    0xffffffffu, 0xffffffffu, 0xffffffffu, 0x00000000u,
    0x00000000u, 0x00000000u, 0x00000001u, 0xffffffffu
}};

static const fe256_t p256_b = { .v = {
    0x27d2604bu, 0x3bce3c3eu, 0xcc53b0f6u, 0x651d06b0u,
    0x769886bcu, 0xb3ebbd55u, 0xaa3a93e7u, 0x5ac635d8u
}};

static const fe256_t p256_gx = { .v = {
    0xd898c296u, 0xf4a13945u, 0x2deb33a0u, 0x77037d81u,
    0x63a440f2u, 0xf8bce6e5u, 0xe12c4247u, 0x6b17d1f2u
}};

static const fe256_t p256_gy = { .v = {
    0x37bf51f5u, 0xcbb64068u, 0x6b315eceu, 0x2bce3357u,
    0x7c0f9e16u, 0x8ee7eb4au, 0xfe1a7f9bu, 0x4fe342e2u
}};

static const uint32_t p256_n[8] = {
    0xfc632551u, 0xf3b9cac2u, 0xa7179e84u, 0xbce6faadu,
    0xffffffffu, 0xffffffffu, 0x00000000u, 0xffffffffu
};

These arrays store ordinary integers in little-endian 32-bit words. Although p256_p reuses the storage struct, it holds the modulus rather than a canonical field element. The coefficients and base-point coordinates are ordinary residues; a field layer using Montgomery encoding converts them before point arithmetic. Reconstructing each integer from its limbs and comparing it with the specified parameter detects transcription and ordering errors.

secp256k1

secp256k1 uses

\[y^2=x^3+7\]

over \(p=2^{256}-2^{32}-977\). Here \(a=0\), so the \(a=-3\) doubling shortcut does not apply. The curve has efficiently computable endomorphism structure, but using it safely requires scalar decomposition and additional side-channel review.

Curve25519 contrast

X25519 uses the Montgomery model of Curve25519 and an x-coordinate ladder. Its scalar decoding and input rules are specified by RFC 7748, Section 5, including acceptance and reduction of noncanonical coordinate encodings. Those rules belong to X25519 and differ from the SEC 1 validation procedure for the short-Weierstrass examples here.

SageMath parameter generation

def words(x, n=8):
    return [hex((Integer(x) >> (32*i)) & 0xffffffff) for i in range(n)]

p = 2^256 - 2^224 + 2^192 + 2^96 - 1
n = Integer("ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", 16)
b = Integer("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", 16)
gx = Integer("6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296", 16)
gy = Integer("4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5", 16)
F = GF(p)
E = EllipticCurve(F, [F(-3), F(b)])
print(E.discriminant() != 0)
print(E(F(gx), F(gy)) in E)
print(words(p))
print(words(n))

Two implementation lessons

For P-256, the field prime and \(a=-3\) shape encourage a specialized reducer and specialized doubling. For secp256k1, the prime supports reduction by folding high bits, but the curve equation changes the point-formula schedule.

For a minimal library, fixing one named curve fixes the reduction constants, point-formula hypotheses, and validation rules. A runtime-selectable curve interface must establish those same contracts for each accepted parameter set.