Skip to content

Commit

Permalink
aes_gcm: Prefer integrated implementatoins, avoid inlining fallbacks.
Browse files Browse the repository at this point in the history
The `#[inline(always)]` on `open_strided` was just a mistake.

But, even correcting that, the compiler won't structure `open()` and
`seal()` in the expected way. With these changes, the integrated
implementations will get inlined (as far as possible) and the
compiler will be biased towards assuming they will be used.
  • Loading branch information
briansmith committed Jun 23, 2024
1 parent 525047a commit 6e398d9
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/aead/aes_gcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,26 @@ pub(super) fn seal(
}
}

#[cfg_attr(
any(
all(
any(target_arch = "aarch64", target_arch = "arm"),
target_feature = "neon"
),
all(
any(target_arch = "x86", target_arch = "x86_64"),
target_feature = "sse"
)
),
inline(never)
)]
#[cfg_attr(
any(
all(target_arch = "aarch64", target_feature = "neon"),
all(target_arch = "x86_64", target_feature = "sse")
),
cold
)]
fn seal_strided<A: aes::EncryptBlock + aes::EncryptCtr32, G: gcm::UpdateBlocks + gcm::Gmult>(
Combo { aes_key, gcm_key }: &Combo<A, G>,
aad: Aad<&[u8]>,
Expand Down Expand Up @@ -392,7 +412,26 @@ pub(super) fn open(
}
}

#[inline(always)]
#[cfg_attr(
any(
all(
any(target_arch = "aarch64", target_arch = "arm"),
target_feature = "neon"
),
all(
any(target_arch = "x86", target_arch = "x86_64"),
target_feature = "sse"
)
),
inline(never)
)]
#[cfg_attr(
any(
all(target_arch = "aarch64", target_feature = "neon"),
all(target_arch = "x86_64", target_feature = "sse")
),
cold
)]
fn open_strided<A: aes::EncryptBlock + aes::EncryptCtr32, G: gcm::UpdateBlocks + gcm::Gmult>(
Combo { aes_key, gcm_key }: &Combo<A, G>,
aad: Aad<&[u8]>,
Expand Down

0 comments on commit 6e398d9

Please sign in to comment.