Curve building blocks
This crate provides X25519 and pure Ed25519 through fixed-size keys and borrowed messages. It has no SDK, IC call, persistence, clock or ambient entropy dependency. Callers own keys, prepared state, randomness and output buffers. See the preferred measured paths and dated best-pick report for installed qualification and exact workload boundaries. The X25519 optimization report records the selected field/inversion paths and compiled guarded-output checks.
X25519 accepts every 32-byte coordinate encoding specified by RFC 7748, including noncanonical representatives and high-bit aliases. Agreement rejects all-zero output in constant time. Importing private bytes is distinct from HPKE's labeled DeriveKeyPair operation. Every 32-byte secret input is mathematically valid; applications supply unpredictable entropy.
Ed25519 signs original message bytes with internal SHA-512. SigningKey caches
the public key while expanding the seed per signature. PreparedSigningKey
retains the expanded scalar, nonce prefix and bound public bytes. sign is the
stateless control including public derivation. Key state is private and owned;
signing follows upstream constant-time scalar arithmetic and owned secret state
uses zeroization on drop.
Strict single verification requires canonical A/R encodings, on-curve and
non-small-order points and S<L. It accepts mixed-order points and checks the
uncofactored equation. PreparedPublicKey retains a native width-five NAF table
for -A and uses the positive challenge scalar. This distinction preserves
mixed-order behavior. Comparing the decoded R with the computed projective point
avoids a final field inversion without weakening that equation.
The optional batch feature enables PrimeOrderBatch. Construction adds
exact prime-subgroup checks for both A and R, using a public-input point-halving
test. This is an explicit different admission policy; it never silently replaces
strict singles. Construction retains decoded A/R and canonical S in one owned
record array, so verification does not decode or parse them again. Every message
is hashed again. The shared upstream helper derives the same deterministic
coefficients from every ordered full SHA-512 H(R||A||M) digest and every S; no
record is omitted or coalesced. Verification allocates fresh transcript/MSM
scratch and returns one whole-batch result.
verify_affine is an experimental serial affine Pippenger control with an
explicit window 4..8. Freshly decoded points already have Z=1, allowing mixed
affine additions without normalization inversions. It includes digit/bucket
allocation and point preparation on every call. General projective inputs to
the underlying MSM are still normalized correctly.
verify_prime_order_batch_with_fallback constructs a fresh batch and fills every
per-record verdict. Aggregate success carries the ordinary transcript-derived
probabilistic soundness. Aggregate failure or a malformed/non-prime record
causes exact individual checks of all records under the same prime-order policy.
Sequential prepared verification remains available for strict singles' different
mixed-order policy.
Fresh prime-order cases perform canonical, curve, small-order and subgroup checks, message hashing and fresh transcript/MSM allocation within the call. Reused exact-batch cases are diagnostics. Record arrays, digest/coefficient storage and MSM backing are separate from allocator overhead, stack frames and actual page charges; use the artifact-specific qualification reports for those costs.
Source and backend variants
The opt-in wasm-simd128-verify feature adds strict verify_strict_simd128.
Four records use independent lanes of actual Wasm SIMD128 field arithmetic:
u32x4 radix25.5 limbs, exact unsigned widening products into two u64x2
accumulators, and the established serial32 carry schedule. Each input still
undergoes canonical A/R/S decoding, curve and small-order checks; every verdict
uses its own uncofactored equation and retains strict singles' mixed-order
policy. There is no aggregate equation or probabilistic acceptance.
Keys and messages arrive as borrowed VerificationItem records. Each call
constructs its temporary A tables and returns every Result<bool, Error>;
malformed records do not bypass their neighbors. Native hosts execute the same
formulas with checked scalar-vector arithmetic for correctness. The actual
SIMD implementation uses existing IC SIMD128 instructions and requires no
runtime or instruction-set extension. Signing and secret arithmetic dispatch
remain unchanged.
This four-record design differs from Dalek's x86 four-coordinate AVX2/AVX512
formulas. Native x86 target flags do not enable Wasm SIMD. Exact widening
products retain the high bits needed by the field arithmetic. Fixed groups
can still waste lanes on different sparse NAF digits; basepoint gathering,
carries, shuffles, loads, stores and page fees belong to the complete cost. The benchmark feature
ed25519-simd128 adds matched fresh scalar and SIMD cohort cases, with common
borrowed-descriptor allocation inside timing and all results checked afterward.
The earlier matched Wasm64 qualification preserves its
original fixed-group and dense-scheduler measurements. Current selections and
input/preparation/page boundaries are recorded in the preferred paths
and dated best-pick report.
The shared field source is in backend/serial/wasm_simd128; variable-time
point/table scheduling stays in edwards/simd128. The four-lane A table is
10,880 bytes plus NAF and arithmetic temporaries. Existing scalar basepoint
constants are gathered at use; no extra generator table is installed.
SIMD128-SOURCE.json records the primary Dalek/HWCD sources, bounds, adaptation
limits and binary-matched IC cost-table provenance.
verify_strict_simd128_dense is the separate 0..500-record scheduling control.
At each bit it completes every doubling, packs nonzero A jobs into groups of
four distinct record IDs, completes them, then does the same for B. All adds
finish before the next bit begins. Completed coordinates remain in groups of
four records in limb-major state, so the all-record doubling pass loads and
stores complete SIMD groups without transposing separate records on every bit.
Sparse A/B additions still gather distinct record IDs and scatter only those
results. The equation, phase barriers and partial-group identities are unchanged.
Its strict-fresh.simd128-dense case includes heap table construction and freeing
inside timing. The workspace factory creates Vec backings directly on the heap.
Dense storage includes grouped completed-point state, per-record A tables and NAFs, job IDs, parsed equations and final points. Tail groups include identity padding. Caller verdicts, allocator metadata and stack frames are additional; array backing alone does not determine live memory or page charges. The fixed-four control instead uses a bounded stack table per four records.
The frozen Wycheproof source receipt pins 210 independent test cases. The native suite executes all 198 fixed-size records through both SIMD controls; the 12 wrong-length signatures reject at the typed-input boundary. Valid and invalid verdicts follow the source expectations. Acceptable cases must match the existing strict verifier exactly. No parser or acceptance policy is changed to accommodate a vector.
The copied prepared forks pin curve25519-dalek 4.1.3 and ed25519-dalek 2.2.0, with
BSD-3-Clause licenses. vendor/*/upstream-source.json, exact.patch and
PORT-SOURCE.json retain published/copy provenance. NEWSTACK.json and
newstack.patch record additional local edits. The workspace markers were removed
to embed these packages. No upstream secret-scalar formula was changed.
The layered ED-BATCH.json/ed-batch.patch receipts record the subsequent
public-input batch changes. The exact subgroup test is adapted from Thomas
Pornin's crrl implementation
of Point-Halving and Subgroup Membership in Twisted Edwards Curves.
HALVING-SOURCE.json pins the author source and the sqrt convention adaptation;
LICENSE-CRRL retains its MIT notice. The direct paper PDF was inaccessible
during this work; source review used the author's pinned implementation.
These pins are historical optimization references, not the latest releases.
As checked on 2026-10-25, the latest stable curve/x25519/ed25519 Dalek versions
were 5.0.0/3.0.0/3.0.0. x25519-dalek 2.0.1 is the matching pinned X25519 dependency.
Its vendored manifest binds the sibling prepared curve package directly, so an
external consuming application does not need a root Cargo patch. The wrapper's
NEWSTACK.json records its published archive, file hashes and manifest-only edit.
Wasm64 defaults to the previously measured serial32 selection, while explicit word-size and backend overrides remain effective. Choose an explicit pair of build cfg values for matched comparisons:
| Variant | curve25519_dalek_backend |
curve25519_dalek_bits |
|---|---|---|
| serial32 | serial |
32 |
| serial64 | serial |
64 |
| fiat32 | fiat |
32 |
| fiat64 | fiat |
64 |
For example, Cargo rustflags include
--cfg curve25519_dalek_backend="serial" --cfg curve25519_dalek_bits="32".
Use the canonical builder's configuration rather than assuming a shell override
survives it. Capture the effective dependency build-script output for each
artifact. The pointer target and limb word size are independent. Upstream SIMD
backends are Intel-specific and cannot be selected as Wasm SIMD.
The mutually exclusive Cargo features dalek-serial32, dalek-serial64,
dalek-fiat32 and dalek-fiat64 select those same established backends in
this crate and are forwarded by the benchmark cases and canister. Pass one
feature through the canonical builder's --features option to compare the
same Wasm64 workload without changing global rustflags or the SDK/standard
library build identity. Conflicting feature selections or contradictory explicit
cfg values fail the build. With no feature, backend selection is unchanged.
Fiat features activate the existing locked Fiat dependency directly; dependency
resolution does not rely on a cfg emitted later by the build script.
The x25519.dh.one-local-key.fresh-call.* benchmark pair imports one local
secret and allocates/initializes its output and validity buffers inside every
measured invocation. The inversion variant also allocates/initializes and
clears its scratch there. Distinct input mode supplies separate peer coordinates;
every record still executes a complete clamped ladder and all-zero rejection.
x25519-inline-select is a separate code-generation experiment. It forces the
existing Montgomery projective selector to inline so the optimizer can see both
halves of the default constant-time swap together. It changes no arithmetic or
lookup and is disabled by default. Compare it separately on the same backend;
the native vectors establish correctness, not an IC instruction saving.
Experimental shared inversion
experimental-batch-inversion adds SecretKey::agree_batch_experimental.
Each input still executes the existing clamped Montgomery ladder. Only its
projective-to-affine conversion is postponed. A constant-time prefix/reverse
product calculation shares one final inversion, skipping zero denominators
with masks. There is no scalar combination, allocation or replacement ladder.
The caller supplies one initialized BatchScratch per item plus outputs and
validity flags. Scratch is cleared before return; zero-DH items return false
and zero output without invalidating their neighbors. Bounds failures occur
before modifying buffers. Scratch contains secret-derived state during a call
and must remain private and synchronous. This scalar batching control and the
selected SIMD path have separate measured contracts in the preferred paths.
Fixed-size tiles can bound the scratch footprint.
The same feature also exposes public_keys_batch_experimental and
agree_batch_independent_experimental. The first retains the existing
constant-time Edwards fixed-base multiplication and shares only the final
(Z+Y)/(Z-Y) map inversion. The second accepts independent local-secret/peer
pairs and checks each resulting DH value separately. Its synchronous consumer
receives every result in reverse index order. Both use the same caller-owned
scratch, perform no allocation and preserve RFC 7748 encoding acceptance.
These are explicit experiments; ordinary APIs retain their scalar paths.
public_keys_from_bytes_batch_experimental accepts borrowed raw private bytes
without an intermediate array of secret-key objects. It imports and clamps each
scalar within the call, using the same fixed-base operation and caller-owned
scratch. Callers retain responsibility for the original private input bytes.
Validation scope
Native tests include RFC 7748 agreement and iteration answers, all five pure
RFC 8032 examples, independent OpenSSL signatures, SHA-512 prefix boundaries,
mixed-order/cofactor-only cases, prepared parity, strict errors and batch policy.
Batch tests cover all eight torsion classes against multiplication by the group
order, arbitrary/mixed-order affine MSMs at 0..1001 terms, all 100 record
positions, opposite-S cancellation attempts and complete failure fallback at
1/8/32/100/128/500 records.
tests/fixture-source.json identifies the frozen independent vector sources.
The inversion experiment compares every output with scalar multiplication,
including mixed valid/zero-denominator cohorts. Run each supported backend and
both Wasm targets before making target-specific claims. These tests and prior
source reviews are not an external cryptographic audit or new performance
qualification.
Current combined vendor source is verified by the tracked replay tool:
python3 cdk-rsx/crates/crypto/curves/tools/replay-vendor-layers.py
It verifies original import hashes, ordered immutable patches and current
compiled/supporting file hashes. The original source checkouts referenced by
the frozen import receipts must be available at their recorded paths; an ordinary
clone does not provision these external source checkouts. Patch application uses
an isolated temporary Git repository,
keeping paths independent of the outer workspace.
curve25519-dalek/COMBINED.json and
ed25519-dalek/COMBINED.json define the combined state; dated source
receipts retain their original experiment pins.