Skip to content

Commit

Permalink
Fixes for const generics used in sm4ks and sm4ed
Browse files Browse the repository at this point in the history
Use `static_assert!` macro to constrain BS: u8

Thanks @Amanieu
  • Loading branch information
luojia65 committed Feb 6, 2022
1 parent 596762d commit ad6287a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/core_arch/src/riscv_shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ pub fn sm3p1(x: u32) -> u32 {
/// According to RISC-V Cryptography Extensions, Volume I, the execution latency of
/// this instruction must always be independent from the data it operates on.
pub fn sm4ed<const BS: u8>(x: u32, a: u32) -> u32 {
static_assert_imm2!(BS); // `bs` immediate value must be within [0, 3]
static_assert!(BS: u8 where BS <= 3);
let ans: u32;
match BS {
0 => unsafe {
Expand Down Expand Up @@ -750,7 +750,7 @@ pub fn sm4ed<const BS: u8>(x: u32, a: u32) -> u32 {
/// According to RISC-V Cryptography Extensions, Volume I, the execution latency of
/// this instruction must always be independent from the data it operates on.
pub fn sm4ks<const BS: u8>(x: u32, k: u32) -> u32 {
static_assert_imm2!(BS); // `bs` immediate value must be within [0, 3]
static_assert!(BS: u8 where BS <= 3);
let ans: u32;
match BS {
0 => unsafe {
Expand Down

0 comments on commit ad6287a

Please sign in to comment.