Daniel Laptop 2 years ago
parent
commit
9e5c4126a5
1 changed files with 11 additions and 16 deletions
  1. 11
    16
      src/bin/client.rs

+ 11
- 16
src/bin/client.rs View File

0x15, 0xc3, 0xb5, 0x96, 0x41, 0x17, 0x4e, 0xc9, 0x15, 0xc3, 0xb5, 0x96, 0x41, 0x17, 0x4e, 0xc9,
0x67, 0x8a, 0x53, 0x78, 0x9d, 0x92, 0xc7, 0x54, 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 { loop {
let mut buffer = String::new(); let mut buffer = String::new();
} }
println!("Terminated."); 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)
}


Loading…
Cancel
Save