Skip to content

Commit

Permalink
Fix dcf prg
Browse files Browse the repository at this point in the history
Fix a misuse of zip.
Add a test for the mistake.
  • Loading branch information
myl7 committed Apr 10, 2024
1 parent d28a4d2 commit abc9540
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/dcf/prg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ impl<const LAMBDA: usize, const N: usize> Prg<LAMBDA> for Aes256HirosePrg<LAMBDA
let mut result_buf0 = [[0; LAMBDA]; 2];
let mut result_buf1 = [[0; LAMBDA]; 2];
let mut out_blocks = [GenericArray::default(); 2];
(0..2usize).zip(0..LAMBDA / 16).for_each(|(i, j)| {
let in_block0 = GenericArray::from_slice(&seed[j * 16..(j + 1) * 16]);
let in_block1 = GenericArray::from_slice(&seed_p[j * 16..(j + 1) * 16]);
self.ciphers[i * 16 + j]
.encrypt_blocks_b2b(&[*in_block0, *in_block1], &mut out_blocks)
.unwrap();
result_buf0[i][j * 16..(j + 1) * 16].copy_from_slice(out_blocks[0].as_ref());
result_buf1[i][j * 16..(j + 1) * 16].copy_from_slice(out_blocks[1].as_ref());
(0..2usize).for_each(|i| {
(0..LAMBDA / 16).for_each(|j| {
let in_block0 = GenericArray::from_slice(&seed[j * 16..(j + 1) * 16]);
let in_block1 = GenericArray::from_slice(&seed_p[j * 16..(j + 1) * 16]);
self.ciphers[i * (LAMBDA / 16) + j]
.encrypt_blocks_b2b(&[*in_block0, *in_block1], &mut out_blocks)
.unwrap();
result_buf0[i][j * 16..(j + 1) * 16].copy_from_slice(out_blocks[0].as_ref());
result_buf1[i][j * 16..(j + 1) * 16].copy_from_slice(out_blocks[1].as_ref());
});
});
result_buf0
.iter_mut()
Expand Down Expand Up @@ -144,6 +146,8 @@ mod tests {
assert_ne!(out[i].1, [0; 16]);
assert_ne!(xor(&[&out[i].0, SEED]), [0; 16]);
assert_ne!(xor(&[&out[i].1, SEED]), [0; 16]);
assert_ne!(xor(&[&out[i].0, SEED]), [0xff; 16]);
assert_ne!(xor(&[&out[i].1, SEED]), [0xff; 16]);
});
}
}

0 comments on commit abc9540

Please sign in to comment.