add mallory and let them calculate bobs private key and their shared secret as well

This commit is contained in:
theBreadCompany 2024-12-07 19:22:05 +01:00
parent fdfc1bac45
commit 1ba1e6931d
2 changed files with 32 additions and 6 deletions

View file

@ -1,6 +1,7 @@
use keygen::Person;
use discrete_logarithm::discrete_log_pollard_rho; use discrete_logarithm::discrete_log_pollard_rho;
use keygen::Person;
use rug::Integer; use rug::Integer;
use utils::mod_pow;
mod keygen; mod keygen;
mod utils; mod utils;
@ -11,12 +12,37 @@ fn main() {
Person::diffie_hellman(&mut alice, &mut bob); Person::diffie_hellman(&mut alice, &mut bob);
alice.send(b"Hello World", &bob); alice.send(b"Hello World", &bob);
let n_primediv = discrete_log_pollard_rho(&Integer::from(alice.r#mod.unwrap()) let alice_priv = discrete_log_pollard_rho(
, &Integer::from(alice.public_key.unwrap()), &Integer::from(alice.gen.unwrap()), None); &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!( eprintln!(
"[{}] Calculated private key {} from public key {}", "[mallory] Calculated {}'s private key {} from {}'s public key {}",
alice.name,
&alice_priv,
alice.name, alice.name,
n_primediv.unwrap(),
alice.public_key.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
} }

View file

@ -25,4 +25,4 @@ where
exp /= T::from(2); exp /= T::from(2);
} }
result result
} }