[][src]Module libra_crypto::x25519

An abstraction of x25519 elliptic curve keys required for Diffie-Hellman key exchange in the Libra 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 libra_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 libra_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

PrivateKey

This type should be used to deserialize a received private key

PublicKey

This type should be used to deserialize a received public key

Constants

PRIVATE_KEY_SIZE

Size of a X25519 private key

PUBLIC_KEY_SIZE

Size of a X25519 public key

SHARED_SECRET_SIZE

Size of a X25519 shared secret

Functions

keypair_strategy

Produces a uniformly random ed25519 keypair from a seed