From 1826c9a6befc9c11ca4e2b49b8e0b5cb429357f7 Mon Sep 17 00:00:00 2001 From: usamoi Date: Sat, 15 Feb 2025 15:33:21 +0800 Subject: [PATCH] mark riscv intrinsics as safe --- crates/core_arch/src/riscv32/zk.rs | 96 +++++++------------------ crates/core_arch/src/riscv64/zk.rs | 88 ++++++----------------- crates/core_arch/src/riscv_shared/zb.rs | 40 ++++------- crates/core_arch/src/riscv_shared/zk.rs | 84 ++++++---------------- 4 files changed, 80 insertions(+), 228 deletions(-) diff --git a/crates/core_arch/src/riscv32/zk.rs b/crates/core_arch/src/riscv32/zk.rs index 6ea3793ce9..054bcfe955 100644 --- a/crates/core_arch/src/riscv32/zk.rs +++ b/crates/core_arch/src/riscv32/zk.rs @@ -56,20 +56,16 @@ unsafe extern "unadjusted" { /// /// The `BS` parameter is expected to be a constant value and only the bottom 2 bits of `bs` are /// used. -/// -/// # Safety -/// -/// This function is safe to use if the `zkne` target feature is present. #[target_feature(enable = "zkne")] #[rustc_legacy_const_generics(2)] // See #1464 // #[cfg_attr(test, assert_instr(aes32esi, BS = 0))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes32esi(rs1: u32, rs2: u32) -> u32 { +pub fn aes32esi(rs1: u32, rs2: u32) -> u32 { static_assert!(BS < 4); - _aes32esi(rs1 as i32, rs2 as i32, BS as i32) as u32 + unsafe { _aes32esi(rs1 as i32, rs2 as i32, BS as i32) as u32 } } /// AES middle round encryption instruction for RV32 with. @@ -89,20 +85,16 @@ pub unsafe fn aes32esi(rs1: u32, rs2: u32) -> u32 { /// /// The `bs` parameter is expected to be a constant value and only the bottom 2 bits of `bs` are /// used. -/// -/// # Safety -/// -/// This function is safe to use if the `zkne` target feature is present. #[target_feature(enable = "zkne")] #[rustc_legacy_const_generics(2)] // See #1464 // #[cfg_attr(test, assert_instr(aes32esmi, BS = 0))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes32esmi(rs1: u32, rs2: u32) -> u32 { +pub fn aes32esmi(rs1: u32, rs2: u32) -> u32 { static_assert!(BS < 4); - _aes32esmi(rs1 as i32, rs2 as i32, BS as i32) as u32 + unsafe { _aes32esmi(rs1 as i32, rs2 as i32, BS as i32) as u32 } } /// AES final round decryption instruction for RV32. @@ -121,20 +113,16 @@ pub unsafe fn aes32esmi(rs1: u32, rs2: u32) -> u32 { /// /// The `BS` parameter is expected to be a constant value and only the bottom 2 bits of `bs` are /// used. -/// -/// # Safety -/// -/// This function is safe to use if the `zknd` target feature is present. #[target_feature(enable = "zknd")] #[rustc_legacy_const_generics(2)] // See #1464 // #[cfg_attr(test, assert_instr(aes32dsi, BS = 0))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes32dsi(rs1: u32, rs2: u32) -> u32 { +pub fn aes32dsi(rs1: u32, rs2: u32) -> u32 { static_assert!(BS < 4); - _aes32dsi(rs1 as i32, rs2 as i32, BS as i32) as u32 + unsafe { _aes32dsi(rs1 as i32, rs2 as i32, BS as i32) as u32 } } /// AES middle round decryption instruction for RV32. @@ -154,20 +142,16 @@ pub unsafe fn aes32dsi(rs1: u32, rs2: u32) -> u32 { /// /// The `BS` parameter is expected to be a constant value and only the bottom 2 bits of `bs` are /// used. -/// -/// # Safety -/// -/// This function is safe to use if the `zknd` target feature is present. #[target_feature(enable = "zknd")] #[rustc_legacy_const_generics(2)] // See #1464 // #[cfg_attr(test, assert_instr(aes32dsmi, BS = 0))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes32dsmi(rs1: u32, rs2: u32) -> u32 { +pub fn aes32dsmi(rs1: u32, rs2: u32) -> u32 { static_assert!(BS < 4); - _aes32dsmi(rs1 as i32, rs2 as i32, BS as i32) as u32 + unsafe { _aes32dsmi(rs1 as i32, rs2 as i32, BS as i32) as u32 } } /// Place upper/lower halves of the source register into odd/even bits of the destination @@ -183,17 +167,13 @@ pub unsafe fn aes32dsmi(rs1: u32, rs2: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.49 -/// -/// # Safety -/// -/// This function is safe to use if the `zbkb` target feature is present. #[target_feature(enable = "zbkb")] // See #1464 // #[cfg_attr(test, assert_instr(zip))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn zip(rs: u32) -> u32 { - _zip(rs as i32) as u32 +pub fn zip(rs: u32) -> u32 { + unsafe { _zip(rs as i32) as u32 } } /// Place odd and even bits of the source word into upper/lower halves of the destination. @@ -207,16 +187,12 @@ pub unsafe fn zip(rs: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.45 -/// -/// # Safety -/// -/// This function is safe to use if the `zbkb` target feature is present. #[target_feature(enable = "zbkb")] #[cfg_attr(test, assert_instr(unzip))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn unzip(rs: u32) -> u32 { - _unzip(rs as i32) as u32 +pub fn unzip(rs: u32) -> u32 { + unsafe { _unzip(rs as i32) as u32 } } /// Implements the high half of the Sigma0 transformation, as used in the SHA2-512 hash @@ -233,17 +209,13 @@ pub unsafe fn unzip(rs: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.31 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] // See #1464 // #[cfg_attr(test, assert_instr(sha512sig0h))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sig0h(rs1: u32, rs2: u32) -> u32 { - _sha512sig0h(rs1 as i32, rs2 as i32) as u32 +pub fn sha512sig0h(rs1: u32, rs2: u32) -> u32 { + unsafe { _sha512sig0h(rs1 as i32, rs2 as i32) as u32 } } /// Implements the low half of the Sigma0 transformation, as used in the SHA2-512 hash function @@ -260,17 +232,13 @@ pub unsafe fn sha512sig0h(rs1: u32, rs2: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.32 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] // See #1464 // #[cfg_attr(test, assert_instr(sha512sig0l))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sig0l(rs1: u32, rs2: u32) -> u32 { - _sha512sig0l(rs1 as i32, rs2 as i32) as u32 +pub fn sha512sig0l(rs1: u32, rs2: u32) -> u32 { + unsafe { _sha512sig0l(rs1 as i32, rs2 as i32) as u32 } } /// Implements the high half of the Sigma1 transformation, as used in the SHA2-512 hash @@ -287,17 +255,13 @@ pub unsafe fn sha512sig0l(rs1: u32, rs2: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.33 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] // See #1464 // #[cfg_attr(test, assert_instr(sha512sig1h))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sig1h(rs1: u32, rs2: u32) -> u32 { - _sha512sig1h(rs1 as i32, rs2 as i32) as u32 +pub fn sha512sig1h(rs1: u32, rs2: u32) -> u32 { + unsafe { _sha512sig1h(rs1 as i32, rs2 as i32) as u32 } } /// Implements the low half of the Sigma1 transformation, as used in the SHA2-512 hash function @@ -314,16 +278,12 @@ pub unsafe fn sha512sig1h(rs1: u32, rs2: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.34 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha512sig1l))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sig1l(rs1: u32, rs2: u32) -> u32 { - _sha512sig1l(rs1 as i32, rs2 as i32) as u32 +pub fn sha512sig1l(rs1: u32, rs2: u32) -> u32 { + unsafe { _sha512sig1l(rs1 as i32, rs2 as i32) as u32 } } /// Implements the Sum0 transformation, as used in the SHA2-512 hash function \[49\] (Section @@ -339,17 +299,13 @@ pub unsafe fn sha512sig1l(rs1: u32, rs2: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.35 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] // See #1464 // #[cfg_attr(test, assert_instr(sha512sum0r))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sum0r(rs1: u32, rs2: u32) -> u32 { - _sha512sum0r(rs1 as i32, rs2 as i32) as u32 +pub fn sha512sum0r(rs1: u32, rs2: u32) -> u32 { + unsafe { _sha512sum0r(rs1 as i32, rs2 as i32) as u32 } } /// Implements the Sum1 transformation, as used in the SHA2-512 hash function \[49\] (Section @@ -365,15 +321,11 @@ pub unsafe fn sha512sum0r(rs1: u32, rs2: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.36 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] // See #1464 // #[cfg_attr(test, assert_instr(sha512sum1r))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sum1r(rs1: u32, rs2: u32) -> u32 { - _sha512sum1r(rs1 as i32, rs2 as i32) as u32 +pub fn sha512sum1r(rs1: u32, rs2: u32) -> u32 { + unsafe { _sha512sum1r(rs1 as i32, rs2 as i32) as u32 } } diff --git a/crates/core_arch/src/riscv64/zk.rs b/crates/core_arch/src/riscv64/zk.rs index 37ee65876f..c6af750bbc 100644 --- a/crates/core_arch/src/riscv64/zk.rs +++ b/crates/core_arch/src/riscv64/zk.rs @@ -48,16 +48,12 @@ unsafe extern "unadjusted" { /// Version: v1.0.1 /// /// Section: 3.7 -/// -/// # Safety -/// -/// This function is safe to use if the `zkne` target feature is present. #[target_feature(enable = "zkne")] #[cfg_attr(test, assert_instr(aes64es))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes64es(rs1: u64, rs2: u64) -> u64 { - _aes64es(rs1 as i64, rs2 as i64) as u64 +pub fn aes64es(rs1: u64, rs2: u64) -> u64 { + unsafe { _aes64es(rs1 as i64, rs2 as i64) as u64 } } /// AES middle round encryption instruction for RV64. @@ -72,16 +68,12 @@ pub unsafe fn aes64es(rs1: u64, rs2: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.8 -/// -/// # Safety -/// -/// This function is safe to use if the `zkne` target feature is present. #[target_feature(enable = "zkne")] #[cfg_attr(test, assert_instr(aes64esm))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes64esm(rs1: u64, rs2: u64) -> u64 { - _aes64esm(rs1 as i64, rs2 as i64) as u64 +pub fn aes64esm(rs1: u64, rs2: u64) -> u64 { + unsafe { _aes64esm(rs1 as i64, rs2 as i64) as u64 } } /// AES final round decryption instruction for RV64. @@ -96,16 +88,12 @@ pub unsafe fn aes64esm(rs1: u64, rs2: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.5 -/// -/// # Safety -/// -/// This function is safe to use if the `zknd` target feature is present. #[target_feature(enable = "zknd")] #[cfg_attr(test, assert_instr(aes64ds))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes64ds(rs1: u64, rs2: u64) -> u64 { - _aes64ds(rs1 as i64, rs2 as i64) as u64 +pub fn aes64ds(rs1: u64, rs2: u64) -> u64 { + unsafe { _aes64ds(rs1 as i64, rs2 as i64) as u64 } } /// AES middle round decryption instruction for RV64. @@ -120,16 +108,12 @@ pub unsafe fn aes64ds(rs1: u64, rs2: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.6 -/// -/// # Safety -/// -/// This function is safe to use if the `zknd` target feature is present. #[target_feature(enable = "zknd")] #[cfg_attr(test, assert_instr(aes64dsm))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes64dsm(rs1: u64, rs2: u64) -> u64 { - _aes64dsm(rs1 as i64, rs2 as i64) as u64 +pub fn aes64dsm(rs1: u64, rs2: u64) -> u64 { + unsafe { _aes64dsm(rs1 as i64, rs2 as i64) as u64 } } /// This instruction implements part of the KeySchedule operation for the AES Block cipher @@ -149,19 +133,15 @@ pub unsafe fn aes64dsm(rs1: u64, rs2: u64) -> u64 { /// # Note /// /// The `RNUM` parameter is expected to be a constant value inside the range of `0..=10`. -/// -/// # Safety -/// -/// This function is safe to use if the `zkne` or `zknd` target feature is present. #[target_feature(enable = "zkne", enable = "zknd")] #[rustc_legacy_const_generics(1)] #[cfg_attr(test, assert_instr(aes64ks1i, RNUM = 0))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes64ks1i(rs1: u64) -> u64 { +pub fn aes64ks1i(rs1: u64) -> u64 { static_assert!(RNUM <= 10); - _aes64ks1i(rs1 as i64, RNUM as i32) as u64 + unsafe { _aes64ks1i(rs1 as i64, RNUM as i32) as u64 } } /// This instruction implements part of the KeySchedule operation for the AES Block cipher. @@ -175,16 +155,12 @@ pub unsafe fn aes64ks1i(rs1: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.11 -/// -/// # Safety -/// -/// This function is safe to use if the `zkne` or `zknd` target feature is present. #[target_feature(enable = "zkne", enable = "zknd")] #[cfg_attr(test, assert_instr(aes64ks2))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes64ks2(rs1: u64, rs2: u64) -> u64 { - _aes64ks2(rs1 as i64, rs2 as i64) as u64 +pub fn aes64ks2(rs1: u64, rs2: u64) -> u64 { + unsafe { _aes64ks2(rs1 as i64, rs2 as i64) as u64 } } /// This instruction accelerates the inverse MixColumns step of the AES Block Cipher, and is used to aid creation of @@ -200,16 +176,12 @@ pub unsafe fn aes64ks2(rs1: u64, rs2: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.9 -/// -/// # Safety -/// -/// This function is safe to use if the `zkne` or `zknd` target feature is present. #[target_feature(enable = "zkne", enable = "zknd")] #[cfg_attr(test, assert_instr(aes64im))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn aes64im(rs1: u64) -> u64 { - _aes64im(rs1 as i64) as u64 +pub fn aes64im(rs1: u64) -> u64 { + unsafe { _aes64im(rs1 as i64) as u64 } } /// Implements the Sigma0 transformation function as used in the SHA2-512 hash function \[49\] @@ -224,16 +196,12 @@ pub unsafe fn aes64im(rs1: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.37 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha512sig0))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sig0(rs1: u64) -> u64 { - _sha512sig0(rs1 as i64) as u64 +pub fn sha512sig0(rs1: u64) -> u64 { + unsafe { _sha512sig0(rs1 as i64) as u64 } } /// Implements the Sigma1 transformation function as used in the SHA2-512 hash function \[49\] @@ -248,16 +216,12 @@ pub unsafe fn sha512sig0(rs1: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.38 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha512sig1))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sig1(rs1: u64) -> u64 { - _sha512sig1(rs1 as i64) as u64 +pub fn sha512sig1(rs1: u64) -> u64 { + unsafe { _sha512sig1(rs1 as i64) as u64 } } /// Implements the Sum0 transformation function as used in the SHA2-512 hash function \[49\] @@ -272,16 +236,12 @@ pub unsafe fn sha512sig1(rs1: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.39 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha512sum0))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sum0(rs1: u64) -> u64 { - _sha512sum0(rs1 as i64) as u64 +pub fn sha512sum0(rs1: u64) -> u64 { + unsafe { _sha512sum0(rs1 as i64) as u64 } } /// Implements the Sum1 transformation function as used in the SHA2-512 hash function \[49\] @@ -296,14 +256,10 @@ pub unsafe fn sha512sum0(rs1: u64) -> u64 { /// Version: v1.0.1 /// /// Section: 3.40 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha512sum1))] #[inline] #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] -pub unsafe fn sha512sum1(rs1: u64) -> u64 { - _sha512sum1(rs1 as i64) as u64 +pub fn sha512sum1(rs1: u64) -> u64 { + unsafe { _sha512sum1(rs1 as i64) as u64 } } diff --git a/crates/core_arch/src/riscv_shared/zb.rs b/crates/core_arch/src/riscv_shared/zb.rs index d7ae05d46d..9472e3c8be 100644 --- a/crates/core_arch/src/riscv_shared/zb.rs +++ b/crates/core_arch/src/riscv_shared/zb.rs @@ -42,22 +42,18 @@ unsafe extern "unadjusted" { /// Version: v1.0.0 /// /// Section: 2.24 -/// -/// # Safety -/// -/// This function is safe to use if the `zbb` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zbb")] #[cfg_attr(test, assert_instr(orc.b))] #[inline] -pub unsafe fn orc_b(rs: usize) -> usize { +pub fn orc_b(rs: usize) -> usize { #[cfg(target_arch = "riscv32")] - { + unsafe { _orc_b_32(rs as i32) as usize } #[cfg(target_arch = "riscv64")] - { + unsafe { _orc_b_64(rs as i64) as usize } } @@ -71,22 +67,18 @@ pub unsafe fn orc_b(rs: usize) -> usize { /// Version: v1.0.0 /// /// Section: 2.11 -/// -/// # Safety -/// -/// This function is safe to use if the `zbc` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zbc")] #[cfg_attr(test, assert_instr(clmul))] #[inline] -pub unsafe fn clmul(rs1: usize, rs2: usize) -> usize { +pub fn clmul(rs1: usize, rs2: usize) -> usize { #[cfg(target_arch = "riscv32")] - { + unsafe { _clmul_32(rs1 as i32, rs2 as i32) as usize } #[cfg(target_arch = "riscv64")] - { + unsafe { _clmul_64(rs1 as i64, rs2 as i64) as usize } } @@ -100,22 +92,18 @@ pub unsafe fn clmul(rs1: usize, rs2: usize) -> usize { /// Version: v1.0.0 /// /// Section: 2.12 -/// -/// # Safety -/// -/// This function is safe to use if the `zbc` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zbc")] #[cfg_attr(test, assert_instr(clmulh))] #[inline] -pub unsafe fn clmulh(rs1: usize, rs2: usize) -> usize { +pub fn clmulh(rs1: usize, rs2: usize) -> usize { #[cfg(target_arch = "riscv32")] - { + unsafe { _clmulh_32(rs1 as i32, rs2 as i32) as usize } #[cfg(target_arch = "riscv64")] - { + unsafe { _clmulh_64(rs1 as i64, rs2 as i64) as usize } } @@ -129,22 +117,18 @@ pub unsafe fn clmulh(rs1: usize, rs2: usize) -> usize { /// Version: v1.0.0 /// /// Section: 2.13 -/// -/// # Safety -/// -/// This function is safe to use if the `zbc` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zbc")] #[cfg_attr(test, assert_instr(clmulr))] #[inline] -pub unsafe fn clmulr(rs1: usize, rs2: usize) -> usize { +pub fn clmulr(rs1: usize, rs2: usize) -> usize { #[cfg(target_arch = "riscv32")] - { + unsafe { _clmulr_32(rs1 as i32, rs2 as i32) as usize } #[cfg(target_arch = "riscv64")] - { + unsafe { _clmulr_64(rs1 as i64, rs2 as i64) as usize } } diff --git a/crates/core_arch/src/riscv_shared/zk.rs b/crates/core_arch/src/riscv_shared/zk.rs index f333c826c5..b1e633d170 100644 --- a/crates/core_arch/src/riscv_shared/zk.rs +++ b/crates/core_arch/src/riscv_shared/zk.rs @@ -57,22 +57,18 @@ unsafe extern "unadjusted" { /// Version: v1.0.1 /// /// Section: 3.47 -/// -/// # Safety -/// -/// This function is safe to use if the `zbkx` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zbkx")] #[cfg_attr(test, assert_instr(xperm8))] #[inline] -pub unsafe fn xperm8(rs1: usize, rs2: usize) -> usize { +pub fn xperm8(rs1: usize, rs2: usize) -> usize { #[cfg(target_arch = "riscv32")] - { + unsafe { _xperm8_32(rs1 as i32, rs2 as i32) as usize } #[cfg(target_arch = "riscv64")] - { + unsafe { _xperm8_64(rs1 as i64, rs2 as i64) as usize } } @@ -89,22 +85,18 @@ pub unsafe fn xperm8(rs1: usize, rs2: usize) -> usize { /// Version: v1.0.1 /// /// Section: 3.48 -/// -/// # Safety -/// -/// This function is safe to use if the `zbkx` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zbkx")] #[cfg_attr(test, assert_instr(xperm4))] #[inline] -pub unsafe fn xperm4(rs1: usize, rs2: usize) -> usize { +pub fn xperm4(rs1: usize, rs2: usize) -> usize { #[cfg(target_arch = "riscv32")] - { + unsafe { _xperm4_32(rs1 as i32, rs2 as i32) as usize } #[cfg(target_arch = "riscv64")] - { + unsafe { _xperm4_64(rs1 as i64, rs2 as i64) as usize } } @@ -124,16 +116,12 @@ pub unsafe fn xperm4(rs1: usize, rs2: usize) -> usize { /// Version: v1.0.1 /// /// Section: 3.27 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha256sig0))] #[inline] -pub unsafe fn sha256sig0(rs1: u32) -> u32 { - _sha256sig0(rs1 as i32) as u32 +pub fn sha256sig0(rs1: u32) -> u32 { + unsafe { _sha256sig0(rs1 as i32) as u32 } } /// Implements the Sigma1 transformation function as used in the SHA2-256 hash function \[49\] @@ -151,16 +139,12 @@ pub unsafe fn sha256sig0(rs1: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.28 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha256sig1))] #[inline] -pub unsafe fn sha256sig1(rs1: u32) -> u32 { - _sha256sig1(rs1 as i32) as u32 +pub fn sha256sig1(rs1: u32) -> u32 { + unsafe { _sha256sig1(rs1 as i32) as u32 } } /// Implements the Sum0 transformation function as used in the SHA2-256 hash function \[49\] @@ -178,16 +162,12 @@ pub unsafe fn sha256sig1(rs1: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.29 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha256sum0))] #[inline] -pub unsafe fn sha256sum0(rs1: u32) -> u32 { - _sha256sum0(rs1 as i32) as u32 +pub fn sha256sum0(rs1: u32) -> u32 { + unsafe { _sha256sum0(rs1 as i32) as u32 } } /// Implements the Sum1 transformation function as used in the SHA2-256 hash function \[49\] @@ -205,16 +185,12 @@ pub unsafe fn sha256sum0(rs1: u32) -> u32 { /// Version: v1.0.1 /// /// Section: 3.30 -/// -/// # Safety -/// -/// This function is safe to use if the `zknh` target feature is present. #[unstable(feature = "riscv_ext_intrinsics", issue = "114544")] #[target_feature(enable = "zknh")] #[cfg_attr(test, assert_instr(sha256sum1))] #[inline] -pub unsafe fn sha256sum1(rs1: u32) -> u32 { - _sha256sum1(rs1 as i32) as u32 +pub fn sha256sum1(rs1: u32) -> u32 { + unsafe { _sha256sum1(rs1 as i32) as u32 } } /// Accelerates the block encrypt/decrypt operation of the SM4 block cipher \[5, 31\]. @@ -237,10 +213,6 @@ pub unsafe fn sha256sum1(rs1: u32) -> u32 { /// The `BS` parameter is expected to be a constant value and only the bottom 2 bits of `bs` are /// used. /// -/// # Safety -/// -/// This function is safe to use if the `zksed` target feature is present. -/// /// # Details /// /// Accelerates the round function `F` in the SM4 block cipher algorithm @@ -291,10 +263,10 @@ pub unsafe fn sha256sum1(rs1: u32) -> u32 { #[rustc_legacy_const_generics(2)] #[cfg_attr(test, assert_instr(sm4ed, BS = 0))] #[inline] -pub unsafe fn sm4ed(rs1: u32, rs2: u32) -> u32 { +pub fn sm4ed(rs1: u32, rs2: u32) -> u32 { static_assert!(BS < 4); - _sm4ed(rs1 as i32, rs2 as i32, BS as i32) as u32 + unsafe { _sm4ed(rs1 as i32, rs2 as i32, BS as i32) as u32 } } /// Accelerates the Key Schedule operation of the SM4 block cipher \[5, 31\] with `bs=0`. @@ -317,10 +289,6 @@ pub unsafe fn sm4ed(rs1: u32, rs2: u32) -> u32 { /// The `BS` parameter is expected to be a constant value and only the bottom 2 bits of `bs` are /// used. /// -/// # Safety -/// -/// This function is safe to use if the `zksed` target feature is present. -/// /// # Details /// /// Accelerates the round function `F` in the SM4 block cipher algorithm @@ -371,10 +339,10 @@ pub unsafe fn sm4ed(rs1: u32, rs2: u32) -> u32 { #[rustc_legacy_const_generics(2)] #[cfg_attr(test, assert_instr(sm4ks, BS = 0))] #[inline] -pub unsafe fn sm4ks(rs1: u32, rs2: u32) -> u32 { +pub fn sm4ks(rs1: u32, rs2: u32) -> u32 { static_assert!(BS < 4); - _sm4ks(rs1 as i32, rs2 as i32, BS as i32) as u32 + unsafe { _sm4ks(rs1 as i32, rs2 as i32, BS as i32) as u32 } } /// Implements the P0 transformation function as used in the SM3 hash function [4, 30]. @@ -389,10 +357,6 @@ pub unsafe fn sm4ks(rs1: u32, rs2: u32) -> u32 { /// /// Section: 3.41 /// -/// # Safety -/// -/// This function is safe to use if the `zksh` target feature is present. -/// /// # Details /// /// `P0` transformation function as is used in the SM3 hash algorithm @@ -412,8 +376,8 @@ pub unsafe fn sm4ks(rs1: u32, rs2: u32) -> u32 { #[target_feature(enable = "zksh")] #[cfg_attr(test, assert_instr(sm3p0))] #[inline] -pub unsafe fn sm3p0(rs1: u32) -> u32 { - _sm3p0(rs1 as i32) as u32 +pub fn sm3p0(rs1: u32) -> u32 { + unsafe { _sm3p0(rs1 as i32) as u32 } } /// Implements the P1 transformation function as used in the SM3 hash function [4, 30]. @@ -428,10 +392,6 @@ pub unsafe fn sm3p0(rs1: u32) -> u32 { /// /// Section: 3.42 /// -/// # Safety -/// -/// This function is safe to use if the `zksh` target feature is present. -/// /// # Details /// /// `P1` transformation function as is used in the SM3 hash algorithm @@ -457,6 +417,6 @@ pub unsafe fn sm3p0(rs1: u32) -> u32 { #[target_feature(enable = "zksh")] #[cfg_attr(test, assert_instr(sm3p1))] #[inline] -pub unsafe fn sm3p1(rs1: u32) -> u32 { - _sm3p1(rs1 as i32) as u32 +pub fn sm3p1(rs1: u32) -> u32 { + unsafe { _sm3p1(rs1 as i32) as u32 } }