diff --git a/CMakeLists.txt b/CMakeLists.txt index c492660bab..19f226c397 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x") if(${OQS_DIST_BUILD}) set(OQS_DIST_S390X_BUILD ON) endif() +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv") + set(ARCH "riscv") elseif(OQS_PERMIT_UNSUPPORTED_ARCHITECTURE) message(WARNING "Unknown or unsupported processor: " ${CMAKE_SYSTEM_PROCESSOR}) message(WARNING "Compilation on an unsupported processor should only be used for testing, as it may result an insecure configuration, for example due to variable-time instructions leaking secret information.") diff --git a/PLATFORMS.md b/PLATFORMS.md index d25e1df633..f3f7d04cda 100644 --- a/PLATFORMS.md +++ b/PLATFORMS.md @@ -54,7 +54,7 @@ In this policy, the words "must" and "must not" specify absolute requirements th - x86_64/amd64/x64 for Windows 2022 - armeabi-v7a, arm64-v8a, x86, x86_64 for Android - aarch64 for Apple iOS and tvOS (CMake `-DPLATFORM=OS64` and `TVOS`) -- arm64, arm (32 bit), x86, x86_64 for Zephyr +- arm64, arm (32 bit), x86, x86_64, riscv32, riscv64 for Zephyr ### Tier 3 diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 985259d0af..7c4d934ea8 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -2,14 +2,33 @@ # Only add liboqs Zephyr module if enabled in Kconfig if(CONFIG_LIBOQS) + # Workarounds for Zephyr if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm") # Workaround as the generic name "arm" is not a supported architecture in liboqs. # In Zephyr, however, it is exclusively used for 32-bit ARM architectures. set(CMAKE_SYSTEM_PROCESSOR "armv7") + # We have to set that manually as CMake can't detect it properly in Zephyr + set(CMAKE_SIZEOF_VOID_P 4) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv") + if(BOARD STREQUAL "qemu_riscv32") + set(CMAKE_SYSTEM_PROCESSOR "riscv32") + # We have to set that manually as CMake can't detect it properly in Zephyr + set(CMAKE_SIZEOF_VOID_P 4) + elseif(BOARD STREQUAL "hifive1_revb") + set(CMAKE_SYSTEM_PROCESSOR "riscv32") + # We have to set that manually as CMake can't detect it properly in Zephyr + set(CMAKE_SIZEOF_VOID_P 4) + elseif(BOARD STREQUAL "qemu_riscv64") + set(CMAKE_SYSTEM_PROCESSOR "riscv64") + # We have to set that manually as CMake can't detect it properly in Zephyr + set(CMAKE_SIZEOF_VOID_P 8) + else() + message(FATAL_ERROR "Unsupported board ${BOARD} with riscv architecture") + endif() elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "posix") # Workaround to enable the native Zephyr builds on the Linux host system. - if(BOARD MATCHES "native_posix|native_sim") + if(BOARD STREQUAL "native_posix|native_sim") set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) else() message(FATAL_ERROR "Unsupported board ${BOARD} with posix architecture") diff --git a/zephyr/Kconfig b/zephyr/Kconfig index ef5da803d5..cc3538b70c 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -2,10 +2,10 @@ config LIBOQS bool "Enable liboqs" - depends on ARM || ARM64 || X86 || ARCH_POSIX + depends on ARM || ARM64 || X86 || ARCH_POSIX || RISCV help This option enables the liboqs as a Zephyr module. Currenty, the port is only - available for ARM, ARM64, and x86 architectures and the native Posix simulators. + available for ARM, ARM64, x86, RISCV-32, and RISCV-64 architectures and the native Posix simulators. menu "Liboqs algorithm configuration" diff --git a/zephyr/samples/KEMs/sample.yaml b/zephyr/samples/KEMs/sample.yaml index 664f86169c..22220b4209 100644 --- a/zephyr/samples/KEMs/sample.yaml +++ b/zephyr/samples/KEMs/sample.yaml @@ -14,3 +14,5 @@ tests: integration_platforms: - qemu_x86 - qemu_cortex_a53 + - qemu_riscv32 + - qemu_riscv64 diff --git a/zephyr/samples/Signatures/sample.yaml b/zephyr/samples/Signatures/sample.yaml index 9c66001051..6004722ae4 100644 --- a/zephyr/samples/Signatures/sample.yaml +++ b/zephyr/samples/Signatures/sample.yaml @@ -14,3 +14,5 @@ tests: integration_platforms: - qemu_x86 - qemu_cortex_a53 + - qemu_riscv32 + - qemu_riscv64