Module diem_crypto::x25519
source · Expand description
An abstraction of x25519 elliptic curve keys required for
Diffie-Hellman key exchange
in the Diem project.
Ideally, only x25519::PrivateKey
and x25519::PublicKey
should be used throughout the
codebase, until the bytes are actually used in cryptographic operations.
Examples
use diem_crypto::{x25519, Uniform, test_utils::TEST_SEED};
use rand::{rngs::StdRng, SeedableRng};
// Derive an X25519 private key for testing.
let mut rng: StdRng = SeedableRng::from_seed(TEST_SEED);
let private_key = x25519::PrivateKey::generate(&mut rng);
let public_key = private_key.public_key();
// Deserialize an hexadecimal private or public key
use diem_crypto::traits::ValidCryptoMaterialStringExt;
let private_key = "404acc8ec6a0f18df7359a6ee7823f19dd95616b10fed8bdb0de030e891b945a";
let private_key = x25519::PrivateKey::from_encoded_string(&private_key)?;
let public_key = "080e287879c918794170e258bfaddd75acac5b3e350419044655e4983a487120";
let public_key = x25519::PublicKey::from_encoded_string(&public_key)?;
Re-exports
pub use x25519_dalek;
Structs
- This type should be used to deserialize a received private key
- This type should be used to deserialize a received public key
Constants
- Size of a X25519 private key
- Size of a X25519 public key
- Size of a X25519 shared secret
Functions
- Produces a uniformly random ed25519 keypair from a seed