Skip to content

Commit

Permalink
Fix ML-KEM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneider-bensch committed Jun 11, 2024
1 parent 90dc277 commit 8fdf171
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions libcrux-ml-kem/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ macro_rules! impl_generic_struct {
// self.value.split_at(mid)
// }


/// The number of bytes.
pub const fn len() -> usize {
SIZE
Expand Down Expand Up @@ -137,8 +136,8 @@ mod index_impls {

/// An ML-KEM key pair
pub struct MlKemKeyPair<const PRIVATE_KEY_SIZE: usize, const PUBLIC_KEY_SIZE: usize> {
pub (crate) sk: MlKemPrivateKey<PRIVATE_KEY_SIZE>,
pub (crate) pk: MlKemPublicKey<PUBLIC_KEY_SIZE>,
pub(crate) sk: MlKemPrivateKey<PRIVATE_KEY_SIZE>,
pub(crate) pk: MlKemPublicKey<PUBLIC_KEY_SIZE>,
}

impl<const PRIVATE_KEY_SIZE: usize, const PUBLIC_KEY_SIZE: usize>
Expand Down
8 changes: 4 additions & 4 deletions libcrux-ml-kem/tests/self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn modify_ciphertext<const LEN: usize>(
}
random_u32 >>= 8;

let position = random_u32 % ciphertext.len();
let position = random_u32 % MlKemCiphertext::<LEN>::len();
ciphertext[position] ^= random_byte;

ciphertext
Expand Down Expand Up @@ -87,9 +87,9 @@ fn modify_secret_key<const LEN: usize>(
random_u32 >>= 8;

let position = if modify_implicit_rejection_value {
(raw_secret_key.len() - SHARED_SECRET_SIZE) + (random_u32 % SHARED_SECRET_SIZE)
(MlKemPrivateKey::<LEN>::len() - SHARED_SECRET_SIZE) + (random_u32 % SHARED_SECRET_SIZE)
} else {
random_u32 % (raw_secret_key.len() - SHARED_SECRET_SIZE)
random_u32 % (MlKemPrivateKey::<LEN>::len() - SHARED_SECRET_SIZE)
};

raw_secret_key[position] ^= random_byte;
Expand All @@ -101,7 +101,7 @@ fn compute_implicit_rejection_shared_secret<const CLEN: usize, const LEN: usize>
ciphertext: MlKemCiphertext<CLEN>,
secret_key: MlKemPrivateKey<LEN>,
) -> [u8; SHARED_SECRET_SIZE] {
let mut to_hash = secret_key[secret_key.len() - SHARED_SECRET_SIZE..].to_vec();
let mut to_hash = secret_key[MlKemPrivateKey::<LEN>::len() - SHARED_SECRET_SIZE..].to_vec();
to_hash.extend_from_slice(ciphertext.as_ref());

shake256(&to_hash)
Expand Down

0 comments on commit 8fdf171

Please sign in to comment.