Summary
This library provides implementations for a field of scalars, a group of elliptic curve points, and scalar multiplication operations over these mathematical structures. The set of scalars and the group are large enough to offer cryptographic security, and therefore require specialized efficient implementations.
In addition, the library allows bitstring conversions to and from these mathematical structures, as well as conversions between equivalent forms of the elliptic curve group. Each form (Edwards, Montgomery, Ristretto) offers specific computational advantages for cryptographic operations.
Applications
| Function |
|---|
add(s₁, s₂) |
sub(s₁, s₂) |
mul(s₁, s₂) |
neg(s) |
invert(s) |
| Function |
|---|
from_canonical_bytes(b) |
from_bits(b) |
to_bytes / as_bytes |
| Function |
|---|
from(x: u64) |
from_bytes_mod_order(b) |
from_bytes_mod_order_wide(b) |
| Function |
|---|
from_hash(h) |
random |
clamp_integer(b) |
| Function |
|---|
add(P, Q) |
sub(P, Q) |
neg(P) |
mul_by_cofactor(P) |
is_small_order(P) |
is_identity(P) |
| Function |
|---|
mul_base(s) |
vartime_double_scalar_mul_basepoint(a, A, b) |
random |
mul_base_clamped(b) |
| Function |
|---|
compress(P) |
AffinePoint::compress(P) |
decompress(b) |
to_bytes / as_bytes |
from_slice(b) |
| Function |
|---|
to_montgomery(P) |
AffinePoint::to_edwards(P) |
| Function |
|---|
mul_clamped(P, b) |
| Function |
|---|
to_edwards(P, sign) |
| Function |
|---|
to_bytes / as_bytes |
| Function |
|---|
add(P, Q) |
sub(P, Q) |
neg(P) |
mul(P, s) |
conditional_select(a, b, c) |
basepoint_mul(T, s) |
mul_base(s) |
vartime_double_scalar_mul_basepoint(a, A, b) |
double_and_compress_batch(Ps) |
RistrettoBasepointTable::create(P) |
RistrettoBasepointTable::basepoint |
vartime_multiscalar_mul(ss, Ps) |
| Function |
|---|
compress(P) |
decompress(b) |
to_bytes / as_bytes |
from_slice(b) |
| Function |
|---|
ct_eq(c₁, c₂) |
identity() |
| Function |
|---|
from_hash(h) |
from_uniform_bytes(b) |
random |
The Libsignal protocol stack reaches curve25519-dalek via three paths. 51 (TBD) functions are called directly; 7 (TBD) more are reached indirectly through the x25519-dalek and ed25519-dalek wrapper crates. Each protocol module consumes a distinct subset of operations.
| Source File | Direct | Indirect | Total | Primary Protocol | Dominant Consumer |
|---|---|---|---|---|---|
montgomery.rs | 1 | 3 | 4 | X25519 XEdDSA | x25519-dalek (DH), core (XEdDSA verify) |
edwards.rs | 12 | 2 | 14 | Ed25519 VRF | keytrans/vrf.rs, core/curve25519.rs |
ristretto.rs | 20 | 1 | 21 | zkgroup | zkgroup, zkcredential, poksho, svrb |
scalar.rs | 14 | 1 | 15 | Ed25519 zkgroup | universal (all crates) |
lizard_ristretto.rs | 2 | 0 | 2 | zkgroup | uid_struct.rs, uid_encryption.rs |
traits.rs | 2 | 0 | 2 | VRF zkgroup | keytrans/vrf.rs, endorsements.rs |
| Total | 51 | 7 | 58 | ||
Ed25519 signatures are the foundation of Signal’s identity and message authentication. The signing key is a Scalar (clamped); the verification key is a compressed Edwards point.
| Operation | Type | Key Call Sites |
|---|---|---|
| Sign (scalar mul) | Scalar × Edwards | ed25519-dalek → mul_base_clamped, from_bits |
| Verify ($[a]A + [b]B$) | Edwards | vartime_double_scalar_mul_basepoint |
| Hash-to-scalar | Scalar | from_bytes_mod_order_wide, from_hash |
| Key encoding | Edwards | compress, decompress, as_bytes, from_slice |
X25519 performs Diffie-Hellman on the Montgomery curve via the constant-time ladder. Private keys are clamped scalars; public keys are $u$-coordinates.
| Operation | Type | Key Call Sites |
|---|---|---|
| DH ($[s]P$) | Montgomery | x25519-dalek → mul_clamped |
| Clamping | Scalar | clamp_integer |
| Public key extract | Montgomery | as_bytes, to_bytes |
pub fn diffie_hellman(secret: &StaticSecret, public: &PublicKey) -> SharedSecret { // clamp_integer → MontgomeryPoint::mul_clamped → as_bytes }
XEdDSA allows signing with an X25519 private key by converting the Montgomery public key back to Edwards form. Used in Signal’s sealed sender and key verification.
| Operation | Type | Key Call Sites |
|---|---|---|
| Curve conversion | Montgomery → Edwards | to_edwards(sign) |
| Signature verify | Edwards | vartime_double_scalar_mul_basepoint |
| Cofactor check | Edwards | mul_by_cofactor, is_small_order, is_identity |
zkgroup uses the Ristretto group for anonymous credential issuance, presentation, and verification. Prime order eliminates cofactor issues in zero-knowledge proofs.
| Operation | Type | Key Call Sites |
|---|---|---|
| Pedersen commit | Ristretto | mul, add, sub, mul_base |
| Credential MAC | Ristretto | basepoint_mul, from_hash |
| Batch verify | Ristretto | vartime_multiscalar_mul, double_and_compress_batch |
| UID encoding | Ristretto | lizard_encode, lizard_decode |
| Wire format | Ristretto | compress, decompress, as_bytes, from_slice, ct_eq |
| Point construction | Ristretto | from_uniform_bytes, random, RistrettoBasepointTable::create |
Key Transparency uses VRF proofs over both Edwards and Ristretto points for verifiable pseudorandom evaluation.
| Operation | Type | Key Call Sites |
|---|---|---|
| VRF evaluate | Edwards & Ristretto | mul_base, vartime_double_scalar_mul_basepoint |
| Multi-scalar | Ristretto | vartime_multiscalar_mul |
| Scalar ops | Scalar | invert, mul, from_bytes_mod_order_wide |