| Crates.io | x25519-nostd |
| lib.rs | x25519-nostd |
| version | 0.1.0 |
| created_at | 2025-12-22 11:25:36.131478+00 |
| updated_at | 2025-12-22 11:25:36.131478+00 |
| description | Pure-Rust X25519 (Curve25519) ECDH implementation for no_std/bare-metal targets (avoids LLVM SIMD issues) |
| homepage | https://github.com/artst3in/x25519-nostd |
| repository | https://github.com/artst3in/x25519-nostd |
| max_upload_size | |
| id | 1999581 |
| size | 34,205 |
Pure-Rust X25519 (Curve25519) elliptic curve Diffie-Hellman implementation for no_std and bare-metal targets.
The standard curve25519-dalek and x25519-dalek crates (from RustCrypto) fail to compile on certain bare-metal targets like x86_64-unknown-none with LLVM errors:
LLVM ERROR: Do not know how to split the result of this operator!
This happens because these crates use SIMD intrinsics that aren't available on all targets. This pure-Rust implementation avoids SIMD entirely, making it portable to any Rust target.
no_std compatible: Works in bare-metal and embedded environmentsAdd to your Cargo.toml:
[dependencies]
x25519-nostd = "0.1"
use x25519_nostd::{public_key, diffie_hellman};
// Alice generates a keypair
let alice_secret = [0x42u8; 32]; // In practice, use secure random
let alice_public = public_key(&alice_secret);
// Bob generates a keypair
let bob_secret = [0x07u8; 32];
let bob_public = public_key(&bob_secret);
// Both compute the same shared secret
let alice_shared = diffie_hellman(&alice_secret, &bob_public);
let bob_shared = diffie_hellman(&bob_secret, &alice_public);
assert_eq!(alice_shared, bob_shared);
use x25519_nostd::{public_key, diffie_hellman};
// Generate static keypair
let static_secret = [/* secure random 32 bytes */];
let static_public = public_key(&static_secret);
// Compute shared secret with peer
let peer_public = [/* peer's public key */];
let shared_secret = diffie_hellman(&static_secret, &peer_public);
// Use shared_secret with a KDF (like BLAKE2s or HKDF)
X25519 performs scalar multiplication on Curve25519:
y² = x³ + 486662x² + xp = 2^255 - 19u = 9s[0] &= 248, s[31] &= 127, s[31] |= 64Uses the Montgomery ladder for constant-time scalar multiplication.
2^255 - 19a^(p-2) ≡ a^(-1) (mod p)On modern x86_64 CPUs:
(Performance varies by target; bare-metal may differ)
Tested on:
x86_64-unknown-none (bare-metal)x86_64-unknown-linux-gnu (std)Run the test suite:
cargo test
Includes RFC 7748 test vectors.
Licensed under Apache License 2.0.
Contributions welcome! This crate was extracted from a bare-metal OS project to help the Rust embedded and bare-metal community overcome LLVM SIMD limitations.