Skip to content

Commit c485c85

Browse files
committed
aes internals: Make Rounds an enum.
1 parent 738b5db commit c485c85

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/aead/aes/ffi.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(in super::super) struct Counter(pub(super) [u8; BLOCK_LEN]);
3333
#[derive(Clone, Copy)]
3434
pub(super) struct AES_KEY {
3535
rd_key: RdKeys,
36-
rounds: Rounds,
36+
rounds: c_uint,
3737
}
3838

3939
#[derive(Clone, Copy)]
@@ -43,18 +43,22 @@ union RdKeys {
4343
aes256: Aes256RoundKeys,
4444
}
4545

46-
pub(super) type Aes128RoundKeys = [RdKey; AES_128_ROUNDS_PLUS_1];
47-
pub(super) type Aes256RoundKeys = [RdKey; AES_256_ROUNDS_PLUS_1];
46+
pub(super) type Aes128RoundKeys = [RdKey; Rounds::Aes128.into_usize() + 1];
47+
pub(super) type Aes256RoundKeys = [RdKey; Rounds::Aes256.into_usize() + 1];
4848

4949
pub type RdKey = [u32; 4];
5050

51-
pub type Rounds = c_uint;
52-
53-
pub(super) const AES_128_ROUNDS_PLUS_1: usize = (AES_128_ROUNDS as usize) + 1;
54-
pub(super) const AES_256_ROUNDS_PLUS_1: usize = (AES_256_ROUNDS as usize) + 1;
51+
#[repr(u32)]
52+
pub enum Rounds {
53+
Aes128 = 10,
54+
Aes256 = 14,
55+
}
5556

56-
pub const AES_128_ROUNDS: Rounds = 10;
57-
pub const AES_256_ROUNDS: Rounds = 14;
57+
impl Rounds {
58+
const fn into_usize(self) -> usize {
59+
self as usize
60+
}
61+
}
5862

5963
impl KeyBytes<'_> {
6064
pub(super) fn as_user_key_and_bits(&self) -> (*const u8, KeyBitLength) {

src/aead/aes/hw.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ impl Key {
5454
#[cfg(all(target_arch = "aarch64", target_endian = "little"))]
5555
pub(in super::super) fn rd_keys_and_rounds(&self) -> (*const ffi::RdKey, ffi::Rounds) {
5656
match self {
57-
Key::Aes128(rd_keys) => (rd_keys.as_ptr(), ffi::AES_128_ROUNDS),
58-
Key::Aes256(rd_keys) => (rd_keys.as_ptr(), ffi::AES_256_ROUNDS),
57+
Key::Aes128(rd_keys) => (rd_keys.as_ptr(), ffi::Rounds::Aes128),
58+
Key::Aes256(rd_keys) => (rd_keys.as_ptr(), ffi::Rounds::Aes256),
5959
}
6060
}
6161
}

src/aead/aes/vp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ impl EncryptCtr32 for Key {
136136
fn ctr32_encrypt_within(&self, in_out: Overlapping<'_>, ctr: &mut Counter) {
137137
prefixed_extern_ctr32_encrypt_blocks_with_rd_keys! { vpaes_ctr32_encrypt_blocks }
138138
let (rd_keys, rounds) = match self {
139-
Self::Aes128(rd_keys) => (rd_keys.as_ptr(), ffi::AES_128_ROUNDS),
140-
Self::Aes256(rd_keys) => (rd_keys.as_ptr(), ffi::AES_256_ROUNDS),
139+
Self::Aes128(rd_keys) => (rd_keys.as_ptr(), ffi::Rounds::Aes128),
140+
Self::Aes256(rd_keys) => (rd_keys.as_ptr(), ffi::Rounds::Aes256),
141141
};
142142
unsafe {
143143
ffi::ctr32_encrypt_blocks(in_out, ctr, rd_keys, rounds, vpaes_ctr32_encrypt_blocks)

0 commit comments

Comments
 (0)