Completely remove OpenSSL
This commit is contained in:
parent
2ffa34e673
commit
b9067599d4
4 changed files with 13 additions and 100 deletions
|
@ -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"
|
||||
|
|
|
@ -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<Vec<u8>> {
|
|||
.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<String> {
|
||||
let mut z = BigNum::from_slice(byte_seq).unwrap();
|
||||
let mut z = BigInt::from_bytes_be(Sign::Plus, byte_seq);
|
||||
let mut out: VecDeque<char> = 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())
|
||||
}
|
||||
|
||||
|
|
|
@ -59,32 +59,3 @@ pub fn mod_sqrt(n: &BigInt, p: &BigInt) -> Option<BigInt> {
|
|||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue