Skip to content

Stabilize RISC-V Zk and Zb intrinsics - #2248

Open
TechnoPorg wants to merge 6 commits into
rust-lang:mainfrom
TechnoPorg:push-nlsqwkrlpsnq
Open

TechnoPorg wants to merge 6 commits into
rust-lang:mainfrom
TechnoPorg:push-nlsqwkrlpsnq

Conversation

@TechnoPorg

@TechnoPorg TechnoPorg commented Oct 9, 2026 •

Copy link
Copy Markdown

Stabilization report

Summary

These intrinsics allow using instructions from the RISC-V ratified scalar crypto extensions and bit manipulation extensions. This includes:

  • The AES block cipher extensions Zkne and Zknd
  • The SHA-2 extension Zknh
  • The bit manipulation extension Zbkb
  • The carry-less multiply extension Zbkc
  • The cross-bar permutation extension Zbkx
  • The SM4 block cipher extension Zksed
  • The SM3 hash function extension Zksh

These have the potential to significantly accelerate cryptographic operations on both RV32 and RV64 devices.

Tracking:

What isn't stabilized

Other RISC-V ratified extension intrinsics, such as the packed SIMD extension P.

Design

Answers to unresolved questions

From the tracking issue:

Use usize for riscv32 or riscv64 specific intrinsics or use u32 and u64 respectively?

The conclusion in rust-lang/rust#114544 from the libs team is that for this set of intrinsics, u32/u64 are preferable. This matches the way they are used by current nightly consumers and feels more appropriate given that these operate on data and not addresses.

Feedback

Nightly use

In all of these, u32/u64 are more ergonomic than usize.

Breaking changes

None.

History

Acknowledgments

Open items


No LLMs were used to write this PR.

@rustbot

rustbot commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @sayantn (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Amanieu, @adamgemmell, @davidtwco, @folkertdev, @sayantn
  • @Amanieu, @adamgemmell, @davidtwco, @folkertdev, @sayantn expanded to Amanieu, adamgemmell, davidtwco, folkertdev, sayantn
  • Random selection from Amanieu, adamgemmell, davidtwco, folkertdev, sayantn

@TechnoPorg

Copy link
Copy Markdown
Author

Whoops meant to open this against my fork... let me quickly write a stabilization report!

@TechnoPorg TechnoPorg changed the title CI test Stabilize RISC-V Zkn intrinsics Oct 9, 2026
@rustbot

rustbot commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Error: The feature shortcut is not enabled in this repository.
To enable it add its section in the triagebot.toml in the root of the repository.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@TechnoPorg TechnoPorg changed the title Stabilize RISC-V Zkn intrinsics Stabilize RISC-V Zk and Zb intrinsics Oct 9, 2026
@TechnoPorg
TechnoPorg force-pushed the push-nlsqwkrlpsnq branch 2 times, most recently from 4c5b583 to ce1255a Compare October 9, 2026 13:38
Comment thread crates/core_arch/src/riscv32/zk.rs Outdated
/// The `BS` parameter is expected to be a constant value and only the bottom 2 bits of `bs` are
/// used.
#[target_feature(enable = "zkne")]
#[rustc_legacy_const_generics(2)]

@tgross35 tgross35 Oct 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also yes, this should be removed from stabilized intrinsics rust-lang/rust#149654. You could also put up a separate PR removing them from all RISC-V stdarch, if interested. (Or even more if there are arches aside from arm, aarch64, and x86 that use it).

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Opened #2254

Comment thread crates/core_arch/src/riscv32/zk.rs Outdated
Comment thread crates/core_arch/src/riscv64/mod.rs
@sayantn

sayantn commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

#2255

@rustbot reroll

@rustbot rustbot assigned folkertdev and unassigned sayantn Oct 13, 2026
@tgross35

Copy link
Copy Markdown
Member

@rustbot blocked

Based on rust-lang/rust#114544 (comment), we'd like to change to match the C API first. We should make sure there is fuzz testing against C intrinsics as mentioned in #2221 (comment).

@rustbot

rustbot commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Error: The feature shortcut is not enabled in this repository.
To enable it add its section in the triagebot.toml in the root of the repository.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@TechnoPorg

Copy link
Copy Markdown
Author

Based on rust-lang/rust#114544 (comment), we'd like to change to match the C API first.

I've just updated #2247 to match the C API.

We should make sure there is fuzz testing against C intrinsics as mentioned in #2221 (comment).

That seems reasonable. I can start on a branch for it now, but I'd ideally like to wait until #2247 and #2254 are merged so as to not be stuck in an endless cycle of rebases.

Error: The feature shortcut is not enabled in this repository.

I tried the same thing 😂

This branch has not been deployed

No deployments
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.

5 participants