Ed25519
zisklib functions for Ed25519 (edwards25519): base field arithmetic,
point addition, compression and decompression, double scalar
multiplication with the base point, scalar reduction mod L, and
RFC 8032 signature verification.
Ed25519 support was added in 1.4.0-alpha (#1387). Point additions run on
the ed25519_add precompile, proven by the TwistedEdwards state machine.
Overview
Ed25519 is the twisted Edwards curve −x² + y² = 1 + d·x²·y² over the
prime field Fp with p = 2²⁵⁵ − 19 and d = −121665/121666. The base
point B has prime order L, and the curve cofactor is 8. It is the
curve behind EdDSA signatures in RFC 8032,
used by Solana, many TLS and SSH keys, and libsodium.
The addition law is complete, so the same operation adds and doubles,
and the identity (0, 1) needs no special case.
The page is organized bottom-up:
| Section | Provides | Depends on |
|---|---|---|
| Base field (Fp) | Coordinate arithmetic and square roots of ratios. | — |
| Scalars | Canonical-scalar check and reduction mod L. | — |
| Curve | Point add, negate, (de)compress, double scalar mul. | Fp |
| EdDSA | Ed25519 signature verification (two variants). | Scalars, Curve, SHA-512 |
Field elements and scalars are 4 little-endian u64 limbs. Points are
affine and canonical, [u64; 8] = x ‖ y. The 32-byte encodings that
RFC 8032 uses are little-endian; convert them with
le_bytes_to_u64_4.
The examples on this page assume the module is in scope:
use ziskos::zisklib;
Base field (Fp)
The prime field where curve coordinates live, p = 2²⁵⁵ − 19.
Multiplication goes through the arith256_mod precompile.
Scalars
Scalars live modulo the base-point order L.
Whether a scalar is canonical, s < L. RFC 8032 rejects signatures
with s ≥ L.
pub fn is_canonical_scalar_ed25519(s: &[u64; 4]) -> bool
Returns
| Type | Description |
|---|---|
bool | true if s < L. |
Curve
Affine point operations. All additions and doublings go through the
ed25519_add precompile (see
syscall_ed25519_add).
Adds two points. Because the addition law is complete, it also doubles
when p1 == p2.
pub fn add_points_ed25519(p1: &[u64; 8], p2: &[u64; 8]) -> [u64; 8]
Parameters
| Name | Type | Description |
|---|---|---|
p1 | &[u64; 8] | First point as x ‖ y limbs. |
p2 | &[u64; 8] | Second point as x ‖ y limbs. |
Returns
| Type | Description |
|---|---|
[u64; 8] | p1 + p2. |
Example
let r = zisklib::add_points_ed25519(&p, &q);
EdDSA
Ed25519 signature verification per RFC 8032 (pure Ed25519, no context
or prehash). Both variants compute k = SHA-512(R ‖ A ‖ M) mod L over
the encodings exactly as given, reject s ≥ L, recompute
R' = [s]B − [k]A, and compare its canonical encoding with the R
bytes of the signature. SHA-512 runs in software, so the cost grows
with the message length.
Verifies an Ed25519 signature with the cofactorless check. It matches
ed25519-dalek's verify.
pub fn ed25519_verify(pk: &[u8; 32], msg: &[u8], sig: &[u8; 64]) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
pk | &[u8; 32] | Compressed public key A. |
msg | &[u8] | The message. |
sig | &[u8; 64] | Signature R ‖ S. |
Returns
| Type | Description |
|---|---|
bool | true if the signature is valid, false otherwise (including a public key that does not decompress or a non-canonical S). |
Example
let ok = zisklib::ed25519_verify(&pk, b"hello world", &sig);