Expand description
Elliptic Curve Diffie-Hellman operations.
This module implements ECDH over the NIST curves P-256 and P-384.
use bssl_crypto::{ecdh, ec::P256};
let alice_private_key = ecdh::PrivateKey::<P256>::generate();
let alice_public_key_serialized = alice_private_key.to_x962_uncompressed();
// Somehow, Alice's public key is sent to Bob.
let bob_private_key = ecdh::PrivateKey::<P256>::generate();
let alice_public_key =
ecdh::PublicKey::<P256>::from_x962_uncompressed(
alice_public_key_serialized.as_ref())
.unwrap();
let shared_key1 = bob_private_key.compute_shared_key(&alice_public_key);
// Likewise, Alice gets Bob's public key and computes the same shared key.
let bob_public_key = bob_private_key.to_public_key();
let shared_key2 = alice_private_key.compute_shared_key(&bob_public_key);
assert_eq!(shared_key1, shared_key2);Structsยง
- Private
Key - An ECDH private key over the given curve.
- Public
Key - An ECDH public key over the given curve.