Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AES backend for riscv64 using Zkned scalar crypto extensions #397

Closed
wants to merge 2 commits into from
Closed

Implement AES backend for riscv64 using Zkned scalar crypto extensions #397

wants to merge 2 commits into from

Conversation

silvanshade
Copy link
Contributor

@silvanshade silvanshade commented Jan 10, 2024

This PR implements AES for riscv64 using the zkned scalar crypto extensions.

Some comments:

This will require nightly to build since the riscv64 intrinsics are unstable. However, it should be enough to just feature-gate on the respective riscv64 extensions, since those are only available on nightly.

Auto-detection of zkne and zknd is currently problematic.

It's possible to detect them (although I haven't tried that it actually works) with std::arch::is_riscv_feature_detected but this requires std and also requires the feature stdsimd (unstable).

The approach used by cpufeatures using libc::getauxval(libc::AT_HWCAP) won't work for riscv64 either. However, there is a new Linux syscall that exposes some riscv64 features: [https://www.kernel.org/doc/Documentation/riscv/hwprobe.rst](riscv_hwprobe).

Unfortunately, it doesn't expose the zkne or zknd features yet, although it looks like it is supposed to eventually, based on this code: https://github.com/clementleger/hwprobe_dump/blob/main/hwprobe.h

Hence, the approach I used here, where the backend is used if target_arch = "riscv64" and zkne and zknd target features are enabled.

I've opted not to add the hazmat module for riscv64 since supporting that is a little more complicated for riscv64 due to how the intrinsics work and how 1, 1.5, or 2 rounds are processed at a time depending on the key length.

Also, I don't have useful benchmarks since I don't have any riscv64 hardware with these extensions. However, the implementation produces the correct output and passes the tests when run with QEMU 8.0.4 on Ubuntu 23.10.

Regarding the CI config, I had some difficulty getting things to build and run properly with cross, and in any case a more recent QEMU is needed for the riscv64 extensions used here, so I used a custom docker image.

EDIT: Marking as draft again since I'm going to try and implement the vector version also.

@silvanshade silvanshade marked this pull request as ready for review January 12, 2024 06:56
@silvanshade silvanshade marked this pull request as draft January 13, 2024 16:39
@silvanshade silvanshade deleted the feature/aes-riscv64-zkned branch January 21, 2024 19:56
@tarcieri
Copy link
Member

Why did you close this?

@silvanshade
Copy link
Contributor Author

Oops, I was trying to rename the branch in my local repo and guess it closed this automatically instead of reflecting the update.

I'll just re-open with the new branch though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants