Expand description
Diffie-Hellman over curve25519.
X25519 is the Diffie-Hellman primitive built from curve25519. It is sometimes referred to as “curve25519”, but “X25519” is a more precise name. See http://cr.yp.to/ecdh.html and https://tools.ietf.org/html/rfc7748.
use bssl_crypto::x25519;
// Alice generates her key pair.
let (alice_public_key, alice_private_key) = x25519::PrivateKey::generate();
// Bob generates his key pair.
let (bob_public_key, bob_private_key) = x25519::PrivateKey::generate();
// If Alice obtains Bob's public key somehow, she can compute their
// shared key:
let shared_key = alice_private_key.compute_shared_key(&bob_public_key);
// Alice can then derive a key (e.g. by using HKDF), which should include
// at least the two public keys. Then shen can send a message to Bob
// including her public key and an AEAD-protected blob. Bob can compute the
// same shared key given Alice's public key:
let shared_key2 = bob_private_key.compute_shared_key(&alice_public_key);
assert_eq!(shared_key, shared_key2);
// This is an _unauthenticated_ exchange which is vulnerable to an
// active attacker. See, for example,
// http://www.noiseprotocol.org/noise.html for an example of building
// real protocols from a Diffie-Hellman primitive.Structs§
- Private
Key - An X25519 private key (a 32-byte string).
Constants§
- PRIVATE_
KEY_ LEN - Number of bytes in a private key in X25519
- PUBLIC_
KEY_ LEN - Number of bytes in a public key in X25519
- SHARED_
KEY_ LEN - Number of bytes in a shared secret derived with X25519
Type Aliases§
- Public
Key - X25519 public keys are simply 32-byte strings.