Module x25519
Available on crate feature
dep_orion
only.Expand description
Diffie-Hellman key exchange over Curve25519 as specified in the RFC 7748.
§Parameters:
private_key
: The private key used in key agreement.public_key
: The public key used in key agreement.
§Errors:
An error will be returned if:
- The
key_agreement()
operation results in an all-zero output.
§Security:
- Multiple different
private_key
/public_key
pairs can produce the same shared key. Therefore, using the resultingSharedKey
, directly fromkey_agreement()
, is not recommended. This is handled automatically inorion::kex
. - To securely generate a strong key, use
PrivateKey::generate()
.
§Recommendation:
- It is recommended to use
orion::kex
when possible.
§Example:
use orion::hazardous::ecc::x25519::{PrivateKey, PublicKey, SharedKey, key_agreement};
use core::convert::TryFrom;
// Alice generates a private key and computes the corresponding public key
let alice_sk = PrivateKey::generate();
let alice_pk = PublicKey::try_from(&alice_sk)?;
// Bob does the same
let bob_sk = PrivateKey::generate();
let bob_pk = PublicKey::try_from(&bob_sk)?;
// They both compute a shared key using the others public key
let alice_shared = key_agreement(&alice_sk, &bob_pk)?;
let bob_shared = key_agreement(&bob_sk, &alice_pk)?;
assert_eq!(alice_shared, bob_shared);
Structs§
- Private
Key - A type to represent the
PrivateKey
that X25519 uses. - Public
Key - A type that represents a
PublicKey
that X25519 uses. - Shared
Key - A type to represent the
SharedKey
that X25519 produces.
Constants§
- PRIVATE_
KEY_ SIZE - The size of a private key used in X25519.
- PUBLIC_
KEY_ SIZE - The size of a public key used in X25519.
- SHARED_
KEY_ SIZE - The size of a shared key used in X25519.
Functions§
- key_
agreement - X25519 (Diffie-Hellman with Montgomery form of Curve25519).