Merge fixes for pfmath functions #14
12 changed files with 16 additions and 40 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
env::{self, args},
|
env::{self},
|
||||||
fs,
|
fs,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
|
|
||||||
use std::{collections::HashMap, env::args};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::utils::{
|
use crate::utils::parse::{Responses, Testcase, Testcases};
|
||||||
ciphers::gcm_encrypt_aes,
|
|
||||||
parse::{Responses, Testcase, Testcases},
|
|
||||||
};
|
|
||||||
use tasks01::{
|
use tasks01::{
|
||||||
block2poly::block2poly,
|
block2poly::block2poly,
|
||||||
gcm::{gcm_decrypt, gcm_encrypt},
|
gcm::{gcm_decrypt, gcm_encrypt},
|
||||||
|
|
@ -14,7 +11,7 @@ use tasks01::{
|
||||||
pfmath::{gfdiv, gfpoly_add, gfpoly_divmod, gfpoly_mul, gfpoly_pow, gfpoly_powmod},
|
pfmath::{gfdiv, gfpoly_add, gfpoly_divmod, gfpoly_mul, gfpoly_pow, gfpoly_powmod},
|
||||||
poly2block::poly2block,
|
poly2block::poly2block,
|
||||||
sea128::sea128,
|
sea128::sea128,
|
||||||
xex::{self, fde_xex},
|
xex::{fde_xex},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::poly::{b64_2_num, block_2_polynomial, get_coefficients};
|
use crate::utils::poly::block_2_polynomial;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
use crate::utils::{
|
use crate::utils::poly::gfmul;
|
||||||
field::ByteArray,
|
|
||||||
poly::{b64_2_num, coefficient_to_binary, gfmul},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ use base64::prelude::*;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::Instant;
|
||||||
use std::{thread, usize};
|
use std::usize;
|
||||||
|
|
||||||
pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
let hostname: String = serde_json::from_value(args["hostname"].clone())?;
|
let hostname: String = serde_json::from_value(args["hostname"].clone())?;
|
||||||
|
|
@ -29,8 +29,6 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
let mut chunk_counter = 0;
|
let mut chunk_counter = 0;
|
||||||
|
|
||||||
for chunk in &cipher_chunks {
|
for chunk in &cipher_chunks {
|
||||||
let start = Instant::now();
|
|
||||||
|
|
||||||
let mut stream = TcpStream::connect(format!("{}:{}", hostname, port))?;
|
let mut stream = TcpStream::connect(format!("{}:{}", hostname, port))?;
|
||||||
stream.set_nonblocking(false)?;
|
stream.set_nonblocking(false)?;
|
||||||
|
|
||||||
|
|
@ -111,12 +109,12 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
} else {
|
} else {
|
||||||
//eprintln!("Invalid padding");
|
//eprintln!("Invalid padding");
|
||||||
// Search for second hit
|
// Search for second hit
|
||||||
let valid_val = (255
|
let valid_val = 255
|
||||||
- server_q_resp
|
- server_q_resp
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.position(|&r| r == 0x01)
|
.position(|&r| r == 0x01)
|
||||||
.unwrap_or(0x00) as u8);
|
.unwrap_or(0x00) as u8;
|
||||||
if valid_val == 0x00 {
|
if valid_val == 0x00 {
|
||||||
eprintln!("No valid found");
|
eprintln!("No valid found");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::utils::poly::{self, polynomial_2_block};
|
use crate::utils::poly::{polynomial_2_block};
|
||||||
use anyhow::{Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
use base64::prelude::*;
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
pub fn poly2block(args: &Value) -> Result<Vec<u8>> {
|
pub fn poly2block(args: &Value) -> Result<Vec<u8>> {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ pub fn sea128(args: &Value) -> Result<String> {
|
||||||
let input_string: String = serde_json::from_value(args["input"].clone())?;
|
let input_string: String = serde_json::from_value(args["input"].clone())?;
|
||||||
//let plaintexts: &[u8] = &b64_2_num(plaintexts_string)?.to_ne_bytes();
|
//let plaintexts: &[u8] = &b64_2_num(plaintexts_string)?.to_ne_bytes();
|
||||||
let input = BASE64_STANDARD.decode(input_string)?;
|
let input = BASE64_STANDARD.decode(input_string)?;
|
||||||
let xor_val: u128 = 0xc0ffeec0ffeec0ffeec0ffeec0ffee11;
|
|
||||||
|
|
||||||
let mode: String = serde_json::from_value(args["mode"].clone())?;
|
let mode: String = serde_json::from_value(args["mode"].clone())?;
|
||||||
match mode.as_str() {
|
match mode.as_str() {
|
||||||
|
|
@ -34,7 +33,6 @@ pub fn sea128(args: &Value) -> Result<String> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
use std::{io::BufRead, process::Output};
|
use crate::utils::{field::ByteArray, poly::gfmul};
|
||||||
|
|
||||||
use crate::utils::{field::ByteArray, math::reverse_bits_in_bytevec, poly::gfmul};
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
use openssl::symm::{Cipher, Crypter, Mode};
|
use openssl::symm::{Cipher, Crypter, Mode};
|
||||||
|
|
@ -40,7 +38,6 @@ pub fn aes_128_decrypt(key: &Vec<u8>, input: &Vec<u8>) -> Result<Vec<u8>> {
|
||||||
|
|
||||||
let mut bytes: [u8; 16] = [0u8; 16];
|
let mut bytes: [u8; 16] = [0u8; 16];
|
||||||
bytes.copy_from_slice(&plaintext);
|
bytes.copy_from_slice(&plaintext);
|
||||||
let number: u128 = <u128>::from_be_bytes(bytes);
|
|
||||||
|
|
||||||
Ok(plaintext)
|
Ok(plaintext)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
use std::{
|
use std::ops::{Add, BitXor, Div, Mul, Sub};
|
||||||
env::args,
|
|
||||||
ops::{Add, BitXor, Div, Mul, Rem, Sub},
|
|
||||||
result,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Ok, Result};
|
use anyhow::{anyhow, Ok, Result};
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::{tasks::tasks01::poly2block::poly2block, utils::poly::polynomial_2_block};
|
use crate::utils::poly::polynomial_2_block;
|
||||||
|
|
||||||
use super::{math::xor_bytes, poly::gfmul};
|
use super::{math::xor_bytes, poly::gfmul};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
use anyhow::{anyhow, Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
use base64::Engine;
|
|
||||||
|
|
||||||
use super::poly::gfmul;
|
|
||||||
|
|
||||||
pub fn xor_bytes(vec1: &Vec<u8>, mut vec2: Vec<u8>) -> Result<Vec<u8>> {
|
pub fn xor_bytes(vec1: &Vec<u8>, mut vec2: Vec<u8>) -> Result<Vec<u8>> {
|
||||||
for (byte1, byte2) in vec1.iter().zip(vec2.iter_mut()) {
|
for (byte1, byte2) in vec1.iter().zip(vec2.iter_mut()) {
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,6 @@ pub fn parse_json(json: String) -> Result<Testcases> {
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
|
|
||||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
use crate::utils::field::ByteArray;
|
use crate::utils::field::ByteArray;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
use serde_json::Value;
|
|
||||||
use std::{str::FromStr, u128, u8, usize};
|
use std::{str::FromStr, u128, u8, usize};
|
||||||
|
|
||||||
use super::{field, math::reverse_bits_in_bytevec};
|
|
||||||
pub const RED_POLY: u128 = 0x87000000_00000000_00000000_00000000;
|
pub const RED_POLY: u128 = 0x87000000_00000000_00000000_00000000;
|
||||||
|
|
||||||
pub fn gfmul(poly_a: &Vec<u8>, poly_b: &Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
|
pub fn gfmul(poly_a: &Vec<u8>, poly_b: &Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
|
||||||
|
|
@ -172,7 +170,7 @@ pub fn coefficients_to_byte_arr_xex(coeffs: Vec<u8>) -> Vec<u8> {
|
||||||
let mut byte_array: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
let mut byte_array: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
for coeff in coeffs {
|
for coeff in coeffs {
|
||||||
let block_num = coeff / 8;
|
let block_num = coeff / 8;
|
||||||
byte_array[usize::from(block_num)] |= (1 << (coeff % 7));
|
byte_array[usize::from(block_num)] |= 1 << (coeff % 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte_array
|
byte_array
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue