pub struct DiffieHellmanSim {
pub p: u64,
pub g: u64,
pub alice_priv: u64,
pub bob_priv: u64,
}Expand description
Toy Diffie-Hellman key exchange simulation.
Encapsulates a full simulated key exchange between Alice and Bob.
§WARNING
Uses tiny parameters with no real security.
Fields§
§p: u64Shared prime p
g: u64Generator g
alice_priv: u64Alice’s private key
bob_priv: u64Bob’s private key
Implementations§
Source§impl DiffieHellmanSim
impl DiffieHellmanSim
Sourcepub fn new(p: u64, g: u64, alice_priv: u64, bob_priv: u64) -> Self
pub fn new(p: u64, g: u64, alice_priv: u64, bob_priv: u64) -> Self
Create a simulation with given parameters.
Sourcepub fn alice_public(&self) -> u64
pub fn alice_public(&self) -> u64
Alice’s public key: g^a mod p.
Sourcepub fn bob_public(&self) -> u64
pub fn bob_public(&self) -> u64
Bob’s public key: g^b mod p.
Shared secret computed by Alice: (g^b)^a mod p.
Shared secret computed by Bob: (g^a)^b mod p.
Sourcepub fn secrets_match(&self) -> bool
pub fn secrets_match(&self) -> bool
Verify that Alice and Bob derive the same shared secret.
Auto Trait Implementations§
impl Freeze for DiffieHellmanSim
impl RefUnwindSafe for DiffieHellmanSim
impl Send for DiffieHellmanSim
impl Sync for DiffieHellmanSim
impl Unpin for DiffieHellmanSim
impl UnsafeUnpin for DiffieHellmanSim
impl UnwindSafe for DiffieHellmanSim
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more