Skip to content

Commit

Permalink
Slightly refactored compress_q and ran cargo fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzcf committed Oct 11, 2023
1 parent ef6b8ad commit a981c0f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/kem/kyber/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ use super::{
fn compress_q<const COEFFICIENT_BITS: usize>(fe: u16) -> KyberFieldElement {
debug_assert!(COEFFICIENT_BITS <= BITS_PER_COEFFICIENT);

let two_pow_bit_size = 1u32 << COEFFICIENT_BITS;

let mut compressed = (fe as u32) * (two_pow_bit_size << 1);
let mut compressed = (fe as u32) << (COEFFICIENT_BITS + 1);
compressed += FIELD_MODULUS as u32;
compressed /= (FIELD_MODULUS << 1) as u32;

(compressed & (two_pow_bit_size - 1)) as KyberFieldElement
(compressed & ((1u32 << COEFFICIENT_BITS) - 1)) as KyberFieldElement
}
pub fn compress<const COEFFICIENT_BITS: usize>(
mut re: KyberPolynomialRingElement,
Expand Down Expand Up @@ -41,4 +39,3 @@ pub fn decompress<const COEFFICIENT_BITS: usize>(
.map(|coefficient| decompress_q::<COEFFICIENT_BITS>(coefficient));
re
}

1 change: 0 additions & 1 deletion src/kem/kyber/ind_cpa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub fn serialize_secret_key<const SERIALIZED_KEY_LEN: usize>(
.array()
}


#[inline(always)]
#[allow(non_snake_case)]
fn sample_matrix_A<const K: usize>(
Expand Down

0 comments on commit a981c0f

Please sign in to comment.