macro_rules! define_curve25519_keypair {
($(#[ $docs_and_attrs:meta ])*
$vis:vis $base_name:ident) => { ... };
}
Expand description
Create a curve25519 keypair wrapper given a visibility and a struct name.
§Syntax:
ⓘ
define_curve25519_keypair(<visibility> <prefix>)
This macro creates a struct tuple named <prefix>Keypair
which contains the lower-level
cryptographic keypair for a curve25519 keypair. It derives the deftly Curve25519Keypair template
which in turn creates <prefix>PublicKey
along a series of useful methods.
The keypair is NOT clonable by design in order to avoid duplicating secret key material.
§Example:
use tor_key_forge::define_curve25519_keypair;
define_curve25519_keypair!(NonPublicEnc);
define_curve25519_keypair!(pub PublicEnc);
define_curve25519_keypair!(pub(crate) CratePublicEnc);
The above results in NonPublicEncKeypair
and NonPublicEncPublicKey
struct being created and
usable with a series of useful methods.
You can then use these objects like so:
use tor_key_forge::define_curve25519_keypair;
use tor_key_forge::Keygen;
define_curve25519_keypair!(
// This is Alice's keypair.
AliceEnc
);
define_curve25519_keypair!(BobEnc);
let alice_kp = AliceEncKeypair::generate(&mut rng).expect("Failed alice keygen");
let bob_kp = BobEncKeypair::generate(&mut rng).expect("Failed bob keygen");
// Using the public key wrapper
let alice_shared_secret = alice_kp.diffie_hellman(bob_kp.public());
// Using the direct curve25519::PublicKey.
let bob_shared_secret = bob_kp.diffie_hellman(&alice_kp.public().0);
assert_eq!(alice_shared_secret.as_bytes(), bob_shared_secret.as_bytes());