ChaCha20: Use ArraySplitMap
to construct Iv
.
This is a step towards eliminating the `unsafe` in `chunks_fixed()`.
This commit is contained in:
parent
ff3febd530
commit
32f209e0fd
@ -193,8 +193,7 @@ pub struct Iv([u32; 4]);
|
||||
|
||||
impl Iv {
|
||||
fn assume_unique_for_key(value: [u8; 16]) -> Self {
|
||||
let value: &[[u8; 4]; 4] = value.chunks_fixed();
|
||||
Self(value.map(u32::from_le_bytes))
|
||||
Self(value.array_split_map(u32::from_le_bytes))
|
||||
}
|
||||
|
||||
fn into_counter_for_single_block_less_safe(self) -> Counter {
|
||||
|
@ -27,3 +27,16 @@ impl<I, O> ArraySplitMap<I, O, 4, 3> for [I; 12] {
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, O> ArraySplitMap<I, O, 4, 4> for [I; 16] {
|
||||
#[inline]
|
||||
fn array_split_map(self, f: impl Fn([I; 4]) -> O) -> [O; 4] {
|
||||
let [a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3] = self;
|
||||
[
|
||||
f([a0, a1, a2, a3]),
|
||||
f([b0, b1, b2, b3]),
|
||||
f([c0, c1, c2, c3]),
|
||||
f([d0, d1, d2, d3]),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ macro_rules! define_chunks_fixed {
|
||||
}
|
||||
|
||||
// Sorted by the first value, then the second value.
|
||||
define_chunks_fixed!(16, 4);
|
||||
define_chunks_fixed!(16, 8);
|
||||
define_chunks_fixed!(32, 4);
|
||||
define_chunks_fixed!(64, 32);
|
||||
|
Loading…
x
Reference in New Issue
Block a user