Skip to content

Commit

Permalink
remove useless FromUniformBytes implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
kilic committed May 30, 2024
1 parent b36f783 commit 851ed19
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 675 deletions.
14 changes: 8 additions & 6 deletions derive/src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ pub(crate) fn impl_field(input: TokenStream) -> TokenStream {
}


/// Converts an element of `$field` into a byte representation in
/// Converts an element of `$field` into a byte representation in
/// <#endian>-endian byte order.
pub fn to_bytes(&self) -> [u8; Self::SIZE] {
use crate::serde::endian::Endian;
let el = self.from_mont();
let mut res = [0; #size];
let mut res = [0; Self::SIZE];
crate::serde::endian::#endian::to_bytes(&mut res, &el);
res.into()
}
Expand Down Expand Up @@ -599,12 +599,14 @@ pub(crate) fn impl_field(input: TokenStream) -> TokenStream {

let impl_from_uniform_bytes = from_uniform
.iter()
.map(|size| {
.map(|input_size| {
assert!(*input_size >= size);
assert!(*input_size <= size*2);
quote! {
impl ff::FromUniformBytes<#size> for #field {
fn from_uniform_bytes(bytes: &[u8; #size]) -> Self {
impl ff::FromUniformBytes<#input_size> for #field {
fn from_uniform_bytes(bytes: &[u8; #input_size]) -> Self {
let mut wide = [0u8; Self::SIZE * 2];
wide[..#size].copy_from_slice(bytes);
wide[..#input_size].copy_from_slice(bytes);
let (a0, a1) = wide.split_at(Self::SIZE);

let a0: [u64; Self::NUM_LIMBS] = (0..Self::NUM_LIMBS)
Expand Down
3 changes: 1 addition & 2 deletions src/bn256/fq2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ impl Fq2 {
let mut c0 = -self.c1;
c0 += self.c0;
c0 *= c0c1;
c0 -= ab;
self.c1 = ab.double();
self.c0 = c0 + ab;
self.c0 = c0;
}

// conjugate by negating c1
Expand Down
17 changes: 0 additions & 17 deletions src/derive/field/tower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,6 @@ macro_rules! impl_tower2 {
}
}

impl FromUniformBytes<{ $field::SIZE * 2 }> for $tower {
fn from_uniform_bytes(bytes: &[u8; $field::SIZE * 2]) -> Self {
Self::new($field::from_uniform_bytes(bytes), $field::ZERO)
}
}

impl FromUniformBytes<{ $field::SIZE * 2 * 2 }> for $tower {
fn from_uniform_bytes(bytes: &[u8; $field::SIZE * 2 * 2]) -> Self {
let c0: [u8; $field::SIZE * 2] = bytes[..$field::SIZE * 2].try_into().unwrap();
let c1: [u8; $field::SIZE * 2] = bytes[$field::SIZE * 2..].try_into().unwrap();
Self::new(
$field::from_uniform_bytes(&c0),
$field::from_uniform_bytes(&c1),
)
}
}

impl $crate::serde::SerdeObject for $tower {
fn from_raw_bytes_unchecked(bytes: &[u8]) -> Self {
debug_assert_eq!(bytes.len(), $field::SIZE * 2);
Expand Down
Loading

0 comments on commit 851ed19

Please sign in to comment.