Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-lj committed Dec 1, 2023
1 parent c7d0845 commit 62efaac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion fastcrypto/src/groups/multiplier/windowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<
panic!("CACHE_SIZE must be a power of two greater than 1");
}
let mut cache = vec![];
cache.push(zero); //[zero; CACHE_SIZE];
cache.push(zero);
cache.push(base_element.clone());
for i in 2..CACHE_SIZE {
cache.push(cache[i - 1].clone() + &base_element);
Expand Down
17 changes: 12 additions & 5 deletions fastcrypto/src/serde_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,21 @@ pub trait ToFromByteArray<const LENGTH: usize>: Sized {
fn to_byte_array(&self) -> [u8; LENGTH];
}

impl ToFromByteArray<34> for BigInt {
fn from_byte_array(_bytes: &[u8; 34]) -> Result<Self, FastCryptoError> {
panic!("Not used")
// This is used for multi-scalar multiplication
impl<const N: usize> ToFromByteArray<N> for BigInt {
fn from_byte_array(bytes: &[u8; N]) -> Result<Self, FastCryptoError> {
Ok(BigInt::from_signed_bytes_be(bytes))
}

Check warning on line 79 in fastcrypto/src/serde_helpers.rs

View check run for this annotation

Codecov / codecov/patch

fastcrypto/src/serde_helpers.rs#L77-L79

Added lines #L77 - L79 were not covered by tests

fn to_byte_array(&self) -> [u8; 34] {
let mut output = [0u8; 34];
fn to_byte_array(&self) -> [u8; N] {
let mut output = [0u8; N];
let bytes = self.to_signed_bytes_le();

// It's up to the caller to ensure that the BigInt is not too large to fit in N bytes.
if bytes.len() > N {
// TODO: Should we return the first N bytes instead of panicking?
panic!("BigInt is too large to fit in {} bytes", N);

Check warning on line 88 in fastcrypto/src/serde_helpers.rs

View check run for this annotation

Codecov / codecov/patch

fastcrypto/src/serde_helpers.rs#L88

Added line #L88 was not covered by tests
}
output[0..bytes.len()].clone_from_slice(&bytes);
output
}
Expand Down

0 comments on commit 62efaac

Please sign in to comment.