diff --git a/src/main.rs b/src/main.rs index d32a7cf..2ab4644 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ -use keygen::Person; use discrete_logarithm::discrete_log_pollard_rho; +use keygen::Person; use rug::Integer; +use utils::mod_pow; mod keygen; mod utils; @@ -11,12 +12,37 @@ fn main() { Person::diffie_hellman(&mut alice, &mut bob); alice.send(b"Hello World", &bob); - let n_primediv = discrete_log_pollard_rho(&Integer::from(alice.r#mod.unwrap()) - , &Integer::from(alice.public_key.unwrap()), &Integer::from(alice.gen.unwrap()), None); + let alice_priv = discrete_log_pollard_rho( + &Integer::from(alice.r#mod.unwrap()), + &Integer::from(alice.public_key.unwrap()), + &Integer::from(alice.gen.unwrap()), + None, + ).unwrap(); + let bob_priv = discrete_log_pollard_rho( + &Integer::from(bob.r#mod.unwrap()), + &Integer::from(bob.public_key.unwrap()), + &Integer::from(bob.gen.unwrap()), + None, + ); eprintln!( - "[{}] Calculated private key {} from public key {}", + "[mallory] Calculated {}'s private key {} from {}'s public key {}", + alice.name, + &alice_priv, alice.name, - n_primediv.unwrap(), alice.public_key.unwrap() ); + eprintln!( + "[mallory] Calculated {}'s private key {} from {}'s public key {}", + bob.name, + bob_priv.unwrap(), + bob.name, + bob.public_key.unwrap() + ); + eprintln!( + "[mallory] Calculated {}'s and {}'s shared secret {}", + alice.name, + bob.name, + mod_pow(bob.public_key.unwrap(), alice_priv.to_u32_wrapping(), alice.r#mod.unwrap()) + ); + //Some(mod_pow(public, self.private_key.unwrap(), r#mod } diff --git a/src/utils.rs b/src/utils.rs index 678084d..26f0416 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -25,4 +25,4 @@ where exp /= T::from(2); } result -} \ No newline at end of file +}