-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for embedded Zephyr RTOS (#1621)
* Zephyr RTOS support This commit adds initial support for the zephyr operating system. Some minor changes to the library build system have been made for it to be compilable with zephyr. Furthermore, we added support for an embedded build option to disable standard library methods for random number generation. * Zephyr: added algorithm selection The algorithms can now be selected with Kconfig. Per default, we only enable the algorithms selected by NIST to be standardized. However, all supported algorithms can be enabled or disabled individually on a per project basis. * Zephyr: added testable samples Added two sample applications within the zephyr directory for KEMs and Signatures. These are also intended for CI testing. * Zephyr: added CI tests * Zephyr: Add documentation Signed-off-by: Tobias Frauenschläger <[email protected]>
- Loading branch information
Showing
20 changed files
with
858 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Zephyr tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
|
||
zephyr_test: | ||
runs-on: ubuntu-22.04 | ||
container: ghcr.io/zephyrproject-rtos/ci:latest | ||
env: | ||
CMAKE_PREFIX_PATH: /opt/toolchains | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- zephyr-ref: v3.4.0 | ||
- zephyr-ref: v3.5.0 | ||
|
||
steps: | ||
- name: Init west workspace | ||
run: west init --mr ${{ matrix.config.zephyr-ref }} zephyr | ||
|
||
- name: Update west.yml | ||
working-directory: zephyr/zephyr | ||
run: | | ||
REF=$(echo '${{ github.ref }}' | sed -e 's/\//\\\//g') | ||
sed -e 's/remotes:/remotes:\n \- name: liboqs\n url\-base: https:\/\/github.com\/${{ github.repository_owner }}/' -i west.yml | ||
sed -e "s/projects:/projects:\n \- name: liboqs\n path: modules\/crypto\/liboqs\n remote: liboqs\n revision: $REF/" -i west.yml | ||
- name: Update west workspace | ||
working-directory: zephyr | ||
run: west update -n -o=--depth=1 | ||
|
||
- name: Export zephyr | ||
working-directory: zephyr | ||
run: west zephyr-export | ||
|
||
- name: Run Signature test | ||
working-directory: zephyr | ||
run: | | ||
west twister --integration -T modules/crypto/liboqs/zephyr -s samples/Signatures/sample.crypto.liboqs_signature_example -vvv | ||
- name: Run KEM test | ||
working-directory: zephyr | ||
run: | | ||
west twister --integration -T modules/crypto/liboqs/zephyr -s samples/KEMs/sample.crypto.liboqs_kem_example -vvv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
# Only add liboqs Zephyr module if enabled in Kconfig | ||
if(CONFIG_LIBOQS) | ||
# Workarounds for Zephyr | ||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") | ||
# We have to set that manually as CMake can't detect it properly in Zephyr | ||
set(CMAKE_SIZEOF_VOID_P 8) | ||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "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 MATCHES "posix") | ||
# Workaround to enable the native Zephyr builds on the Linux host system. | ||
if(BOARD MATCHES "native_posix|native_sim") | ||
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) | ||
else() | ||
message(FATAL_ERROR "Unsupported board ${BOARD} with posix architecture") | ||
endif() | ||
|
||
# We have to set that manually as CMake can't detect it properly in Zephyr | ||
set(CMAKE_SIZEOF_VOID_P 8) | ||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86") | ||
# We have to set that manually as CMake can't detect it properly in Zephyr | ||
set(CMAKE_SIZEOF_VOID_P 4) | ||
endif() | ||
|
||
# Configuration for liboqs | ||
set(OQS_DIST_BUILD OFF) | ||
set(OQS_BUILD_ONLY_LIB ON) | ||
set(OQS_USE_OPENSSL OFF) | ||
set(OQS_EMBEDDED_BUILD ON) | ||
|
||
set(CMAKE_CROSSCOMPILING ON) | ||
|
||
# Disable features by hand, as CMake won't find them properly with Zephyr | ||
set(CMAKE_HAVE_GETENTROPY OFF) | ||
set(CMAKE_HAVE_ALIGNED_ALLOC OFF) | ||
set(CMAKE_HAVE_POSIX_MEMALIGN OFF) | ||
set(CMAKE_HAVE_MEMALIGN OFF) | ||
set(CMAKE_HAVE_EXPLICIT_BZERO OFF) | ||
set(CMAKE_HAVE_MEMSET_S OFF) | ||
set(CC_SUPPORTS_WA_NOEXECSTACK OFF) | ||
set(LD_SUPPORTS_WL_Z_NOEXECSTACK OFF) | ||
|
||
# Algorithm selection (based on Kconfig) | ||
if(CONFIG_LIBOQS_ENABLE_KEM_BIKE) | ||
set(OQS_ENABLE_KEM_BIKE ON) | ||
else() | ||
set(OQS_ENABLE_KEM_BIKE OFF) | ||
endif() | ||
|
||
if(CONFIG_LIBOQS_ENABLE_KEM_FRODOKEM) | ||
set(OQS_ENABLE_KEM_FRODOKEM ON) | ||
else() | ||
set(OQS_ENABLE_KEM_FRODOKEM OFF) | ||
endif() | ||
|
||
if(CONFIG_LIBOQS_ENABLE_KEM_NTRUPRIME) | ||
set(OQS_ENABLE_KEM_NTRUPRIME ON) | ||
else() | ||
set(OQS_ENABLE_KEM_NTRUPRIME OFF) | ||
endif() | ||
|
||
if(CONFIG_LIBOQS_ENABLE_KEM_CLASSIC_MCELIECE) | ||
set(OQS_ENABLE_KEM_CLASSIC_MCELIECE ON) | ||
else() | ||
set(OQS_ENABLE_KEM_CLASSIC_MCELIECE OFF) | ||
endif() | ||
|
||
if(CONFIG_LIBOQS_ENABLE_KEM_HQC) | ||
set(OQS_ENABLE_KEM_HQC ON) | ||
else() | ||
set(OQS_ENABLE_KEM_HQC OFF) | ||
endif() | ||
|
||
if(CONFIG_LIBOQS_ENABLE_KEM_KYBER) | ||
set(OQS_ENABLE_KEM_KYBER ON) | ||
else() | ||
set(OQS_ENABLE_KEM_KYBER OFF) | ||
endif() | ||
|
||
if(CONFIG_LIBOQS_ENABLE_SIG_DILITHIUM) | ||
set(OQS_ENABLE_SIG_DILITHIUM ON) | ||
else() | ||
set(OQS_ENABLE_SIG_DILITHIUM OFF) | ||
endif() | ||
|
||
if(CONFIG_LIBOQS_ENABLE_SIG_FALCON) | ||
set(OQS_ENABLE_SIG_FALCON ON) | ||
else() | ||
set(OQS_ENABLE_SIG_FALCON OFF) | ||
endif() | ||
|
||
if(CONFIG_LIBOQS_ENABLE_SIG_SPHINCS) | ||
set(OQS_ENABLE_SIG_SPHINCS ON) | ||
else() | ||
set(OQS_ENABLE_SIG_SPHINCS OFF) | ||
endif() | ||
|
||
# Add the actual liboqs targets | ||
add_subdirectory(.. build) | ||
|
||
# Add target specific options to all liboqs targets | ||
zephyr_get_targets(.. "STATIC_LIBRARY;OBJECT_LIBRARY" ALL_TARGETS) | ||
foreach(target ${ALL_TARGETS}) | ||
# Zephyr include directories | ||
target_include_directories(${target} PRIVATE | ||
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_INCLUDE_DIRECTORIES> | ||
) | ||
|
||
# Zephyr system include directories | ||
target_include_directories(${target} SYSTEM PRIVATE | ||
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES> | ||
) | ||
|
||
# Definitions | ||
target_compile_definitions(${target} PRIVATE | ||
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS> | ||
) | ||
|
||
# Compile options (includes compiler flags) | ||
target_compile_options(${target} PRIVATE | ||
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS> | ||
$<TARGET_PROPERTY:compiler,no_builtin> | ||
) | ||
|
||
# liboqs depends on unistd.h, which ultimately needs the generated syscall_list.h file, | ||
# which is generated as part of ${SYSCALL_LIST_H_TARGET} target. Therefore, we have to | ||
# make sure that target is built before liboqs. | ||
add_dependencies(${target} ${SYSCALL_LIST_H_TARGET}) | ||
|
||
# We don't want position independent code | ||
set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE OFF) | ||
endforeach() | ||
|
||
# Link the liboqs library | ||
zephyr_link_libraries(oqs) | ||
|
||
# Include the liboqs headers | ||
zephyr_include_directories(${CMAKE_CURRENT_BINARY_DIR}/build/include) | ||
|
||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "armv7") | ||
# Undo the workaround from above to not interfere with other modules | ||
set(CMAKE_SYSTEM_PROCESSOR "arm") | ||
elseif(CMAKE_SYSTEM_PROCESSOR EQUAL CMAKE_HOST_SYSTEM_PROCESSOR) | ||
# Undo the workaround from above to not interfere with other modules | ||
set(CMAKE_SYSTEM_PROCESSOR "posix") | ||
endif() | ||
endif() |
Oops, something went wrong.