add pow_mod for DHM-Exchange

This commit is contained in:
none
2023-06-01 10:45:28 +02:00
parent 8ac1a1f31e
commit 5e0dcf1b13
7 changed files with 295 additions and 95 deletions
+70
View File
@@ -11,6 +11,12 @@ dependencies = [
"memchr",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bincode"
version = "1.3.3"
@@ -96,6 +102,8 @@ dependencies = [
"bincode",
"byteorder",
"crc32fast",
"num-bigint",
"rand",
"regex",
"serde",
"sha2",
@@ -113,6 +121,42 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "num-bigint"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.59"
@@ -131,6 +175,32 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "regex"
version = "1.8.3"
+2
View File
@@ -12,6 +12,8 @@ byteorder = { default-features = false, version = "1.4.3" }
sha2 = { default-features = false, version = "0.10.6" }
regex = { default-features = true, version = "1.8.3" }
crc32fast = { default-features = false, version = "1.3.2" }
rand = { default-features = false, features = ["std_rng"], version = "0.8.5" }
num-bigint = { default-features = true, version = "0.4.3" }
[profile.release]
lto = true # Enable link-time optimization
+14
View File
@@ -4,6 +4,8 @@ use serde::{Serialize, Deserialize};
use sha2::{Digest,Sha512};
use regex::Regex;
use crc32fast;
use rand::{rngs::StdRng, RngCore, SeedableRng};
use num_bigint::BigUint;
mod big_array;
use big_array::BigArray;
@@ -36,6 +38,18 @@ struct StrPacket {
payload: [u8; MAX_PAYLOAD_U]
}
fn pow_mod(num: BigUint, pow: BigUint, modulo: BigUint) -> BigUint {
let mut result = BigUint::from(1u8);
let one = BigUint::from(1u8);
let mut i = BigUint::from(0u8);
while i < pow {
result = (result * &num) % &modulo;
i += &one;
}
result
}
fn main() {
let port = "1337";
let timeout = 100; //ms