1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Elliptic Curve Diffie-Hellman (Ephemeral) Support.
//!
//! This module contains a high-level interface for performing ephemeral
//! Diffie-Hellman key exchanges using the secp384r1 elliptic curve.
//!
//! # Usage
//!
//! This usage example is from the perspective of two participants in the
//! exchange, nicknamed "Alice" and "Bob".
//!
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! // NOTE: requires the `ecdh` and `getrandom` crate features are enabled
//! use p384::{
//! Sec1Point, PublicKey,
//! elliptic_curve::Generate,
//! ecdh::EphemeralSecret
//! };
//!
//! // Alice
//! let alice_secret = EphemeralSecret::generate();
//! let alice_pk_bytes = Sec1Point::from(alice_secret.public_key());
//!
//! // Bob
//! let bob_secret = EphemeralSecret::generate();
//! let bob_pk_bytes = Sec1Point::from(bob_secret.public_key());
//!
//! // Alice decodes Bob's serialized public key and computes a shared secret from it
//! let bob_public = PublicKey::from_sec1_bytes(bob_pk_bytes.as_ref())?;
//!
//! let alice_shared = alice_secret.diffie_hellman(&bob_public);
//!
//! // Bob decodes Alice's serialized public key and computes the same shared secret
//! let alice_public = PublicKey::from_sec1_bytes(alice_pk_bytes.as_ref())
//! .expect("alice's public key is invalid!"); // In real usage, don't panic, handle this!
//!
//! let bob_shared = bob_secret.diffie_hellman(&alice_public);
//!
//! // Both participants arrive on the same shared secret
//! assert_eq!(alice_shared.raw_secret_bytes(), bob_shared.raw_secret_bytes());
//! # Ok(())
//! # }
//! ```
pub use diffie_hellman;
use crateNistP384;
/// NIST P-384 Ephemeral Diffie-Hellman Secret.
pub type EphemeralSecret = EphemeralSecret;
/// Shared secret value computed via ECDH key agreement.
pub type SharedSecret = SharedSecret;