Skip to content

Commit

Permalink
Remove NewFromU128
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinas committed Nov 17, 2024
1 parent ccd63fb commit 5821cb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
20 changes: 10 additions & 10 deletions src/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ mod test {
use super::*;

use crate::{
fields::{large_fields::NewFromU128, GF128, GF192, GF256},
fields::{GF128, GF192, GF256},
parameter::{
FAEST128sParameters, FAEST192sParameters, FAEST256sParameters, FAESTParameters,
OWFParameters, OWF128, OWF192, OWF256,
Expand Down Expand Up @@ -853,6 +853,12 @@ mod test {
res: Vec<u64>,
}

impl AesVerify {
fn res_as_u8(&self) -> Vec<u8> {
self.res.iter().flat_map(|x| x.to_le_bytes()).collect()
}
}

fn aes_verify<O, Tau>(
d: &GenericArray<u8, O::LBYTES>,
gq: &GenericArray<GenericArray<u8, O::LAMBDALBYTES>, O::LAMBDA>,
Expand Down Expand Up @@ -900,7 +906,7 @@ mod test {
GenericArray::from_slice(&data.output),
);
assert_eq!(
GF128::new(data.res[0] as u128 + ((data.res[1] as u128) << 64), 0),
GF128::from(data.res_as_u8().as_slice()),
GF128::from(&out[..])
);
} else if data.lambda == 192 {
Expand All @@ -920,10 +926,7 @@ mod test {
GenericArray::from_slice(&data.output),
);
assert_eq!(
GF192::new(
data.res[0] as u128 + ((data.res[1] as u128) << 64),
data.res[2] as u128
),
GF192::from(data.res_as_u8().as_slice()),
GF192::from(&out[..])
);
} else {
Expand All @@ -943,10 +946,7 @@ mod test {
GenericArray::from_slice(&data.output),
);
assert_eq!(
GF256::new(
data.res[0] as u128 + ((data.res[1] as u128) << 64),
data.res[2] as u128 + ((data.res[3] as u128) << 64)
),
GF256::from(data.res_as_u8().as_slice()),
GF256::from(&out[..])
);
}
Expand Down
29 changes: 0 additions & 29 deletions src/fields/large_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,35 +966,6 @@ impl Distribution<GF256> for Standard {
}
}

#[cfg(test)]
/// Construct fields from `u128` representations
///
/// Only for tests!
pub(crate) trait NewFromU128 {
fn new(first_value: u128, second_value: u128) -> Self;
}

#[cfg(test)]
impl NewFromU128 for GF128 {
fn new(first_value: u128, _second_value: u128) -> Self {
Self([first_value])
}
}

#[cfg(test)]
impl NewFromU128 for GF192 {
fn new(first_value: u128, second_value: u128) -> Self {
Self([first_value, second_value]).clear_high_bits()
}
}

#[cfg(test)]
impl NewFromU128 for GF256 {
fn new(first_value: u128, second_value: u128) -> Self {
Self([first_value, second_value])
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit 5821cb2

Please sign in to comment.