|
1 | 1 | //! Shared RISC-V intrinsics
|
| 2 | +mod p; |
| 3 | + |
| 4 | +pub use p::*; |
2 | 5 |
|
3 | 6 | use crate::arch::asm;
|
4 | 7 |
|
@@ -674,12 +677,17 @@ pub fn sm3p1(x: u32) -> u32 {
|
674 | 677 | /// It can be implemented by `sm4ed` instruction like:
|
675 | 678 | ///
|
676 | 679 | /// ```no_run
|
| 680 | +/// # #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] |
| 681 | +/// # fn round_function(x0: u32, x1: u32, x2: u32, x3: u32, rk: u32) -> u32 { |
| 682 | +/// # #[cfg(target_arch = "riscv32")] use core::arch::riscv32::sm4ed; |
| 683 | +/// # #[cfg(target_arch = "riscv64")] use core::arch::riscv64::sm4ed; |
677 | 684 | /// let a = x1 ^ x2 ^ x3 ^ rk;
|
678 | 685 | /// let c0 = sm4ed::<0>(x0, a);
|
679 | 686 | /// let c1 = sm4ed::<1>(c0, a); // c1 represents c[0..=1], etc.
|
680 | 687 | /// let c2 = sm4ed::<2>(c1, a);
|
681 | 688 | /// let c3 = sm4ed::<3>(c2, a);
|
682 | 689 | /// return c3; // c3 represents c[0..=3]
|
| 690 | +/// # } |
683 | 691 | /// ```
|
684 | 692 | ///
|
685 | 693 | /// According to RISC-V Cryptography Extensions, Volume I, the execution latency of
|
@@ -739,12 +747,17 @@ pub fn sm4ed<const BS: u8>(x: u32, a: u32) -> u32 {
|
739 | 747 | /// Hence, the key schedule operation can be implemented by `sm4ks` instruction like:
|
740 | 748 | ///
|
741 | 749 | /// ```no_run
|
| 750 | +/// # #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] |
| 751 | +/// # fn key_schedule(k0: u32, k1: u32, k2: u32, k3: u32, ck_i: u32) -> u32 { |
| 752 | +/// # #[cfg(target_arch = "riscv32")] use core::arch::riscv32::sm4ks; |
| 753 | +/// # #[cfg(target_arch = "riscv64")] use core::arch::riscv64::sm4ks; |
742 | 754 | /// let k = k1 ^ k2 ^ k3 ^ ck_i;
|
743 | 755 | /// let c0 = sm4ks::<0>(k0, k);
|
744 | 756 | /// let c1 = sm4ks::<1>(c0, k); // c1 represents c[0..=1], etc.
|
745 | 757 | /// let c2 = sm4ks::<2>(c1, k);
|
746 | 758 | /// let c3 = sm4ks::<3>(c2, k);
|
747 | 759 | /// return c3; // c3 represents c[0..=3]
|
| 760 | +/// # } |
748 | 761 | /// ```
|
749 | 762 | ///
|
750 | 763 | /// According to RISC-V Cryptography Extensions, Volume I, the execution latency of
|
|
0 commit comments