ascon: eliminate util module (#38)

Factors the `u8` <-> `u64` conversions to be inline
This commit is contained in:
Tony Arcieri 2023-02-25 16:36:54 -07:00 committed by GitHub
parent 6de759ac15
commit d50fca63d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 21 deletions

View File

@ -41,9 +41,7 @@ extern crate alloc;
#[cfg(feature = "alloc")]
pub mod aead;
mod util;
use crate::util::{u64_to_u8, u8_to_u64};
use core::convert::TryInto;
/// Key length.
const KEY_LEN: usize = 16;
@ -64,7 +62,11 @@ const B: usize = 8;
pub fn permutation(s: &mut [u8], start: usize, rounds: usize) {
let mut x = [0; 5];
let mut t = [0; 5];
u8_to_u64(s, &mut x);
#[allow(clippy::unwrap_used)]
for (i, b) in x.iter_mut().enumerate() {
*b = u64::from_be_bytes(s[(i * 8)..((i + 1) * 8)].try_into().unwrap());
}
for i in start as u64..(start + rounds) as u64 {
x[2] ^= ((0xfu64 - i) << 4) | i;
@ -104,7 +106,9 @@ pub fn permutation(s: &mut [u8], start: usize, rounds: usize) {
x[4] ^= x[4].rotate_right(7) ^ x[4].rotate_right(41);
}
u64_to_u8(&x, s);
for (i, &b) in x.iter().enumerate() {
s[(i * 8)..((i + 1) * 8)].copy_from_slice(&b.to_be_bytes())
}
}
/// Initialize Ascon permutation.

View File

@ -1,16 +0,0 @@
use core::convert::TryInto;
#[inline]
#[allow(clippy::unwrap_used)]
pub fn u8_to_u64(input: &[u8], output: &mut [u64]) {
for (i, b) in output.iter_mut().enumerate() {
*b = u64::from_be_bytes(input[(i * 8)..((i + 1) * 8)].try_into().unwrap());
}
}
#[inline]
pub fn u64_to_u8(input: &[u64], output: &mut [u8]) {
for (i, &b) in input.iter().enumerate() {
output[(i * 8)..((i + 1) * 8)].copy_from_slice(&b.to_be_bytes())
}
}