refactor: remove commented code
This commit is contained in:
parent
b24c703429
commit
c9c26b3971
6 changed files with 2 additions and 120 deletions
|
|
@ -19,7 +19,6 @@ pub fn block2poly(val: &Value) -> Result<Vec<u8>> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
// 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::*;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
let q_block_count: u16 = 256;
|
let q_block_count: u16 = 256;
|
||||||
|
|
||||||
//Send the first ciphertext chunk
|
//Send the first ciphertext chunk
|
||||||
//eprintln!("Sending Ciphertext chunk: {:002X?}", chunk);
|
|
||||||
stream.flush()?;
|
stream.flush()?;
|
||||||
stream.write_all(&chunk)?;
|
stream.write_all(&chunk)?;
|
||||||
stream.flush()?;
|
stream.flush()?;
|
||||||
|
|
@ -50,10 +49,6 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
// FIXME: Assignment is redundant for now
|
// FIXME: Assignment is redundant for now
|
||||||
// TODO: Goal is to maybe add speed increase in the future
|
// TODO: Goal is to maybe add speed increase in the future
|
||||||
let l_msg: [u8; 2] = q_block_count.to_le_bytes();
|
let l_msg: [u8; 2] = q_block_count.to_le_bytes();
|
||||||
//eprintln!("Sending l_msg: {:02X?}", l_msg);
|
|
||||||
//stream.write_all(&l_msg)?;
|
|
||||||
//stream.flush()?;
|
|
||||||
//eprintln!("L_msg sent");
|
|
||||||
|
|
||||||
// Generate attack blocks
|
// Generate attack blocks
|
||||||
// TODO: Collect all and send in one
|
// TODO: Collect all and send in one
|
||||||
|
|
@ -61,14 +56,9 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
payload.extend(l_msg.to_vec());
|
payload.extend(l_msg.to_vec());
|
||||||
for j in 0..q_block_count {
|
for j in 0..q_block_count {
|
||||||
// Next byte
|
// Next byte
|
||||||
//eprintln!("Sending attack block: {:02X?}", attack_counter);
|
|
||||||
|
|
||||||
//thread::sleep(Duration::from_millis(1000));
|
|
||||||
payload.extend(&attack_counter);
|
payload.extend(&attack_counter);
|
||||||
//eprintln!("I in q builder {}", i);
|
|
||||||
attack_counter[i as usize] += 1;
|
attack_counter[i as usize] += 1;
|
||||||
}
|
}
|
||||||
//eprintln!("Time for qblocks: {:?}", start.elapsed());
|
|
||||||
|
|
||||||
stream.write_all(&payload)?;
|
stream.write_all(&payload)?;
|
||||||
stream.flush()?;
|
stream.flush()?;
|
||||||
|
|
@ -76,7 +66,6 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
// Read server response
|
// Read server response
|
||||||
let mut server_q_resp = [0u8; 256];
|
let mut server_q_resp = [0u8; 256];
|
||||||
stream.read_exact(&mut server_q_resp)?;
|
stream.read_exact(&mut server_q_resp)?;
|
||||||
//eprintln!("{:02X?}", buf);
|
|
||||||
|
|
||||||
// extract valid position
|
// extract valid position
|
||||||
let valid_val = server_q_resp
|
let valid_val = server_q_resp
|
||||||
|
|
@ -86,7 +75,6 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
if valid_val == 0x00 {
|
if valid_val == 0x00 {
|
||||||
eprintln!("No valid found in main loop");
|
eprintln!("No valid found in main loop");
|
||||||
}
|
}
|
||||||
//eprintln!("Valid value found: {:02X?}", valid_val);
|
|
||||||
// Craft next attack vector padding; 0x01, 0x02, ...
|
// Craft next attack vector padding; 0x01, 0x02, ...
|
||||||
attack_counter[i as usize] = valid_val;
|
attack_counter[i as usize] = valid_val;
|
||||||
|
|
||||||
|
|
@ -100,15 +88,10 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
l_msg_check.extend(check_q_block.as_slice());
|
l_msg_check.extend(check_q_block.as_slice());
|
||||||
|
|
||||||
stream.write_all(&l_msg_check)?;
|
stream.write_all(&l_msg_check)?;
|
||||||
//stream.write_all(&check_q_block)?;
|
|
||||||
let mut buf = [0u8; 0x01];
|
let mut buf = [0u8; 0x01];
|
||||||
stream.read(&mut buf)?;
|
stream.read(&mut buf)?;
|
||||||
//eprintln!("I = {}", i);
|
|
||||||
//eprintln!("Buffer from pad check: {:02X?}", buf);
|
|
||||||
if buf == [0x01] {
|
if buf == [0x01] {
|
||||||
//eprintln!("Valid padding");
|
|
||||||
} else {
|
} else {
|
||||||
//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
|
||||||
|
|
@ -119,38 +102,21 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
if valid_val == 0x00 {
|
if valid_val == 0x00 {
|
||||||
eprintln!("No valid found");
|
eprintln!("No valid found");
|
||||||
}
|
}
|
||||||
//eprintln!("Valid value found: {:02X?}", valid_val);
|
|
||||||
// Craft next attack vector padding; 0x01, 0x02, ...
|
// Craft next attack vector padding; 0x01, 0x02, ...
|
||||||
attack_counter[i as usize] = valid_val;
|
attack_counter[i as usize] = valid_val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if chunk_counter + 1 < cipher_chunks.len() {
|
if chunk_counter + 1 < cipher_chunks.len() {
|
||||||
//eprintln!("XOR Next Ciph block");
|
|
||||||
plaintext.push(
|
plaintext.push(
|
||||||
cipher_chunks[chunk_counter + 1][i]
|
cipher_chunks[chunk_counter + 1][i]
|
||||||
^ (attack_counter[i as usize] ^ (15 - i as u8 + 1)),
|
^ (attack_counter[i as usize] ^ (15 - i as u8 + 1)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//seprintln!("XOR IV");
|
|
||||||
|
|
||||||
plaintext.push(iv[i] ^ (attack_counter[i as usize] ^ (15 - i as u8 + 1)));
|
plaintext.push(iv[i] ^ (attack_counter[i as usize] ^ (15 - i as u8 + 1)));
|
||||||
}
|
}
|
||||||
//eprintln!("Attack counter after set: {:02X?}", attack_counter);
|
|
||||||
let range = i;
|
let range = i;
|
||||||
for pos in range..=15 {
|
for pos in range..=15 {
|
||||||
//eprintln!("i is: {:02X?}", i);
|
|
||||||
//eprintln!("i + 1 is: {:02X?}", ((16 - i) as u8).to_le());
|
|
||||||
/*
|
|
||||||
eprintln!(
|
|
||||||
"attack_counter[pos as usize]: {:02X?}",
|
|
||||||
attack_counter[pos as usize]
|
|
||||||
);
|
|
||||||
eprintln!(
|
|
||||||
"attack_counter[pos as usize] ^ 0x02 {:02X?}",
|
|
||||||
attack_counter[pos as usize] ^ (15 - i as u8 + 1)
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
let intermediate = attack_counter[pos as usize] ^ (15 - i as u8 + 1);
|
let intermediate = attack_counter[pos as usize] ^ (15 - i as u8 + 1);
|
||||||
|
|
||||||
attack_counter[pos as usize] = intermediate ^ ((15 - i as u8 + 1) + 1);
|
attack_counter[pos as usize] = intermediate ^ ((15 - i as u8 + 1) + 1);
|
||||||
|
|
@ -159,13 +125,10 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||||
stream.flush()?;
|
stream.flush()?;
|
||||||
|
|
||||||
// Write plaintext
|
// Write plaintext
|
||||||
//eprintln!("{:02X?}", plaintext);
|
|
||||||
}
|
}
|
||||||
chunk_counter += 1;
|
chunk_counter += 1;
|
||||||
stream.flush()?;
|
stream.flush()?;
|
||||||
// break;
|
|
||||||
drop(stream);
|
drop(stream);
|
||||||
//eprintln!("Time rest of calc: {:?}", start.elapsed());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plaintext.reverse();
|
plaintext.reverse();
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,13 @@ use crate::utils::ciphers::{sea_128_decrypt, sea_128_encrypt};
|
||||||
|
|
||||||
pub fn sea128(args: &Value) -> Result<String> {
|
pub fn sea128(args: &Value) -> Result<String> {
|
||||||
let key_string: String = serde_json::from_value(args["key"].clone())?;
|
let key_string: String = serde_json::from_value(args["key"].clone())?;
|
||||||
//let key: &[u8] = b64_2_num(key_string)?.to_ne_bytes();
|
|
||||||
let key = BASE64_STANDARD.decode(key_string)?;
|
let key = BASE64_STANDARD.decode(key_string)?;
|
||||||
//eprintln!("{:?}", key);
|
|
||||||
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 input = BASE64_STANDARD.decode(input_string)?;
|
let input = BASE64_STANDARD.decode(input_string)?;
|
||||||
|
|
||||||
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() {
|
||||||
"encrypt" => {
|
"encrypt" => {
|
||||||
//eprintln!("{:?}", plaintexts);
|
|
||||||
|
|
||||||
let output = BASE64_STANDARD.encode(sea_128_encrypt(&key, &input)?);
|
let output = BASE64_STANDARD.encode(sea_128_encrypt(&key, &input)?);
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,6 @@ pub fn gcm_decrypt_aes(
|
||||||
|
|
||||||
let mut counter: u32 = 1;
|
let mut counter: u32 = 1;
|
||||||
nonce.append(counter.to_be_bytes().to_vec().as_mut());
|
nonce.append(counter.to_be_bytes().to_vec().as_mut());
|
||||||
//nonce.append(0u8.to_le_bytes().to_vec().as_mut());
|
|
||||||
|
|
||||||
let auth_tag_xor = aes_128_encrypt(&key, &nonce)?;
|
let auth_tag_xor = aes_128_encrypt(&key, &nonce)?;
|
||||||
|
|
||||||
|
|
@ -250,7 +249,6 @@ pub fn gcm_decrypt_sea(
|
||||||
|
|
||||||
let mut counter: u32 = 1;
|
let mut counter: u32 = 1;
|
||||||
nonce.append(counter.to_be_bytes().to_vec().as_mut());
|
nonce.append(counter.to_be_bytes().to_vec().as_mut());
|
||||||
//nonce.append(0u8.to_le_bytes().to_vec().as_mut());
|
|
||||||
|
|
||||||
let auth_tag_xor = sea_128_encrypt(&key, &nonce)?;
|
let auth_tag_xor = sea_128_encrypt(&key, &nonce)?;
|
||||||
|
|
||||||
|
|
@ -324,13 +322,6 @@ pub fn ghash(
|
||||||
Ok(inter_loop)
|
Ok(inter_loop)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* let mut bytes: [u8; 16] = [0u8; 16];
|
|
||||||
bytes.copy_from_slice(&ciphertext);
|
|
||||||
let number: u128 = <u128>::from_be_bytes(bytes);
|
|
||||||
|
|
||||||
* */
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ use std::{
|
||||||
|
|
||||||
use anyhow::{anyhow, Ok, Result};
|
use anyhow::{anyhow, Ok, Result};
|
||||||
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
math::{reverse_bits_in_bytevec, xor_bytes},
|
math::{reverse_bits_in_bytevec, xor_bytes},
|
||||||
poly::gfmul,
|
poly::gfmul,
|
||||||
|
|
@ -41,14 +40,6 @@ impl FieldElement {
|
||||||
self.field_element.clone()
|
self.field_element.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
pub fn padd(&mut self) {
|
|
||||||
if self.field_element.len() % 16 != 0 || ad.is_empty() {
|
|
||||||
ad.append(vec![0u8; 16 - (ad.len() % 16)].as_mut());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub fn new(field_element: Vec<u8>) -> Self {
|
pub fn new(field_element: Vec<u8>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
field_element: reverse_bits_in_bytevec(field_element),
|
field_element: reverse_bits_in_bytevec(field_element),
|
||||||
|
|
@ -80,29 +71,18 @@ impl FieldElement {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//eprintln!("Initial result: {:?}", result);
|
|
||||||
while exponent > 0 {
|
while exponent > 0 {
|
||||||
//eprintln!("Current exponent: {:02X}", exponent);
|
|
||||||
if exponent & 1 == 1 {
|
if exponent & 1 == 1 {
|
||||||
let temp = &self * &result;
|
let temp = &self * &result;
|
||||||
//eprintln!("Mult");
|
|
||||||
//eprintln!("After mod: {:?}", temp);
|
|
||||||
|
|
||||||
result = temp
|
result = temp
|
||||||
}
|
}
|
||||||
let temp_square = &self * &self;
|
let temp_square = &self * &self;
|
||||||
// eprintln!("Square");
|
|
||||||
|
|
||||||
// eprintln!("After squaring: {:?}", temp_square);
|
|
||||||
self = temp_square;
|
self = temp_square;
|
||||||
//eprintln!("After mod: {:?}", self);
|
|
||||||
exponent >>= 1;
|
exponent >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eprintln!("result in powmod before reduction: {:02X?}", result);
|
|
||||||
|
|
||||||
// eprintln!("result in powmod after reduction: {:02X?}", result);
|
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,10 +91,8 @@ impl FieldElement {
|
||||||
|
|
||||||
let mut inverser = INVERSER_START;
|
let mut inverser = INVERSER_START;
|
||||||
let mut inverse: Vec<u8> = vec![0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
let mut inverse: Vec<u8> = vec![0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
//eprintln!("Inverse start {:02X?}", inverse);
|
|
||||||
|
|
||||||
while inverser > 0 {
|
while inverser > 0 {
|
||||||
//eprintln!("{:02X}", inverser);
|
|
||||||
if inverser & 1 == 1 {
|
if inverser & 1 == 1 {
|
||||||
inverse = gfmul(&self.field_element, &inverse, "xex").unwrap();
|
inverse = gfmul(&self.field_element, &inverse, "xex").unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +100,6 @@ impl FieldElement {
|
||||||
self.field_element = gfmul(&self.field_element, &self.field_element, "xex")
|
self.field_element = gfmul(&self.field_element, &self.field_element, "xex")
|
||||||
.expect("Error in sqrmul sqr");
|
.expect("Error in sqrmul sqr");
|
||||||
}
|
}
|
||||||
//eprintln!("Inverse rhs {:?}", inverse);
|
|
||||||
FieldElement::new_no_convert(inverse)
|
FieldElement::new_no_convert(inverse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
use crate::utils::field::ByteArray;
|
use crate::utils::field::ByteArray;
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
|
|
||||||
use num::traits::{FromBytes, ToBytes};
|
use num::traits::FromBytes;
|
||||||
use num::{BigUint, One, Zero};
|
use num::{BigUint, One, Zero};
|
||||||
|
|
||||||
use std::{str::FromStr, u128, u8, usize};
|
use std::{str::FromStr, u128, u8, usize};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
ops::{Add, Div, Mul},
|
ops::{Add, Mul},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, Ok, Result};
|
use anyhow::{anyhow, Ok, Result};
|
||||||
|
|
@ -107,27 +107,18 @@ impl Polynomial {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//eprintln!("Initial result: {:?}", result);
|
|
||||||
while exponent > 0 {
|
while exponent > 0 {
|
||||||
//eprintln!("Current exponent: {:02X}", exponent);
|
|
||||||
if exponent & 1 == 1 {
|
if exponent & 1 == 1 {
|
||||||
let temp = &self * &result;
|
let temp = &self * &result;
|
||||||
//eprintln!("Mult");
|
|
||||||
//eprintln!("After mod: {:?}", temp);
|
|
||||||
|
|
||||||
result = temp
|
result = temp
|
||||||
}
|
}
|
||||||
let temp_square = &self * &self;
|
let temp_square = &self * &self;
|
||||||
//eprintln!("Square");
|
|
||||||
|
|
||||||
//eprintln!("After squaring: {:?}", temp_square);
|
|
||||||
self = temp_square;
|
self = temp_square;
|
||||||
//eprintln!("After mod: {:?}", self);
|
|
||||||
exponent >>= 1;
|
exponent >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//eprintln!("result in powmod before reduction: {:02X?}", result);
|
|
||||||
|
|
||||||
while !result.polynomial.is_empty()
|
while !result.polynomial.is_empty()
|
||||||
&& result
|
&& result
|
||||||
.polynomial
|
.polynomial
|
||||||
|
|
@ -140,8 +131,6 @@ impl Polynomial {
|
||||||
result.polynomial.pop();
|
result.polynomial.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
//eprintln!("result in powmod after reduction: {:02X?}", result);
|
|
||||||
|
|
||||||
if result.is_empty() {
|
if result.is_empty() {
|
||||||
result = Polynomial::zero();
|
result = Polynomial::zero();
|
||||||
}
|
}
|
||||||
|
|
@ -166,19 +155,13 @@ impl Polynomial {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//eprintln!("Initial result: {:?}", result);
|
|
||||||
while &exponent > &BigUint::zero() {
|
while &exponent > &BigUint::zero() {
|
||||||
//eprintln!("Current exponent: {:02X}", exponent);
|
|
||||||
if &exponent & BigUint::one() == BigUint::one() {
|
if &exponent & BigUint::one() == BigUint::one() {
|
||||||
let temp = &self * &result;
|
let temp = &self * &result;
|
||||||
//eprintln!("After multiplication: {:?}", temp);
|
|
||||||
result = temp.div(&modulus).1;
|
result = temp.div(&modulus).1;
|
||||||
//eprintln!("After mod: {:?}", result);
|
|
||||||
}
|
}
|
||||||
let temp_square = &self * &self;
|
let temp_square = &self * &self;
|
||||||
//eprintln!("After squaring: {:?}", temp_square);
|
|
||||||
self = temp_square.div(&modulus).1;
|
self = temp_square.div(&modulus).1;
|
||||||
//eprintln!("After mod: {:?}", self);
|
|
||||||
exponent >>= 1;
|
exponent >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,19 +198,13 @@ impl Polynomial {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//eprintln!("Initial result: {:?}", result);
|
|
||||||
while exponent > 0 {
|
while exponent > 0 {
|
||||||
//eprintln!("Current exponent: {:02X}", exponent);
|
|
||||||
if exponent & 1 == 1 {
|
if exponent & 1 == 1 {
|
||||||
let temp = &self * &result;
|
let temp = &self * &result;
|
||||||
//eprintln!("After multiplication: {:?}", temp);
|
|
||||||
result = temp.div(&modulus).1;
|
result = temp.div(&modulus).1;
|
||||||
//eprintln!("After mod: {:?}", result);
|
|
||||||
}
|
}
|
||||||
let temp_square = &self * &self;
|
let temp_square = &self * &self;
|
||||||
//eprintln!("After squaring: {:?}", temp_square);
|
|
||||||
self = temp_square.div(&modulus).1;
|
self = temp_square.div(&modulus).1;
|
||||||
//eprintln!("After mod: {:?}", self);
|
|
||||||
exponent >>= 1;
|
exponent >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -574,13 +551,10 @@ 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>> {
|
||||||
let red_poly_bytes: ByteArray = ByteArray(RED_POLY.to_be_bytes().to_vec());
|
let red_poly_bytes: ByteArray = ByteArray(RED_POLY.to_be_bytes().to_vec());
|
||||||
//red_poly_bytes.0.push(0x01);
|
|
||||||
|
|
||||||
let mut poly1: ByteArray = ByteArray(poly_a.to_vec());
|
let mut poly1: ByteArray = ByteArray(poly_a.to_vec());
|
||||||
//poly1.0.push(0x00);
|
|
||||||
|
|
||||||
let mut poly2: ByteArray = ByteArray(poly_b.to_vec());
|
let mut poly2: ByteArray = ByteArray(poly_b.to_vec());
|
||||||
//poly2.0.push(0x00);
|
|
||||||
|
|
||||||
if semantic == "gcm" {
|
if semantic == "gcm" {
|
||||||
poly1.reverse_bits_in_bytevec();
|
poly1.reverse_bits_in_bytevec();
|
||||||
|
|
@ -618,7 +592,6 @@ pub fn gfmul(poly_a: &Vec<u8>, poly_b: &Vec<u8>, semantic: &str) -> Result<Vec<u
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bgfmul(poly_a: &Vec<u8>, poly_b: &Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
|
pub fn bgfmul(poly_a: &Vec<u8>, poly_b: &Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
|
||||||
//TODO: Implement gfmul with bigint
|
|
||||||
let red_poly_bytes: BigUint = BigUint::from_slice(&[
|
let red_poly_bytes: BigUint = BigUint::from_slice(&[
|
||||||
0x87, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0x01,
|
0x87, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0x01,
|
||||||
]);
|
]);
|
||||||
|
|
@ -627,13 +600,6 @@ pub fn bgfmul(poly_a: &Vec<u8>, poly_b: &Vec<u8>, semantic: &str) -> Result<Vec<
|
||||||
|
|
||||||
let mut poly2: BigUint = BigUint::from_le_bytes(poly_b);
|
let mut poly2: BigUint = BigUint::from_le_bytes(poly_b);
|
||||||
|
|
||||||
/*
|
|
||||||
if semantic == "gcm" {
|
|
||||||
poly1.re;
|
|
||||||
poly2.reverse_bits_in_bytevec();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
let mut result: BigUint = BigUint::zero();
|
let mut result: BigUint = BigUint::zero();
|
||||||
|
|
||||||
if (&poly2 & (BigUint::one() << 127)) == BigUint::one() {
|
if (&poly2 & (BigUint::one() << 127)) == BigUint::one() {
|
||||||
|
|
@ -655,12 +621,6 @@ pub fn bgfmul(poly_a: &Vec<u8>, poly_b: &Vec<u8>, semantic: &str) -> Result<Vec<
|
||||||
poly2 = &poly2 >> 1;
|
poly2 = &poly2 >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if semantic == "gcm" {
|
|
||||||
result.reverse_bits_in_bytevec();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Ok(result.to_bytes_le())
|
Ok(result.to_bytes_le())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -676,8 +636,6 @@ pub fn convert_gcm_to_xex(gcm_poly: Vec<u8>) -> Result<Vec<u8>> {
|
||||||
pub fn get_alpha_rep(num: u128) -> String {
|
pub fn get_alpha_rep(num: u128) -> String {
|
||||||
let powers: Vec<u8> = get_coefficients(num);
|
let powers: Vec<u8> = get_coefficients(num);
|
||||||
|
|
||||||
//println!("{:?}", powers);
|
|
||||||
|
|
||||||
let mut alpha_rep = String::new();
|
let mut alpha_rep = String::new();
|
||||||
|
|
||||||
if powers.len() == 1 {
|
if powers.len() == 1 {
|
||||||
|
|
@ -704,7 +662,6 @@ pub fn b64_2_num(string: &String) -> Result<u128> {
|
||||||
pub fn get_coefficients(num: u128) -> Vec<u8> {
|
pub fn get_coefficients(num: u128) -> Vec<u8> {
|
||||||
let mut powers: Vec<u8> = vec![];
|
let mut powers: Vec<u8> = vec![];
|
||||||
for shift in 0..128 {
|
for shift in 0..128 {
|
||||||
//println!("{:?}", ((num >> shift) & 1));
|
|
||||||
if ((num >> shift) & 1) == 1 {
|
if ((num >> shift) & 1) == 1 {
|
||||||
powers.push(shift);
|
powers.push(shift);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue