#ed25519 #signature #x25519 #eddsa #random-key #crypto

no-std ed25519-compact

A small, self-contained, wasm-friendly Ed25519 implementation

38 releases (stable)

2.1.1 Feb 4, 2024
2.0.6 Dec 15, 2023
2.0.4 Dec 5, 2022
2.0.2 Oct 11, 2022
0.1.6 Jul 4, 2020

#16 in Cryptography

Download history 42690/week @ 2024-01-28 46003/week @ 2024-02-04 45704/week @ 2024-02-11 50074/week @ 2024-02-18 54103/week @ 2024-02-25 58385/week @ 2024-03-03 60053/week @ 2024-03-10 64376/week @ 2024-03-17 58376/week @ 2024-03-24 57053/week @ 2024-03-31 56483/week @ 2024-04-07 56746/week @ 2024-04-14 65073/week @ 2024-04-21 67285/week @ 2024-04-28 67399/week @ 2024-05-05 62378/week @ 2024-05-12

266,695 downloads per month
Used in 64 crates (27 directly)

MIT license

3.5K SLoC

GitHub CI

A compact Ed25519 and X25519 implementation for Rust

  • Formally-verified Curve25519 field arithmetic
  • no_std-friendly
  • WebAssembly-friendly
  • Fastly Compute-friendly
  • Lightweight
  • Zero dependencies if randomness is provided by the application
  • Only one portable dependency (getrandom) if not
  • Supports incremental signatures (streaming API)
  • Safe and simple Rust interface

API documentation

Example usage


ed25519-compact = "2"

Example code:

// A message to sign and verify.
let message = b"test";

// Generates a new key pair using a random seed.
// A given seed will always produce the same key pair.
let key_pair = KeyPair::from_seed(Seed::default());

// Computes a signature for this message using the secret part of the key pair.
let signature = key_pair.sk.sign(message, Some(Noise::default()));

// Verifies the signature using the public part of the key pair.
    .verify(message, &signature)
    .expect("Signature didn't verify");

// Verification of a different message using the same signature and public key fails.
    .verify(b"A different message", &signature)
    .expect_err("Signature shouldn't verify");

// All these structures can be viewed as raw bytes simply by dereferencing them:
let signature_as_bytes: &[u8] = signature.as_ref();
println!("Signature as bytes: {:?}", signature_as_bytes);

Incremental API example usage

Messages can also be supplied as multiple parts (streaming API) in order to handle large messages without using much memory:

/// Creates a new key pair.
let kp = KeyPair::generate();

/// Creates a state for an incremental signer.
let mut st = kp.sk.sign_incremental(Noise::default());

/// Feeds the message as any number of chunks, and sign the concatenation.
let signature = st.sign();

/// Creates a state for an incremental verifier.
let mut st = kp.pk.verify_incremental(&signature)?;

/// Feeds the message as any number of chunks, and verify the concatenation.

Cargo features

  • self-verify: after having computed a new signature, verify that is it valid. This is slower, but improves resilience against fault attacks. It is enabled by default on WebAssembly targets.
  • std: disables no_std compatibility in order to make errors implement the standard Error trait.
  • random (enabled by default): adds Default implementations to the Seed and Noise objects, in order to securely create random keys and noise.
  • traits: add support for the traits from the ed25519 and signature crates.
  • pem: add support for importing/exporting keys as OpenSSL-compatible PEM files.
  • blind-keys: add support for key blinding.
  • opt_size: Enable size optimizations (based on benchmarks, 8-15% size reduction at the cost of 6.5-7% performance).
  • x25519: Enable support for the X25519 key exchange system.
  • disable-signatures: Disable support for signatures, and only compile support for X25519.