Skip to main content

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.

New in 1.4.0-alpha

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:

SectionProvidesDepends on
Base field (Fp)Coordinate arithmetic and square roots of ratios.—
ScalarsCanonical-scalar check and reduction mod L.—
CurvePoint add, negate, (de)compress, double scalar mul.Fp
EdDSAEd25519 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.

Reduces a value below 2²⁵⁵ into the base field, with at most one subtraction of p.

pub fn reduce_fp_ed25519(x: &[u64; 4]) -> [u64; 4]

Parameters​

NameTypeDescription
x&[u64; 4]Value as 4 LE limbs. Must be < 2²⁵⁵ (debug-asserted).

Returns​

TypeDescription
[u64; 4]x mod p.

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​

TypeDescription
booltrue 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​

NameTypeDescription
p1&[u64; 8]First point as x ‖ y limbs.
p2&[u64; 8]Second point as x ‖ y limbs.

Returns​

TypeDescription
[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​

NameTypeDescription
pk&[u8; 32]Compressed public key A.
msg&[u8]The message.
sig&[u8; 64]Signature R ‖ S.

Returns​

TypeDescription
booltrue 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);