-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Linux Tests | ||
name: Linux Tests On Stable Rust | ||
on: [push] | ||
|
||
jobs: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod common_modulus_attack; | ||
pub mod common_modulus_attack; | ||
pub mod public_exponent_attack; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::sync::Arc; | ||
use num_traits; | ||
|
||
use num_bigint::{BigUint, BigInt, ToBigInt}; | ||
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
use num_bigint_dig::ModInverse; | ||
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
use num_bigint_dig::prime::probably_prime; | ||
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
//use num_bigint_dig::ToBigInt; | ||
use num_bigint_dig::RandBigInt; | ||
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
use num_traits::Pow; | ||
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
use num_integer::Integer; | ||
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
|
||
use num::FromPrimitive; | ||
use num::ToPrimitive; | ||
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
use std::str::FromStr; | ||
|
||
use crate::utils::alphabets::Alphabet; | ||
use crate::maths::factorization; | ||
use crate::utils::convert::Encode; | ||
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
|
||
pub struct PublicExponentAttacks { | ||
alphabet: Arc<Alphabet>, | ||
} | ||
|
||
impl PublicExponentAttacks { | ||
pub fn new(alphabet: Arc<Alphabet>) -> Self { | ||
PublicExponentAttacks { | ||
alphabet | ||
} | ||
} | ||
|
||
/// ``` | ||
/// use cryptatools_core::cryptanalysis::common::rsa::public_exponent_attack::{*}; | ||
/// use cryptatools_core::utils::convert::Decode; | ||
/// use num_bigint::BigInt; | ||
/// use std::str::FromStr; | ||
/// // 742449129124467073921545687640895127535705902454369756401331 | ||
/// | ||
/// //let algos = PublicExponentAttacks::new(); | ||
/// let mut plaintext = PublicExponentAttacks::modulo_factorisation_attack(vec![], vec![], vec![]); | ||
/// //let ascii: String = Decode::from_u8_to_ascii(plaintext); | ||
/// assert_eq!(plaintext, BigInt::from_str("9525146106593233618825000042088863551831280763610019197").unwrap()); | ||
/// ``` | ||
pub fn modulo_factorisation_attack(cipher_text: Vec<u8>, modulo: Vec<u8>, exponent: Vec<u8>) -> BigInt { | ||
|
||
let mut cipher = BigInt::from_u64(3); //BigUint::new(cipher_text); | ||
let mut modulo = BigInt::from_i64(-1); //BigUint::new(modulo); | ||
let mut exponent = BigInt::from_str("742449129124467073921545687639156049064283454870081476956200");//BigUint::new(exponent); | ||
|
||
|
||
let vec = factorization::Factorization::factor(exponent.clone().unwrap()); | ||
let p = &vec[0]; | ||
let q = &vec[1]; | ||
|
||
let phi = p.to_bigint().unwrap()-BigInt::from_u64(1).unwrap()*(q.to_bigint().unwrap()-BigInt::from_u64(1).unwrap()); | ||
|
||
let dec = exponent.clone().unwrap().modpow(&BigInt::from_i64(-1).unwrap(), &phi); | ||
|
||
return (cipher.unwrap().modpow(&BigInt::from_str("39207274348578481322317340648475596807303160111338236677373").unwrap(), &dec) % modulo.unwrap()); | ||
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (macos-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (windows-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs GitHub Actions / test (ubuntu-latest)
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use num_bigint::BigUint; | ||
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (macos-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (macos-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (macos-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (windows-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (windows-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (windows-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (ubuntu-latest)
Check warning on line 1 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (ubuntu-latest)
|
||
use num_bigint::BigInt; | ||
use num::FromPrimitive; | ||
|
||
pub struct Factorization { | ||
|
||
} | ||
|
||
impl Factorization { | ||
|
||
/// ``` | ||
/// use cryptatools_core::maths::factorization; | ||
/// use num_bigint::BigUint; | ||
/// | ||
/// let mut factor = factorization::factor(742449129124467073921545687640895127535705902454369756401331); | ||
/// assert_eq!(factor, vec![123]); | ||
Check failure on line 16 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (ubuntu-latest)
Check failure on line 16 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (ubuntu-latest)
Check failure on line 16 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (macos-latest)
Check failure on line 16 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (macos-latest)
Check failure on line 16 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (windows-latest)
Check failure on line 16 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (windows-latest)
Check failure on line 16 in cryptatools-core/src/maths/factorization.rs GitHub Actions / test (ubuntu-latest)
|
||
/// | ||
/// ``` | ||
pub fn factor(n_input: BigInt) -> Vec<BigInt> { | ||
|
||
let mut factors = vec![]; | ||
let mut divisor = 2; | ||
|
||
|
||
let mut n_input = n_input; | ||
while n_input >= BigInt::from_u8(2).unwrap() { | ||
if n_input.clone() % divisor == BigInt::from_u8(0).unwrap() { | ||
factors.push(BigInt::from(divisor)); | ||
n_input = n_input / divisor; | ||
} else { | ||
divisor += 1; | ||
} | ||
} | ||
|
||
factors | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod factorization; |