autoinstall + feistel0 module python

This commit is contained in:
Christoph J. Scherr 2023-05-10 18:11:34 +02:00
parent ad7cdd48b1
commit 462ee87ac4
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
4 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "plexcryptool"
version = "0.1.2"
version = "0.2.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

5
install.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
rm target/wheels -rf
cargo install --path .
maturin build --release
pip install target/wheels/plexcryptool*x86_64.whl --force

View File

@ -8,6 +8,8 @@
/// License: MIT
/// Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
use pyo3::prelude::*;
const SBOX: [u8; 0x10] = [0x4, 3, 9, 0xa, 0xb, 2, 0xe, 1, 0xd, 0xc, 8, 6, 7, 5, 0, 0xf];
const ROUNDS: u8 = 3;
@ -20,6 +22,7 @@ fn test_inner() {
assert!(inner(0x9876, 0xfedc, false) == 0x93c5);
}
#[pyfunction]
pub fn inner(input: u16, key: u16, verbose: bool) -> u16 {
// cut into u8 blocks
let mut blocks: [u8; 4] = [
@ -85,6 +88,7 @@ pub fn inner(input: u16, key: u16, verbose: bool) -> u16 {
return result ^ key
}
#[pyfunction]
/// Boilerplate KSA, returns the same given values everytime.
pub fn key_scheduler(_key: u32) -> Vec<u16> {
return vec![0xdead, 0xc0ff, 0xee5a]
@ -96,6 +100,7 @@ fn test_encrypt() {
assert_eq!(encrypt(0x12345678, vec![0x1aa2, 0x2bb3, 0x3cc4], true), 0x4313e07a);
}
#[pyfunction]
/// encrypt a block
pub fn encrypt(plaintext: u32, keys: Vec<u16>, verbose: bool) -> u32 {
assert_eq!(keys.len(), ROUNDS as usize);
@ -133,6 +138,7 @@ fn test_decrypt() {
assert_eq!(plaintext, deciphertext);
}
#[pyfunction]
/// decrypt a given plaintext with a given key vec
pub fn decrypt(ciphertext: u32, mut keys: Vec<u16>, verbose: bool) -> u32 {
assert_eq!(keys.len(), ROUNDS as usize);
@ -175,6 +181,7 @@ pub fn decrypt(ciphertext: u32, mut keys: Vec<u16>, verbose: bool) -> u32 {
return plaintext;
}
#[pyfunction]
/// returns the value of the sbox for any input
///
/// max index is 0xf

View File

@ -22,6 +22,7 @@ use pyo3::prelude::*;
mod binary;
mod math;
mod algo;
#[pymodule]
fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
@ -41,6 +42,17 @@ fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
Ok(())
}
#[pymodule]
fn register_algo_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
let algo_module = PyModule::new(py, "algo")?;
algo_module.add_function(wrap_pyfunction!(algo::feistel0::encrypt, algo_module)?)?;
algo_module.add_function(wrap_pyfunction!(algo::feistel0::decrypt, algo_module)?)?;
algo_module.add_function(wrap_pyfunction!(algo::feistel0::sbox, algo_module)?)?;
algo_module.add_function(wrap_pyfunction!(algo::feistel0::key_scheduler, algo_module)?)?;
parent_module.add_submodule(algo_module)?;
Ok(())
}
/// A Python module implemented in Rust.
#[pymodule]
fn plexcryptool(py: Python, m: &PyModule) -> PyResult<()> {