-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 externally defined RNG method. Signed-off-by: Tobias Frauenschläger <[email protected]>
- Loading branch information
Showing
9 changed files
with
111 additions
and
6 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
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,60 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
if(CONFIG_LIBOQS) | ||
# We add our own module library to build our RNG implementation | ||
zephyr_library() | ||
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/zephyr/zephyr_rng.c) | ||
|
||
# Configuration for liboqs | ||
set(OQS_DIST_BUILD OFF) | ||
set(OQS_BUILD_ONLY_LIB ON) | ||
set(OQS_USE_OPENSSL OFF) | ||
set(OQS_POSITION_INDEPENDENT_CODE OFF) | ||
set(OQS_USE_EXTERNAL_RNG ON) | ||
|
||
set(CMAKE_CROSSCOMPILING ON) | ||
set(CMAKE_SIZEOF_VOID_P 4) # Not really needed, only for surpressing unrelated warnings | ||
|
||
# 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) | ||
|
||
add_subdirectory(.. build) | ||
|
||
# Add compiler options from Zephyr to all liboqs targets | ||
zephyr_get_targets(.. "STATIC_LIBRARY;OBJECT_LIBRARY" ALL_TARGETS) | ||
foreach(target ${ALL_TARGETS}) | ||
target_include_directories(${target} PRIVATE | ||
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_INCLUDE_DIRECTORIES> | ||
) | ||
|
||
target_include_directories(${target} SYSTEM PRIVATE | ||
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES> | ||
) | ||
|
||
target_compile_definitions(${target} PRIVATE | ||
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS> | ||
) | ||
|
||
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. | ||
add_dependencies(${target} ${SYSCALL_LIST_H_TARGET}) | ||
endforeach() | ||
|
||
# Link the liboqs library to our module library | ||
zephyr_library_link_libraries(oqs) | ||
|
||
# Include the liboqs headers | ||
zephyr_include_directories(${CMAKE_CURRENT_BINARY_DIR}/build/include) | ||
endif() |
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,6 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
config LIBOQS | ||
bool "Enable liboqs" | ||
help | ||
This option enables the liboqs as a Zephyr module. |
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,3 @@ | ||
build: | ||
cmake: zephyr | ||
kconfig: zephyr/Kconfig |
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,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
// Autogenerated header file from Zephyr containing the version number | ||
#include <version.h> | ||
|
||
#if KERNEL_VERSION_NUMBER >= 0x30500 | ||
#include <zephyr/random/random.h> | ||
#else | ||
#include <zephyr/random/rand32.h> | ||
#endif | ||
|
||
|
||
void OQS_randombytes_external(uint8_t *random_array, size_t bytes_to_read) | ||
{ | ||
// Obtain random bytes from the zephyr RNG | ||
sys_rand_get(random_array, bytes_to_read); | ||
} |