A compact Ed25519 and X25519 implementation for Rust
- Formally-verified Curve25519 field arithmetic
no_std-friendly- WebAssembly-friendly
- Compute@Edge-friendly
- Lightweight
- Zero dependencies if randomness is provided by the application
- Only one portable dependency (
getrandom) if not - Safe and simple Rust interface
API documentation
Example usage
cargo.toml:
[]
= "0.1"
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 = from_seed;
// Computes a signature for this message using the secret part of the key pair.
let signature = key_pair.sk.sign;
// Verifies the signature using the public part of the key pair.
key_pair
.pk
.verify
.expect;
// Verification of a different message using the same signature and public key fails.
key_pair
.pk
.verify
.expect_err;
// All these structures can be viewed as raw bytes simply by dereferencing them:
let signature_as_bytes: & = signature.as_ref;
println!;
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: disablesno_stdcompatibility in order to make errors implement the standardErrortrait.random(enabled by default): addsDefaultimplementations to theSeedandNoiseobjects, in order to securely create random keys and noise.traits: add support for the traits from theed25519andsignaturecrates.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.