Skip to content

Conversation

jschneider-bensch
Copy link
Collaborator

@jschneider-bensch jschneider-bensch commented Sep 23, 2025

Doing an initial review here, before we get started on cleanup (cf. #1159, #1166).

@jschneider-bensch jschneider-bensch added the do-not-merge Don't merge this PR label Sep 23, 2025
Copy link
Collaborator Author

@jschneider-bensch jschneider-bensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a bunch of comments.
There was one spot where I wasn't sure if a debug_assert bound is correct, but other than that i didn't find any issues.

#[inline]
fn aes_ctr_xor_blocks(&self, ctr: u32, input: &[u8], out: &mut [u8]) {
debug_assert!(input.len() == out.len() && input.len().is_multiple_of(AES_BLOCK_LEN));
debug_assert!(input.len() / AES_BLOCK_LEN < u32::MAX as usize);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this bound be one less? If input.len() / AES_BLOCK_LEN == u32::MAX - 1 and we start with ctr == 2 then we'll wrap to 0 below and we'll repeat the initial key block, or did I get something wrong?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that sounds right. I add this as a comment and update the bound. But really we should never call this function this way as this assert won't be there in release builds. So we should check that we check the length correctly before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't the AES instructions require [target_feature(enable = "aes")] as well as the neon target feature?

I think it works because in lib.rs we also guard this implementation as a whole with #[cfg(all(target_arch = "aarch64", target_feature = "aes"))].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment as well. We don't need to enable any features on arm.
I forgot to update the include here to the feature style that we usually use. Both is fine, it's just a little more consistent this way and allows cross compilation.

}

#[cfg(feature = "simd256")]
pub mod x64 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I like this style more than the NEON version, where every individual function in platform::neon has to be marked unsafe if it uses an intrinsic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really need the feature on Arm, there are different reasons here. But I'll revert the other style anyway.

On x64/x86 we have to tell the compiler about the CPU features like AES. That's why we need the annotations here. In the case of arm we can add hardware features to functions to avoid making certain intrinsic calls unsafe. But they are not needed for the compiler.

However, hax is still on an old rustc version that can't do the feature flags to avoid unsafe. And this would also bump our general MSRV quite a bit. And I didn't really like the ergonomics yet. I think we need to play with that a little more.

But because of all of that I'll change back to making all the arm intrinsics calls unsafe in the intrinsics crate and drop the feature flags.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, this should probably be named x64.


#[inline]
pub fn _vaesmcq_u8(data: uint8x16_t) -> uint8x16_t {
unsafe { vaesmcq_u8(data) }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the [target_feature(enable = "aes")] style not supported?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not all intrinsics support that yet. But see the other comment. I'm reverting to this style for now again anyway.

@jschneider-bensch
Copy link
Collaborator Author

Closing this in favor of #1185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge Don't merge this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants