This commit is contained in:
Daniel Laptop 2022-12-01 12:39:01 +01:00
commit 9e5c4126a5

View File

@ -19,7 +19,17 @@ fn main() {
0x15, 0xc3, 0xb5, 0x96, 0x41, 0x17, 0x4e, 0xc9,
0x67, 0x8a, 0x53, 0x78, 0x9d, 0x92, 0xc7, 0x54,
]);
let (salsa_box, pub_key) = generate_box(bob_init_pub_key.clone());
// Generate a random secret key.
// NOTE: The secret key bytes can be accessed by calling `secret_key.as_bytes()`
let own_secret_key = SecretKey::generate(&mut OsRng);
// Get the public key for the secret key we just generated
let own_public_key = own_secret_key.public_key().clone();
// Create a `SalsaBox` by performing Diffie-Hellman key agreement between
// the two keys.
let salsa_box = SalsaBox::new(&bob_init_pub_key, &own_secret_key);
loop {
let mut buffer = String::new();
@ -68,18 +78,3 @@ fn main() {
}
println!("Terminated.");
}
fn generate_box(partner_public_key: PublicKey) -> (SalsaBox, PublicKey) {
// Generate a random secret key.
// NOTE: The secret key bytes can be accessed by calling `secret_key.as_bytes()`
let own_secret_key = SecretKey::generate(&mut OsRng);
// Get the public key for the secret key we just generated
let own_public_key = own_secret_key.public_key().clone();
// Create a `SalsaBox` by performing Diffie-Hellman key agreement between
// the two keys.
let salsa_box = SalsaBox::new(&partner_public_key, &own_secret_key);
(salsa_box, own_public_key)
}