An implementation of Ristretto, which provides a prime-order group.
Ristretto is a modification of Mike Hamburg's Decaf scheme to work with cofactor-\(8\) curves, such as Curve25519.
The introduction of the Decaf paper, Decaf: Eliminating cofactors through point compression, notes that while most cryptographic systems require a group of prime order, most concrete implementations using elliptic curve groups fall short – they either provide a group of prime order, but with incomplete or variable-time addition formulae (for instance, most Weierstrass models), or else they provide a fast and safe implementation of a group whose order is not quite a prime \(q\), but \(hq\) for a small cofactor \(h\) (for instance, Edwards curves, which have cofactor at least \(4\)).
This abstraction mismatch is commonly “handled” by pushing the complexity upwards, adding ad-hoc protocol modifications. But these modifications require careful analysis and are a recurring source of vulnerabilities and design complications.
Instead, Decaf (and Ristretto) use a quotient group to implement a prime-order group using a non-prime-order curve. This provides the correct abstraction for cryptographic systems, while retaining the speed and safety benefits of an Edwards curve.
Decaf is named “after the procedure which divides the effect of coffee by \(4\)”. However, Curve25519 has a cofactor of \(8\). To eliminate its cofactor, Ristretto restricts further; this additional restriction gives the Ristretto encoding.
More details on why Ristretto is necessary can be found in the Why Ristretto? section of the Ristretto website.
points are provided in
curve25519-dalek by the
Encoding is done by converting to and from a
struct, which is a typed wrapper around
The encoding is not batchable, but it is possible to
double-and-encode in a batch using
Testing equality of points on an Edwards curve in projective coordinates requires an expensive inversion. By contrast, equality checking in the Ristretto group can be done in projective coordinates without requiring an inversion, so it is much faster.
RistrettoPoint struct implements the
subtle::ConstantTimeEq trait for constant-time equality
checking, and the Rust
Eq trait for variable-time equality
Scalars are represented by the
Scalar struct. Each scalar has a
canonical representative mod the group order. To attempt to load
a supposedly-canonical scalar, use
Scalar::from_canonical_bytes(). To check whether a
representative is canonical, use
Scalar multiplication on Ristretto points is provided by:
*operator between a
RistrettoPoint, which performs constant-time variable-base scalar multiplication;
*operator between a
RistrettoBasepointTable, which performs constant-time fixed-base scalar multiplication;
an implementation of the
MultiscalarMultrait for constant-time variable-base multiscalar multiplication;
an implementation of the
VartimeMultiscalarMultrait for variable-time variable-base multiscalar multiplication;
The Ristretto group comes equipped with an Elligator map. This is used to implement
RistrettoPoint::random(), which generates random points from an RNG;
RistrettoPoint::hash_from_bytes(), which perform hashing to the group.
The Elligator map itself is not currently exposed.
The Decaf suggestion is to use a quotient group, such as \(\mathcal E / \mathcal E\) or \(2 \mathcal E / \mathcal E \), to implement a prime-order group using a non-prime-order curve.
This requires only changing
- the function for equality checking (so that two representatives of the same coset are considered equal);
- the function for encoding (so that two representatives of the same coset are encoded as identical bitstrings);
- the function for decoding (so that only the canonical encoding of a coset is accepted).
Internally, each coset is represented by a curve point; two points \( P, Q \) may represent the same coset in the same way that two points with different \(X,Y,Z\) coordinates may represent the same point. The group operations are carried out with no overhead using Edwards formulas.
Notes on the details of the encoding can be found in the Details section of the Ristretto website.
A Ristretto point, in compressed wire format.
A precomputed table of multiples of a basepoint, used to accelerate scalar multiplication.
Precomputation for variable-time multiscalar multiplication with