Skip to content

Commit cfa41e2

Browse files
hack3ricsmuellerDD
authored andcommitted
ML-KEM: check CPU features before calling kyber_rvv_selector
On RISC-V platforms without V, kyber_rvv_selector is called first in __attribute__((constructor)) before the normal dynamic dispatch code in kyber_kem_api_riscv.c, causing SIGILL. Add a condition so that lc_cpu_feature_available() is always first checked. Signed-off-by: Eric Long <i@hack3r.moe> Signed-off-by: Stephan Mueller <smueller@chronox.de>
1 parent fd71be5 commit cfa41e2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ml-kem/src/riscv64/kyber_rvv_vlen_selector.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* DAMAGE.
1818
*/
1919

20+
#include "cpufeatures.h"
2021
#include "ext_headers_riscv.h"
2122
#include "initialization.h"
2223
#include "kyber_rvv_vlen_selector.h"
@@ -28,9 +29,11 @@ static int lc_riscv_rvv_vlen = 0;
2829

2930
LC_CONSTRUCTOR(kyber_riscv_rvv_selector)
3031
{
31-
LC_VECTOR_ENABLE;
32-
lc_riscv_rvv_vlen = kyber_rvv_selector();
33-
LC_VECTOR_DISABLE;
32+
if (lc_cpu_feature_available() & LC_CPU_FEATURE_RISCV_ASM_RVV) {
33+
LC_VECTOR_ENABLE;
34+
lc_riscv_rvv_vlen = kyber_rvv_selector();
35+
LC_VECTOR_DISABLE;
36+
}
3437
}
3538

3639
int lc_riscv_rvv_is_vlen128(void)

0 commit comments

Comments
 (0)