summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-04-17 01:21:15 -0400
committerJesse Luehrs <doy@tozt.net>2019-04-17 01:21:15 -0400
commitdf9d05b74ef79671d4421bf6134b204fdc7a5ee3 (patch)
treecfabac77b2f35e0460485b3f8de1a1fc8184d7fa /src
parent06188a1e0ba1c03ac223afb59b62fd6fcf928bb0 (diff)
downloadmatasano-df9d05b74ef79671d4421bf6134b204fdc7a5ee3.tar.gz
matasano-df9d05b74ef79671d4421bf6134b204fdc7a5ee3.zip
problem 33
Diffstat (limited to 'src')
-rw-r--r--src/dh.rs28
-rw-r--r--src/lib.rs2
2 files changed, 30 insertions, 0 deletions
diff --git a/src/dh.rs b/src/dh.rs
new file mode 100644
index 0000000..24c2277
--- /dev/null
+++ b/src/dh.rs
@@ -0,0 +1,28 @@
+use num_bigint::RandBigInt;
+
+pub struct DHKeyPair {
+ pub p: num_bigint::BigUint,
+ pub g: num_bigint::BigUint,
+ pub pubkey: num_bigint::BigUint,
+ privkey: num_bigint::BigUint,
+}
+
+impl DHKeyPair {
+ pub fn new(p: num_bigint::BigUint, g: num_bigint::BigUint) -> DHKeyPair {
+ let privkey = rand::thread_rng().gen_biguint_below(&p);
+ let pubkey = g.modpow(&privkey, &p);
+ DHKeyPair {
+ p,
+ g,
+ pubkey,
+ privkey,
+ }
+ }
+
+ pub fn key_exchange(
+ &self,
+ other_pubkey: &num_bigint::BigUint,
+ ) -> num_bigint::BigUint {
+ other_pubkey.modpow(&self.privkey, &self.p)
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index ae69401..7c1dc82 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,7 @@
mod aes;
mod crack;
mod data;
+mod dh;
mod http;
mod md4;
mod primitives;
@@ -36,6 +37,7 @@ pub use crack::recover_16_bit_mt19937_key;
pub use crack::recover_mersenne_twister_seed_from_time;
pub use crack::recover_mt19937_key_from_time;
pub use crack::BlockCipherMode;
+pub use dh::DHKeyPair;
pub use http::create_query_string;
pub use http::parse_query_string;
pub use md4::md4;