Skip to content

Commit 97c046f

Browse files
authored
ctr: Add SAFETY comment (#278)
Suggested during review of `aes-gcm` for inclusion in Fuchsia OS: https://fuchsia-review.googlesource.com/c/fuchsia/+/585023
1 parent 338c078 commit 97c046f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ctr/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,11 @@ fn xor(buf: &mut [u8], key: &[u8]) {
241241
#[inline(always)]
242242
fn to_slice<C: BlockEncrypt>(blocks: &ParBlocks<C>) -> &[u8] {
243243
let blocks_len = C::BlockSize::to_usize() * C::ParBlocks::to_usize();
244+
// SAFETY:
245+
// - `blocks` is a `GenericArray<GenericArray<u8, C::BlockSize>, C::ParBlocks>`, and
246+
// so `blocks.as_ptr()` returns a pointer to the `&[GenericArray<u8, C::BlockSize>]`
247+
// slice represented by `blocks`.
248+
// - `GenericArray<T, N>` has the same layout as `[T; N]`.
249+
// - `[[u8; M]; N]` has the same layout as `[u8; M * N]`.
244250
unsafe { core::slice::from_raw_parts(blocks.as_ptr() as *const u8, blocks_len) }
245251
}

0 commit comments

Comments
 (0)