Skip to content

Commit 6d80869

Browse files
coastalwhiteAmanieu
authored andcommitted
Add missing aes64im of RISC-V Zk extension
1 parent 51f2b1e commit 6d80869

File tree

1 file changed

+27
-0
lines changed
  • crates/core_arch/src/riscv64

1 file changed

+27
-0
lines changed

crates/core_arch/src/riscv64/zk.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ extern "unadjusted" {
2020
#[link_name = "llvm.riscv.aes64ks2"]
2121
fn _aes64ks2(rs1: i64, rs2: i64) -> i64;
2222

23+
#[link_name = "llvm.riscv.aes64im"]
24+
fn _aes64im(rs1: i64) -> i64;
25+
2326
#[link_name = "llvm.riscv.sha512sig0"]
2427
fn _sha512sig0(rs1: i64) -> i64;
2528

@@ -178,6 +181,30 @@ pub unsafe fn aes64ks2(rs1: u64, rs2: u64) -> u64 {
178181
_aes64ks2(rs1 as i64, rs2 as i64) as u64
179182
}
180183

184+
/// This instruction accelerates the inverse MixColumns step of the AES Block Cipher, and is used to aid creation of
185+
/// the decryption KeySchedule.
186+
///
187+
/// The instruction applies the inverse MixColumns transformation to two columns of the state array, packed
188+
/// into a single 64-bit register. It is used to create the inverse cipher KeySchedule, according to the equivalent
189+
/// inverse cipher construction in (Page 23, Section 5.3.5). This instruction must always be implemented
190+
/// such that its execution latency does not depend on the data being operated on.
191+
///
192+
/// Source: RISC-V Cryptography Extensions Volume I: Scalar & Entropy Source Instructions
193+
///
194+
/// Version: v1.0.1
195+
///
196+
/// Section: 3.9
197+
///
198+
/// # Safety
199+
///
200+
/// This function is safe to use if the `zkne` or `zknd` target feature is present.
201+
#[target_feature(enable = "zkne", enable = "zknd")]
202+
#[cfg_attr(test, assert_instr(aes64im))]
203+
#[inline]
204+
pub unsafe fn aes64im(rs1: u64) -> u64 {
205+
_aes64im(rs1 as i64) as u64
206+
}
207+
181208
/// Implements the Sigma0 transformation function as used in the SHA2-512 hash function \[49\]
182209
/// (Section 4.1.3).
183210
///

0 commit comments

Comments
 (0)