Skip to content
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
3 changes: 3 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ CONFIG_ARCH_TEGRA
CONFIG_ARM
CONFIG_ARM64
CONFIG_BOARD_NATIVE_POSIX
CONFIG_BOARD_NATIVE_SIM
CONFIG_COMPILER_OPTIMIZATION_DEFAULT
CONFIG_COMPILER_OPTIMIZATION_NONE
CONFIG_COMPILER_OPTIMIZATION_PERF
Expand Down Expand Up @@ -564,6 +565,7 @@ STSAFE_HOST_KEY_MAC
STSAFE_I2C_BUS
STSE_CONF_ECC_BRAINPOOL_P_256
STSE_CONF_ECC_BRAINPOOL_P_384
SYS_CLOCK_REALTIME
TASK_EXTRA_STACK_SIZE
TCP_NODELAY
TFM_ALREADY_SET
Expand Down Expand Up @@ -1098,6 +1100,7 @@ __cplusplus
__ghc__
__ghs__
__has_attribute
__has_include
__hpux__
__i386
__i386__
Expand Down
6 changes: 5 additions & 1 deletion wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -15934,7 +15934,11 @@ void bench_sphincsKeySign(byte level, byte optim)
int64_t t;
(void)reset;
#if defined(CONFIG_ARCH_POSIX)
k_cpu_idle();
#if defined(CONFIG_BOARD_NATIVE_SIM)
k_msleep(1);
#else
k_cpu_idle();
#endif
#endif
t = k_uptime_get(); /* returns current uptime in milliseconds */
return (double)(t / 1000);
Expand Down
24 changes: 16 additions & 8 deletions wolfcrypt/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -3447,7 +3447,17 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)

#elif defined(WOLFSSL_ZEPHYR)

#include <version.h>
#ifdef __has_include
#if __has_include(<zephyr/version.h>)
#include <zephyr/version.h>
#else
#include <version.h>
#endif
#else
#include <version.h>
#endif

#include <sys/types.h>

#if KERNEL_VERSION_NUMBER >= 0x30500
#include <zephyr/random/random.h>
Expand All @@ -3459,14 +3469,12 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
#endif
#endif

#ifndef _POSIX_C_SOURCE
#if KERNEL_VERSION_NUMBER >= 0x30100
#include <zephyr/posix/time.h>
#else
#include <posix/time.h>
#endif
#else
#if KERNEL_VERSION_NUMBER >= 0x40300
#include <time.h>
#elif KERNEL_VERSION_NUMBER >= 0x30100
#include <zephyr/posix/time.h>
#else
#include <posix/time.h>
#endif

int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
Expand Down
14 changes: 12 additions & 2 deletions wolfssl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,15 @@
#include <pthread.h>
#define SOCKET_T int
#elif defined(WOLFSSL_ZEPHYR)
#include <version.h>
#ifdef __has_include
#if __has_include(<zephyr/version.h>)
#include <zephyr/version.h>
#else
#include <version.h>
#endif
#else
#include <version.h>
#endif
#include <string.h>
#include <sys/types.h>
#if KERNEL_VERSION_NUMBER >= 0x30100
Expand All @@ -209,9 +217,10 @@
#endif
#endif
#define SOCKET_T int
#define SOL_SOCKET 1
#define WOLFSSL_USE_GETADDRINFO

#if !defined(CONFIG_POSIX_API)
#define SOL_SOCKET 1
static unsigned long inet_addr(const char *cp)
{
unsigned int a[4]; unsigned long ret;
Expand All @@ -227,6 +236,7 @@
ret = ((a[3]<<24) + (a[2]<<16) + (a[1]<<8) + a[0]) ;
return(ret) ;
}
#endif
#elif defined(NETOS)
#include <string.h>
#include <sys/types.h>
Expand Down
39 changes: 38 additions & 1 deletion wolfssl/wolfcrypt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,15 @@ extern void uITRON4_free(void *p) ;
} /* extern "C" */
#endif

#include <version.h>
#ifdef __has_include
#if __has_include(<zephyr/version.h>)
#include <zephyr/version.h>
#else
#include <version.h>
#endif
#else
#include <version.h>
#endif
#if KERNEL_VERSION_NUMBER >= 0x30100
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
Expand Down Expand Up @@ -2649,9 +2657,38 @@ extern void uITRON4_free(void *p) ;
void *z_realloc(void *ptr, size_t size);
#define realloc z_realloc

#if KERNEL_VERSION_NUMBER >= 0x40100
/* Zephyr >= 4.1 removed CONFIG_NET_SOCKETS_POSIX_NAMES and the
* corresponding macro block in <zephyr/net/socket.h>.
* Define our own compile-time remapping to zsock_* so that wolfSSL
* always calls Zephyr's network stack directly, avoiding host-libc
* symbol conflicts on native_sim. */
#define socket zsock_socket
#define bind zsock_bind
#define connect zsock_connect
#define listen zsock_listen
#define accept zsock_accept
#define send zsock_send
#define recv zsock_recv
#define sendto zsock_sendto
#define recvfrom zsock_recvfrom
#define setsockopt zsock_setsockopt
#define getsockopt zsock_getsockopt
#define shutdown zsock_shutdown
#define getpeername zsock_getpeername
#define getsockname zsock_getsockname
/* Note: close, poll, inet_pton, inet_ntop are NOT remapped here.
* They are general POSIX functions still declared in Zephyr's POSIX
* headers; redefining them conflicts with __syscall declarations in
* <zephyr/net/socket.h>. close is handled via CloseSocket in wolfio.h,
* inet_pton/inet_ntop via XINET_PTON/XINET_NTOP in wolfio.h. */
#else
/* Zephyr < 4.1: define CONFIG_NET_SOCKETS_POSIX_NAMES so that
* <net/socket.h> provides the POSIX name remapping macros. */
#if !defined(CONFIG_NET_SOCKETS_POSIX_NAMES) && !defined(CONFIG_POSIX_API)
#define CONFIG_NET_SOCKETS_POSIX_NAMES
#endif
#endif
#endif /* WOLFSSL_ZEPHYR */

#ifdef WOLFSSL_IMX6
Expand Down
46 changes: 33 additions & 13 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,34 @@
} /* extern "C" */
#endif

#include <version.h>
#ifdef __has_include
#if __has_include(<zephyr/version.h>)
#include <zephyr/version.h>
#else
#include <version.h>
#endif
#else
#include <version.h>
#endif
/* Include sys/types.h early so host libc sets __timer_t_defined
* before Zephyr's posix_types.h can define a conflicting timer_t */
#include <sys/types.h>
#ifndef SINGLE_THREADED
#if !defined(CONFIG_PTHREAD_IPC) && !defined(CONFIG_POSIX_THREADS)
#error "Threading needs CONFIG_PTHREAD_IPC / CONFIG_POSIX_THREADS"
#endif
#if KERNEL_VERSION_NUMBER >= 0x30100
#include <zephyr/kernel.h>
#include <zephyr/posix/posix_types.h>
#include <zephyr/posix/pthread.h>
#ifndef CONFIG_ARCH_POSIX
#include <zephyr/posix/posix_types.h>
#include <zephyr/posix/pthread.h>
#endif
#else
#include <kernel.h>
#include <posix/posix_types.h>
#include <posix/pthread.h>
#ifndef CONFIG_ARCH_POSIX
#include <posix/posix_types.h>
#include <posix/pthread.h>
#endif
#endif
#endif

Expand Down Expand Up @@ -1505,15 +1520,20 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
} /* extern "C" */
#endif

#include <version.h>
#ifndef _POSIX_C_SOURCE
#if KERNEL_VERSION_NUMBER >= 0x30100
#include <zephyr/posix/time.h>
#else
#include <posix/time.h>
#endif
#else
#if KERNEL_VERSION_NUMBER >= 0x40300
#include <time.h>
#elif KERNEL_VERSION_NUMBER >= 0x30100
#include <zephyr/posix/time.h>
#else
#include <posix/time.h>
#endif

#ifndef CLOCK_REALTIME
#ifdef SYS_CLOCK_REALTIME
#define CLOCK_REALTIME SYS_CLOCK_REALTIME
#define clock_gettime sys_clock_gettime
#define clock_settime sys_clock_settime
#endif
#endif

#if defined(CONFIG_RTC)
Expand Down
15 changes: 14 additions & 1 deletion wolfssl/wolfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,15 @@
} /* extern "C" */
#endif

#include <version.h>
#ifdef __has_include
#if __has_include(<zephyr/version.h>)
#include <zephyr/version.h>
#else
#include <version.h>
#endif
#else
#include <version.h>
#endif
#if KERNEL_VERSION_NUMBER >= 0x30100
#include <zephyr/net/socket.h>
#ifdef CONFIG_POSIX_API
Expand Down Expand Up @@ -623,6 +631,11 @@ WOLFSSL_API int wolfIO_RecvFrom(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf,
#define CloseSocket(s) closesocket(s)
#endif
#define StartTCP() WC_DO_NOTHING
#elif defined(WOLFSSL_ZEPHYR) && KERNEL_VERSION_NUMBER >= 0x40100
#ifndef CloseSocket
#define CloseSocket(s) zsock_close(s)
#endif
#define StartTCP() WC_DO_NOTHING
#else
#ifndef CloseSocket
#define CloseSocket(s) close(s)
Expand Down
9 changes: 9 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ if(CONFIG_WOLFSSL)

target_compile_definitions(wolfSSL INTERFACE WOLFSSL_ZEPHYR)
target_compile_definitions(wolfSSL INTERFACE WOLFSSL_USER_SETTINGS)

if(NOT CONFIG_WOLFSSL_NO_HAVE_MIN_MAX AND
(KERNEL_VERSION_MAJOR GREATER_EQUAL 5 OR
(KERNEL_VERSION_MAJOR EQUAL 4 AND
KERNEL_VERSION_MINOR GREATER_EQUAL 3)))
target_compile_definitions(wolfSSL INTERFACE
WOLFSSL_HAVE_MIN
WOLFSSL_HAVE_MAX)
endif()
if(CONFIG_WOLFSSL_DEBUG)
target_compile_definitions(wolfSSL INTERFACE DEBUG_WOLFSSL)
zephyr_library_compile_options(-g3 -O0)
Expand Down
7 changes: 7 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ config WOLFCRYPT_INTELASM
help
wolfCrypt Intel Aassembly support (AVX/AVX2/AESNI)

config WOLFSSL_NO_HAVE_MIN_MAX
bool "Force wolfSSL to use its own min/max"
help
Disable this if Zephyr min()/max() macros cause
issues. By default wolfSSL defers to Zephyr's
min/max on >= 4.3.

config WOLFSSL_DEBUG
bool "wolfSSL debug activation"
depends on WOLFSSL_BUILTIN
Expand Down
12 changes: 12 additions & 0 deletions zephyr/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,43 @@ EXTRA_DIST+= zephyr/README.md
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/CMakeLists.txt
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/README
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/boards/native_sim.conf
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/boards/nrf5340dk_nrf5340_cpuapp.conf
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/boards/nrf5340dk_nrf5340_cpuapp_ns.conf
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/install_test.sh
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/prj.conf
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/sample.yaml
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/zephyr_legacy.conf
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/zephyr_v4.1.conf
EXTRA_DIST+= zephyr/samples/wolfssl_test/CMakeLists.txt
EXTRA_DIST+= zephyr/samples/wolfssl_test/README
EXTRA_DIST+= zephyr/samples/wolfssl_test/boards/native_sim.conf
EXTRA_DIST+= zephyr/samples/wolfssl_test/boards/nrf5340dk_nrf5340_cpuapp.conf
EXTRA_DIST+= zephyr/samples/wolfssl_test/boards/nrf5340dk_nrf5340_cpuapp_ns.conf
EXTRA_DIST+= zephyr/samples/wolfssl_test/install_test.sh
EXTRA_DIST+= zephyr/samples/wolfssl_test/prj.conf
EXTRA_DIST+= zephyr/samples/wolfssl_test/sample.yaml
EXTRA_DIST+= zephyr/samples/wolfssl_test/zephyr_legacy.conf
EXTRA_DIST+= zephyr/samples/wolfssl_test/zephyr_v4.1.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/CMakeLists.txt
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/README
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/boards/native_sim.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/install_sample.sh
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/prj.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/sample.yaml
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/src
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/zephyr_legacy.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/zephyr_v4.1.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/src/tls_sock.c
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/CMakeLists.txt
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/README
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/boards/native_sim.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/boards/nrf5340dk_nrf5340_cpuapp.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/boards/nrf5340dk_nrf5340_cpuapp_ns.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/install_sample.sh
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/prj.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/sample.yaml
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/src
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/zephyr_legacy.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/zephyr_v4.1.conf
EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/src/tls_threaded.c
20 changes: 20 additions & 0 deletions zephyr/samples/wolfssl_benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
cmake_minimum_required(VERSION 3.13.1)

# Select version-specific Kconfig fragment before loading Zephyr
if(EXISTS $ENV{ZEPHYR_BASE}/VERSION)
file(READ $ENV{ZEPHYR_BASE}/VERSION zephyr_version_file)
string(REGEX MATCH "VERSION_MAJOR = ([0-9]+)" _ ${zephyr_version_file})
set(ZEPHYR_VER_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "VERSION_MINOR = ([0-9]+)" _ ${zephyr_version_file})
set(ZEPHYR_VER_MINOR ${CMAKE_MATCH_1})
endif()

if(ZEPHYR_VER_MAJOR GREATER_EQUAL 4 OR
(ZEPHYR_VER_MAJOR EQUAL 3 AND
ZEPHYR_VER_MINOR GREATER 5))
set(OVERLAY_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/zephyr_v4.1.conf)
else()
set(OVERLAY_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/zephyr_legacy.conf)
endif()

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(wolfssl_benchmark)

Expand Down
2 changes: 2 additions & 0 deletions zephyr/samples/wolfssl_benchmark/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# native_sim needs a larger malloc arena for thread stack allocation
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072
6 changes: 0 additions & 6 deletions zephyr/samples/wolfssl_benchmark/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
CONFIG_MAIN_STACK_SIZE=32768
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192

# Pthreads
CONFIG_PTHREAD_IPC=y

# Clock for time()
CONFIG_POSIX_CLOCK=y

# TLS configuration
CONFIG_WOLFSSL=y
CONFIG_WOLFSSL_BUILTIN=y
Expand Down
3 changes: 3 additions & 0 deletions zephyr/samples/wolfssl_benchmark/zephyr_legacy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Zephyr < 4.1 POSIX options
CONFIG_PTHREAD_IPC=y
CONFIG_POSIX_CLOCK=y
2 changes: 2 additions & 0 deletions zephyr/samples/wolfssl_benchmark/zephyr_v4.1.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Zephyr >= 4.1 POSIX options
CONFIG_POSIX_API=y
Loading