Module
std.x.crypto.curve25519 — X25519 key exchange (RFC 7748) and Ed25519 signatures (RFC 8032) over the shared field 2^255 - 19. Stability tier: x — the D53 crypto ladder's THIRD rung (campaign stdc-crypto, sprint sc18). Chosen before Weierstrass P-256 because both curves share one field, are specified in implementation-grade detail in their RFCs. X25519's source-level Montgomery ladder swap is arithmetic selection, with no secret-indexed tables. Source shape is not a fixed-time certification of generated code or runtime calls; review the exact backend/runtime pins separately. Ed25519 signing has the secret-bit branch documented below. P-256's hardened ladder is a named D-question for the rung that proves ACME demands it; the pinned local test CA speaks Ed25519.
The nursery banner (D31). std.x.crypto.curve25519 is not std.crypto: its path, names and behaviour may change or vanish in one sprint; no other std module may depend on it. Its reason and graduation trigger live in std/x/README.md. Ed25519's SHA-512 is std.x.crypto.sha2's, called through the module boundary — a resident MAY depend on the facade, and sha2 is a sibling resident, so the dependency is a resident-on-resident one that the graduation move must resolve (named in the register): until std.crypto exists the two ride together.
**The field is 255-bit, in ten checked-int limbs of ~25.5 bits** (the sc18 probe delta's verdict). The naive 51-bit x 5 packing overflows: one 51x51 product is 102 bits, past every wolf integer type, and a multiply column sums five of them times up to 38 — so RFC 7748's own reference uses 25/26-bit limbs and so does this. The ten limbs alternate 26 and 25 bits; a carried limb is < 2^26, one product < 2^52, and the heaviest multiply column measures 2^58.96 — 16.4x under int_max (2^63 - 1), which X3's checked arithmetic enforces at every operation (a violated bound is a trap the vectors catch, never a silent wrap). The carry discipline: every add, sub, multiply and squaring ends in a two-pass fe_carry that folds the 2^255 overflow back times 19 and leaves each limb in range, so every value entering a multiply is carried. NO wrapping[T] anywhere in the field — it is all checked int, three-lane at the sc18 pin.
The scalar field mod L (the group order, 2^252 + 27742317777372353535851937790883648493) rides as ten 26-bit int limbs with its own Barrett-free reduction (fold the top limbs times C = L - 2^252, MSB-down, then two conditional subtractions); Ed25519's s = r + k*a mod L and the SHA-512 hash reductions use it. Same checked-int discipline, same bound proof (the heaviest signed column measures 2^52.8).
X25519's ladder is the Montgomery ladder with an ARITHMETIC cswap (fe_cswap) — the secret scalar bit enters only as a multiplier, never a branch, and that function is c28's cswap VERIFICATION TARGET (D53), marked in its header. Clamping is RFC 7748 s5 verbatim. A zero shared secret (small-order public key) raises the zero row: RFC 8446 s7.4.2 requires a TLS 1.3 endpoint to abort rather than use it, and Wycheproof's ZeroSharedSecret cases are answered that way.
Ed25519 SIGNING is deterministic (RFC 8032 s5.1.6): the nonce is SHA-512(prefix || message) reduced mod L, where prefix is the second half of the secret's hash — NO entropy is drawn, and the entropy D-question stays parked with the rung that needs it. VERIFY is cofactorless (RFC 8032 s5.1.7's group equation [S]B = R + [k]A, no multiply-by-8), with S < L enforced strictly and decompression's sign bit per s5.1.3 — the choices Wycheproof's malleability cases decide, pinned here. Like the RFC, verify accepts an A or R of small order ([8]P is the identity). **verify_strict** (sc77) is verify plus the refusal of both, for a caller whose policy must refuse small-order keys and commitments; a mixed-order point is a named follow-on (it needs [L]P).
Constant-time (D53's retrofit clause). SIGNING handles the secret scalar; its ladder-free scalar multiplication (sc_mul_base, a fixed double-and-add over the SECRET nonce/scalar) and fe_cswap carry the ct: obligations. VERIFY is PUBLIC-DATA — a verification key and a signature are public, so verify, verify_strict and their point arithmetic have no secret to protect and say so. The one recorded ct exception — the 0..255 ingestion guard, which branched on every input byte — is RETIRED (sc35); to_hex is not constant-time and says so. c28's tier does not exist yet; every pub fn carries a ct: line until it does.
**Byte sequences are List[byte] (sc35).** They were List[int] with a documented 0..255 element contract (F-0035) that this module enforced with a require_byte on every ingested element; D72/s135's byte and s136's byte-typed builtins (wolf-lang#231) make that the TYPE's contract, so the guard is deleted and verify's two range-checking loops with it — a scalar, a u-coordinate, a key, a signature and a message are all List[byte] and cannot carry a non-byte. to_hex is this module's own rendering (the sha2/chacha20 precedent), std.hex.encode the facade spelling.
No division (sc84, wolf-std#151). Nothing in this module divides. At wolf 0.2.39 the x86-64 release ladder compiled its scalar-bit extraction (kb / pow2(t % 8) % 2) to a hardware div of the secret scalar byte on each of its 255 steps, and every default build divided the field's limbs in fe_carry, fe_freeze and fe_tobytes, the clamp, the ladder, and signing's scalar reduction. The scalar bit is now a shift of the byte by its public position on a wrapping[u64] word (scalar_bit); the field's carries and byte seams are literal shifts and masks on limbs the bound proofs keep non-negative, where they equal / and %; signing's signed carries are floor shifts ([type.int.shift]). cargo xtask codegen builds this module's default and release objects on the host target and fails on any integer division instruction in them, and runs the RFC 7748 rows, the 1000-iteration chain among them, and RFC 8032 §7.1 in the release tier. What it does not change: Ed25519 signing still gates the add of its double-and-add on each secret bit (a branch; the fixed-sequence version is a named follow-on), and to_hex indexes by value. It is not a timing measurement (no latency was measured on any CPU), it says nothing about the interpreters, and the compiler that makes the objects is not audited; a target the gate is not run on is not covered by it.
Functions and methods
fn · Source line 952
pub fn x25519(scalar: List[byte], u_bytes: List[byte]) -> List[byte] ! {zero}
X25519 (RFC 7748 s5): the Diffie-Hellman scalar multiplication on Curve25519. scalar and u_bytes are 32-byte little-endian sequences; the scalar is clamped per s5 and the u-coordinate's top bit masked. Returns the 32-byte shared secret UNLESS it is all-zero, in which case it raises zero: a zero output means the public key was a small-order point, and RFC 8446 s7.4.2 requires a TLS 1.3 endpoint to ABORT rather than proceed with a shared secret it knows the peer can predict. Wycheproof's ZeroSharedSecret cases are exactly this, and this row is how the module answers them. Traps assert on a scalar or u-coordinate that is not 32 bytes (a caller contract violation); a non-byte element is a type error since sc35. ct: the ladder and cswap have fixed source-level schedules (see their headers). The shared secret is CONFIDENTIAL, including at the zero check; its bytes are OR-folded without a per-byte branch. Only the final zero/nonzero verdict is disclosed. This is not a fixed-time certification of compiled code or of any interpreter/runtime tier. Do not log or hex-render a real shared secret; examples use test keys.
Diffie-Hellman — two parties reach the same shared secret. This example imports one module (§4), so it builds keys from strings; the RFC 7748 §5.2/§6.1 byte vectors live in the test files.
let a = "alice's own 32-byte x25519 key!!".bytes()
let b = "bob's different 32-byte x25519 k".bytes()
let dh_a = curve25519.x25519(a, curve25519.x25519_base(b)) else List[byte]()
let dh_b = curve25519.x25519(b, curve25519.x25519_base(a)) else List[byte]()
curve25519.to_hex(dh_a) == curve25519.to_hex(dh_b)
fn · Source line 988
pub fn x25519_base(scalar: List[byte]) -> List[byte]
X25519 against the standard base point u = 9 (RFC 7748 s6.1's key generation: the public key for a private scalar). A base-point multiplication never yields the zero secret, so this one is total over its byte contract. ct: as x25519.
let sk = "a 32-byte curve25519 secret key!".bytes()
curve25519.x25519_base(sk).len == 32
fn · Source line 1480
pub fn public(secret: List[byte]) -> List[byte]
The Ed25519 public key for a 32-byte secret (RFC 8032 §5.1.5): A = [a]B compressed, where a is the clamped scalar. Traps assert on a secret that is not 32 bytes (sc35: a non-byte element is a type error). ct: SECRET scalar a drives the double-and-add — the bit test is the recorded ct obligation (module header); the derived public key is public.
let sk = "a 32-byte ed25519 secret key !!!".bytes()
curve25519.public(sk).len == 32
fn · Source line 1506
pub fn sign(secret: List[byte], message: List[byte]) -> List[byte]
Ed25519 signature over message under a 32-byte secret (RFC 8032 §5.1.6). Deterministic: the nonce r = SHA-512(prefix || message) mod L draws NO entropy (the entropy D-question stays parked). Returns the 64-byte R || s. Traps assert on a secret that is not 32 bytes (sc35: a non-byte element is a type error); the message is arbitrary bytes. ct: THE SECRET PATH. The secret drives SHA-512, the clamped scalar, two base multiplications and sc_muladd; the double-and-add's bit-gated add is the recorded ct obligation c28 will verify (the honest constant-time scalarmul is a named follow-on; the scalar reduction's sign-correction branch left with its division in sc84). No randomness, so no nonce-reuse hazard exists.
let sk = "a 32-byte ed25519 secret key !!!".bytes()
let msg = "sign me".bytes()
let sig = curve25519.sign(sk, msg)
sig.len == 64
curve25519.verify(curve25519.public(sk), msg, sig)
fn · Source line 1547
pub fn verify(pubkey: List[byte], message: List[byte], sig: List[byte]) -> bool
Verify an Ed25519 signature (RFC 8032 §5.1.7), COFACTORLESS: the group equation [S]B = R + [k]A holds with no multiply-by-8, S is rejected unless S < L (strict — the malleability check Wycheproof's cases patrol), and both A and R must decompress canonically. Returns true iff the signature is valid; a wrong length, a non-canonical encoding, S >= L, or a failed equation all answer false — no trap, because a signature and a key are the CALLER'S data to check, not a contract they promised (§2's rule: verify answers a bool, it does not trap on a bad signature). Small-order points are accepted, as RFC 8032 allows: nothing here refuses an A or R whose [8]P is the identity. With A = the encoded identity (01 then 31 zero bytes) and R || S = that identity then 32 zero bytes, this answers true for every message. A caller whose policy must refuse small-order keys and commitments calls verify_strict, which checks everything this function checks and that as well; on honestly generated keys and signatures the two agree. ct: VERIFY IS PUBLIC DATA — the key, the signature and the message are all public, so the branches here protect no secret and this function carries no constant-time obligation (stated in the module header).
let sk = "a 32-byte ed25519 secret key !!!".bytes()
let msg = "verify me".bytes()
let sig = curve25519.sign(sk, msg)
curve25519.verify(curve25519.public(sk), msg, sig)
fn · Source line 1605
pub fn verify_strict(pubkey: List[byte], message: List[byte], sig: List[byte]) -> bool
Verify an Ed25519 signature STRICTLY: everything verify checks (the lengths, S < L, canonical decompression of A and R, and RFC 8032 §5.1.7's cofactorless equation [S]B = R + [k]A), and also false when the public key A or the commitment R has small order, meaning [8]A or [8]R is the identity. Those are the eight points of the cofactor subgroup. RFC 8032 accepts them, and verify does too: with A = the encoded identity (01 then 31 zero bytes) and R || S = that identity then 32 zero bytes, verify answers true for every message. Call this function when a policy must refuse small-order keys and commitments. No honestly generated key or signature has small order, so the two functions agree on every one of them. A mixed-order A or R (a prime-order point plus a nonzero small-order one) is NOT refused: that needs [L]P, a further scalar multiplication per point (docs/sc77-the-strict-verify.md measures it). Returns true iff the signature is valid under these rules, and never traps on the caller's data (§2's rule, as for verify). ct: VERIFY IS PUBLIC DATA — the key, the signature and the message are all public, so the branches here, the small-order tests included, protect no secret and this function carries no constant-time obligation (stated in the module header).
var pk = List[byte]()
(mut pk).push(1 as byte)
for i in 0..31 { (mut pk).push(0 as byte) }
var sig = List[byte]()
(mut sig).push(1 as byte)
for i in 0..63 { (mut sig).push(0 as byte) }
curve25519.verify(pk, "any message".bytes(), sig) == true
curve25519.verify_strict(pk, "any message".bytes(), sig) == false
fn · Source line 1686
pub fn field_self_test() -> bool
The field's algebraic identities, checked ALONE (RFC 7748 §5's arithmetic, before any ladder observes it). Returns true iff every one holds: additive inverse, commutativity and associativity of multiply, the distributive law, squaring as self-multiply, the Fermat inverse (a·a⁻¹ = 1), the a24 constant multiply, and the byte round trip (decode∘encode is the identity on a canonical value). Total, three-lane. ct: a test predicate over public constants; no secret.
curve25519.field_self_test()
fn · Source line 1757
pub fn to_hex(b: List[byte]) -> str
b as lowercase hexadecimal, two digits per byte — this module's own rendering so its tests and examples import exactly one module (the sha2/chacha20 precedent); std.hex.encode is the facade spelling. Total — the non-byte element it used to trap on is a type error since sc35. ct: NOT constant-time — the alphabet slice is indexed by each byte's VALUE. Render only public keys, signatures or LABELLED test vectors. Private scalars and shared secrets remain confidential after computation; never log them. This renderer offers no fixed-time guarantee.
curve25519.to_hex("abc".bytes()) == "616263"
curve25519.to_hex(List[byte]()) == ""