Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Riscv zephyr support #1641

Merged
merged 11 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion PLATFORMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
baentsch marked this conversation as resolved.
Show resolved Hide resolved
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")
Expand Down
4 changes: 2 additions & 2 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
baentsch marked this conversation as resolved.
Show resolved Hide resolved

menu "Liboqs algorithm configuration"

Expand Down
2 changes: 2 additions & 0 deletions zephyr/samples/KEMs/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ tests:
integration_platforms:
- qemu_x86
- qemu_cortex_a53
- qemu_riscv32
- qemu_riscv64
2 changes: 2 additions & 0 deletions zephyr/samples/Signatures/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ tests:
integration_platforms:
- qemu_x86
- qemu_cortex_a53
- qemu_riscv32
- qemu_riscv64
Loading