Skip to content

Commit

Permalink
aes: use const preconditions assert (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Feb 13, 2024
1 parent 3e1e83f commit 71f8585
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aes/src/armv8/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub unsafe fn expand_key<const L: usize, const N: usize>(key: &[u8; L]) -> [uint

// Sanity check, as this is required in order for the following line to be sound.
// We'd rather panic than exhibit undefined behavior.
assert!(mem::align_of::<uint8x16_t>() >= mem::align_of::<u32>());
let columns =
slice::from_raw_parts_mut(expanded_keys.as_mut_ptr() as *mut u32, N * BLOCK_WORDS);
const _: () = assert!(mem::align_of::<uint8x16_t>() >= mem::align_of::<u32>());
let keys_ptr: *mut u32 = expanded_keys.as_mut_ptr().cast();
let columns = slice::from_raw_parts_mut(keys_ptr, N * BLOCK_WORDS);

for (i, chunk) in key.chunks_exact(WORD_SIZE).enumerate() {
columns[i] = u32::from_ne_bytes(chunk.try_into().unwrap());
Expand Down

0 comments on commit 71f8585

Please sign in to comment.