From b9067599d409c569990efa97a5dfb6bd0bdd27ca Mon Sep 17 00:00:00 2001 From: Alex Page Date: Wed, 28 Jun 2023 03:49:35 -0400 Subject: [PATCH] Completely remove OpenSSL --- Cargo.lock | 63 ------------------------------------------------ umskt/Cargo.toml | 1 - umskt/src/key.rs | 20 +++++++++------ umskt/src/msr.rs | 29 ---------------------- 4 files changed, 13 insertions(+), 100 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d496ca9..1284077 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -241,21 +241,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "generic-array" version = "0.14.7" @@ -385,47 +370,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "openssl" -version = "0.10.55" -source = "git+https://github.com/sfackler/rust-openssl#8909d3e20682f2f3a3928b53a7cc1ebb118cf19d" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "git+https://github.com/sfackler/rust-openssl#8909d3e20682f2f3a3928b53a7cc1ebb118cf19d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-sys" -version = "0.9.90" -source = "git+https://github.com/sfackler/rust-openssl#8909d3e20682f2f3a3928b53a7cc1ebb118cf19d" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "pkg-config" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -611,7 +555,6 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", - "openssl", "rand", "serde_json", "sha1", @@ -630,12 +573,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" diff --git a/umskt/Cargo.toml b/umskt/Cargo.toml index 1c234ca..0957c9a 100644 --- a/umskt/Cargo.toml +++ b/umskt/Cargo.toml @@ -10,7 +10,6 @@ elliptic-curve = "0.13.5" num-bigint = { version = "0.4.3", features = ["rand"] } num-integer = "0.1.45" num-traits = "0.2.15" -openssl = { git = "https://github.com/sfackler/rust-openssl" } rand = "0.8.5" sha1 = "0.10.5" thiserror = "1.0.40" diff --git a/umskt/src/key.rs b/umskt/src/key.rs index 562a8a2..4dd8b2d 100644 --- a/umskt/src/key.rs +++ b/umskt/src/key.rs @@ -1,7 +1,9 @@ use std::collections::VecDeque; use anyhow::{anyhow, Result}; -use openssl::bn::BigNum; +use num_bigint::{BigInt, Sign}; +use num_integer::Integer; +use num_traits::{ToPrimitive, Zero}; const PK_LENGTH: usize = 25; @@ -17,20 +19,24 @@ pub(crate) fn base24_decode(cd_key: &str) -> Result> { .filter_map(|c| KEY_CHARSET.iter().position(|&x| x == c).map(|i| i as u8)) .collect(); - let mut y = BigNum::from_u32(0).unwrap(); + let mut y = BigInt::zero(); for i in decoded_key { - y.mul_word((PK_LENGTH - 1) as u32).unwrap(); - y.add_word(i.into()).unwrap(); + y *= PK_LENGTH - 1; + y += i as u32; } - Ok(y.to_vec()) + Ok(y.to_bytes_be().1) } pub(crate) fn base24_encode(byte_seq: &[u8]) -> Result { - let mut z = BigNum::from_slice(byte_seq).unwrap(); + let mut z = BigInt::from_bytes_be(Sign::Plus, byte_seq); let mut out: VecDeque = VecDeque::new(); - (0..=24).for_each(|_| out.push_front(KEY_CHARSET[z.div_word(24).unwrap() as usize])); + (0..=24).for_each(|_| { + let (quo, rem) = z.div_rem(&BigInt::from(24)); + z = quo; + out.push_front(KEY_CHARSET[rem.to_u32().unwrap() as usize]); + }); Ok(out.iter().collect()) } diff --git a/umskt/src/msr.rs b/umskt/src/msr.rs index feaeccd..780b216 100644 --- a/umskt/src/msr.rs +++ b/umskt/src/msr.rs @@ -59,32 +59,3 @@ pub fn mod_sqrt(n: &BigInt, p: &BigInt) -> Option { m = i; } } - -#[cfg(test)] -mod tests { - use openssl::bn::{BigNum, BigNumContext}; - - #[test] - fn test() { - let n = "1573769205219068003359487454943505465350185201622247106224183162699789934914421854093895861489537435530695722027283028984396996570717144433549421890648379"; - let p = "5622613991231344109"; - - { - let n = num_bigint::BigInt::parse_bytes(n.as_bytes(), 10).unwrap(); - let p = num_bigint::BigInt::parse_bytes(p.as_bytes(), 10).unwrap(); - - let r = super::mod_sqrt(&n, &p).unwrap(); - dbg!(r); - } - - { - let mut ctx = BigNumContext::new().unwrap(); - let n = BigNum::from_dec_str(n).unwrap(); - let p = BigNum::from_dec_str(p).unwrap(); - - let mut r = BigNum::new().unwrap(); - r.mod_sqrt(&n, &p, &mut ctx).unwrap(); - dbg!(r.to_dec_str().unwrap()); - } - } -}