add mallory and let them calculate bobs private key and their shared secret as well
This commit is contained in:
parent
fdfc1bac45
commit
1ba1e6931d
2 changed files with 32 additions and 6 deletions
36
src/main.rs
36
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
|
||||
}
|
||||
|
|
|
@ -25,4 +25,4 @@ where
|
|||
exp /= T::from(2);
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue