Skip to content

Commit

Permalink
Slight refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzcf committed Oct 10, 2023
1 parent 015bcd7 commit d7ec486
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/kem/kyber/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn serialize_little_endian_11<const OUT_LEN: usize>(
let coefficient7 = coefficients[6];
let coefficient8 = coefficients[7];

serialized[11 * i + 0] = coefficient1 as u8;
serialized[11 * i] = coefficient1 as u8;
serialized[11 * i + 1] = ((coefficient2 & 0x1F) as u8) << 3 | ((coefficient1 >> 8) as u8);
serialized[11 * i + 2] = ((coefficient3 & 0x3) as u8) << 6 | ((coefficient2 >> 5) as u8);
serialized[11 * i + 3] = ((coefficient3 >> 2) & 0xFF) as u8;
Expand Down
8 changes: 4 additions & 4 deletions tests/kyber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ macro_rules! impl_consistency {
}

fn modify_ciphertext(alg: Algorithm, rng: &mut (impl CryptoRng + Rng), ciphertext: Ct) -> Ct {
let mut encoded_ct = ciphertext.encode();
let mut raw_ciphertext = ciphertext.encode();

let mut random_u32: usize = rng.next_u32().try_into().unwrap();

Expand All @@ -48,10 +48,10 @@ fn modify_ciphertext(alg: Algorithm, rng: &mut (impl CryptoRng + Rng), ciphertex
}
random_u32 >>= 8;

let position = random_u32 % encoded_ct.len();
encoded_ct[position] ^= random_byte;
let position = random_u32 % raw_ciphertext.len();
raw_ciphertext[position] ^= random_byte;

Ct::decode(alg, &encoded_ct).unwrap()
Ct::decode(alg, &raw_ciphertext).unwrap()
}
macro_rules! impl_modified_ciphertext {
($name:ident, $alg:expr) => {
Expand Down

0 comments on commit d7ec486

Please sign in to comment.