Skip to content

Commit 7e8c015

Browse files
authored
Merge pull request #7325 from dgarske/zephyr
Improve Zephyr support
2 parents 5b3772c + b8bebd6 commit 7e8c015

21 files changed

Lines changed: 511 additions & 403 deletions

src/internal.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9768,7 +9768,12 @@ ProtocolVersion MakeDTLSv1_3(void)
97689768

97699769
word32 LowResTimer(void)
97709770
{
9771-
return k_uptime_get() / 1000;
9771+
int64_t t;
9772+
#if defined(CONFIG_ARCH_POSIX)
9773+
k_cpu_idle();
9774+
#endif
9775+
t = k_uptime_get(); /* returns current uptime in milliseconds */
9776+
return (word32)(t / 1000);
97729777
}
97739778

97749779
#elif defined(WOLFSSL_LINUXKM)

src/tls13.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,10 +1910,12 @@ int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store)
19101910
#elif defined(WOLFSSL_ZEPHYR)
19111911
word32 TimeNowInMilliseconds(void)
19121912
{
1913+
int64_t t;
19131914
#if defined(CONFIG_ARCH_POSIX)
19141915
k_cpu_idle();
19151916
#endif
1916-
return (word32)k_uptime_get() / 1000;
1917+
t = k_uptime_get(); /* returns current uptime in milliseconds */
1918+
return (word32)t;
19171919
}
19181920

19191921
#else
@@ -2201,10 +2203,12 @@ int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store)
22012203
#elif defined(WOLFSSL_ZEPHYR)
22022204
sword64 TimeNowInMilliseconds(void)
22032205
{
2206+
int64_t t;
22042207
#if defined(CONFIG_ARCH_POSIX)
22052208
k_cpu_idle();
22062209
#endif
2207-
return (sword64)k_uptime_get() / 1000;
2210+
t = k_uptime_get(); /* returns current uptime in milliseconds */
2211+
return (sword64)t;
22082212
}
22092213

22102214
#else

wolfcrypt/benchmark/benchmark.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12998,13 +12998,13 @@ void bench_sphincsKeySign(byte level, byte optim)
1299812998

1299912999
double current_time(int reset)
1300013000
{
13001+
int64_t t;
1300113002
(void)reset;
13002-
1300313003
#if defined(CONFIG_ARCH_POSIX)
1300413004
k_cpu_idle();
1300513005
#endif
13006-
13007-
return (double)k_uptime_get() / 1000;
13006+
t = k_uptime_get(); /* returns current uptime in milliseconds */
13007+
return (double)(t / 1000);
1300813008
}
1300913009

1301013010
#elif defined(WOLFSSL_NETBURNER)

zephyr/CMakeLists.txt

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
if(CONFIG_WOLFSSL)
22
zephyr_interface_library_named(wolfSSL)
3-
3+
44
if(CONFIG_WOLFSSL_BUILTIN)
5-
target_compile_definitions(wolfSSL INTERFACE
6-
WOLFSSL_SETTINGS_FILE="${CONFIG_WOLFSSL_SETTINGS_FILE}"
7-
)
8-
5+
if(CONFIG_WOLFSSL_SETTINGS_FILE)
6+
target_compile_definitions(wolfSSL INTERFACE
7+
WOLFSSL_SETTINGS_FILE="${CONFIG_WOLFSSL_SETTINGS_FILE}"
8+
)
9+
zephyr_include_directories(
10+
${APPLICATION_CONFIG_DIR}
11+
${APPLICATION_CONFIG_DIR}/src
12+
)
13+
endif()
14+
915
zephyr_include_directories(
1016
${ZEPHYR_CURRENT_MODULE_DIR}
1117
${ZEPHYR_CURRENT_MODULE_DIR}/wolfssl
1218
${ZEPHYR_CURRENT_MODULE_DIR}/zephyr
1319
)
14-
20+
1521
zephyr_library()
1622
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/zephyr/zephyr_init.c)
17-
23+
1824
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/src/crl.c)
1925
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/src/dtls13.c)
2026
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/src/internal.c)
@@ -25,8 +31,29 @@ if(CONFIG_WOLFSSL)
2531
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/src/tls.c)
2632
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/src/tls13.c)
2733
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/src/wolfio.c)
28-
34+
35+
# FIPS Boundary
36+
if(CONFIG_WOLFCRYPT_FIPS)
37+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wolfcrypt_first.c)
38+
endif()
39+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/hmac.c)
40+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/random.c)
41+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/kdf.c)
42+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/rsa.c)
43+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/ecc.c)
2944
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/aes.c)
45+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha.c)
46+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha256.c)
47+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha512.c)
48+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha3.c)
49+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/dh.c)
50+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/cmac.c)
51+
if(CONFIG_WOLFCRYPT_FIPS)
52+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/fips.c)
53+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/fips_test.c)
54+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wolfcrypt_last.c)
55+
endif()
56+
3057
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/arc4.c)
3158
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/asm.c)
3259
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/asn.c)
@@ -36,18 +63,15 @@ if(CONFIG_WOLFSSL)
3663
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/camellia.c)
3764
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/chacha.c)
3865
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/chacha20_poly1305.c)
39-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/cmac.c)
4066
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/coding.c)
4167
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/compress.c)
4268
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/cpuid.c)
4369
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/cryptocb.c)
4470
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/curve25519.c)
4571
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/curve448.c)
4672
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/des3.c)
47-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/dh.c)
4873
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/dilithium.c)
4974
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/dsa.c)
50-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/ecc.c)
5175
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/ecc_fp.c)
5276
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/eccsi.c)
5377
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/ed25519.c)
@@ -58,15 +82,11 @@ if(CONFIG_WOLFSSL)
5882
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/fe_448.c)
5983
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/fe_low_mem.c)
6084
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/fe_operations.c)
61-
#zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/fips.c)
62-
#zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/fips_test.c)
6385
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/ge_448.c)
6486
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/ge_low_mem.c)
6587
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/ge_operations.c)
6688
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/hash.c)
67-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/hmac.c)
6889
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/integer.c)
69-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/kdf.c)
7090
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/logging.c)
7191
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/md2.c)
7292
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/md4.c)
@@ -77,15 +97,9 @@ if(CONFIG_WOLFSSL)
7797
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/pkcs7.c)
7898
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/poly1305.c)
7999
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/pwdbased.c)
80-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/random.c)
81100
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/ripemd.c)
82-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/rsa.c)
83101
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sakke.c)
84102
#zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/selftest.c)
85-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha.c)
86-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha256.c)
87-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha3.c)
88-
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha512.c)
89103
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/signature.c)
90104
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/siphash.c)
91105
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sp_arm32.c)
@@ -104,8 +118,6 @@ if(CONFIG_WOLFSSL)
104118
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wc_encrypt.c)
105119
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wc_pkcs11.c)
106120
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wc_port.c)
107-
#zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wolfcrypt_first.c)
108-
#zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wolfcrypt_last.c)
109121
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wolfevent.c)
110122
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/wolfmath.c)
111123

@@ -115,7 +127,38 @@ if(CONFIG_WOLFSSL)
115127
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/psa/psa_hash.c)
116128
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/psa/psa_pkcbs.c)
117129
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/st/stm32.c)
118-
130+
131+
if(CONFIG_WOLFCRYPT_ARMASM)
132+
# tested with board: "qemu_kvm_arm64"
133+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-aes.c)
134+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-32-aes-asm_c.c)
135+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-sha256.c)
136+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-32-sha256-asm_c.c)
137+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-sha512.c)
138+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-sha512-asm_c.c)
139+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-sha3-asm_c.c)
140+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-poly1305.c)
141+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-chacha.c)
142+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-curve25519_c.c)
143+
144+
# Note: The cmake/gcc-m-cpu.cmake make need updated to add "+crypto -mstrict-align"
145+
set(TOOLCHAIN_C_FLAGS "-mcpu=cortex-a53+crypto -mstrict-align")
146+
endif()
147+
148+
if(CONFIG_WOLFCRYPT_INTELASM)
149+
# tested with board: "qemu_x86_64"
150+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha256_asm.S)
151+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha512_asm.S)
152+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha3_asm.S)
153+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/chacha_asm.S)
154+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/poly1305_asm.S)
155+
156+
# AESNI
157+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/aes_asm.S)
158+
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/aes_gcm_x86_asm.S)
159+
set(TOOLCHAIN_C_FLAGS "-march=native -maes -msse4 -mpclmul ")
160+
endif()
161+
119162
zephyr_library_link_libraries(wolfSSL)
120163

121164
target_compile_definitions(wolfSSL INTERFACE WOLFSSL_ZEPHYR)
@@ -125,14 +168,14 @@ if(CONFIG_WOLFSSL)
125168
endif()
126169
else()
127170
assert(CONFIG_WOLFSSL_LIBRARY "wolfSSL was enabled, but neither BUILTIN or LIBRARY was selected.")
128-
171+
129172
# NB: CONFIG_WOLFSSL_LIBRARY is not regression tested and is
130173
# therefore susceptible to bit rot
131-
174+
132175
target_include_directories(wolfSSL INTERFACE
133176
${CONFIG_WOLFSSL_INSTALL_PATH}
134177
)
135-
178+
136179
zephyr_link_libraries(
137180
wolfssl_external
138181
-L${CONFIG_WOLFSSL_INSTALL_PATH}
@@ -142,7 +185,7 @@ if(CONFIG_WOLFSSL)
142185
# wolfssl to link with gcc we need to ensure it is placed
143186
# after wolfssl_external on the linkers command line.
144187
endif()
145-
188+
146189
target_link_libraries(wolfSSL INTERFACE zephyr_interface)
147190

148191
endif()

zephyr/Kconfig

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ endchoice
5353
config WOLFSSL_SETTINGS_FILE
5454
string "wolfSSL settings file"
5555
depends on WOLFSSL_BUILTIN
56-
default "user_settings-tls-generic.h"
5756
help
5857
Use a specific wolfSSL settings file. The default config file
5958
file can be tweaked with Kconfig. The default settings is
@@ -64,6 +63,26 @@ config WOLFSSL_SETTINGS_FILE
6463

6564
rsource "Kconfig.tls-generic"
6665

66+
config WOLFCRYPT_FIPS
67+
bool "wolfCrypt FIPS support"
68+
depends on WOLFSSL_BUILTIN
69+
help
70+
Enables FIPS support in wolfCrypt. Requires the wolfSSL FIPS ready
71+
download that includes fips.c/fips_test.c.
72+
73+
config WOLFCRYPT_ARMASM
74+
bool "wolfCrypt ARM Assembly support"
75+
depends on WOLFSSL_BUILTIN
76+
help
77+
wolfCrypt ARM (ARMv8/ARMv7) assembly support for AES, SHA-2, SHA-3,
78+
ChaCha20/Poly1305 and Curve25519
79+
80+
config WOLFCRYPT_INTELASM
81+
bool "wolfCrypt Intel Assembly support"
82+
depends on WOLFSSL_BUILTIN
83+
help
84+
wolfCrypt Intel Aassembly support (AVX/AVX2/AESNI)
85+
6786
config WOLFSSL_DEBUG
6887
bool "wolfSSL debug activation"
6988
depends on WOLFSSL_BUILTIN

zephyr/include.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ EXTRA_DIST+= zephyr/Kconfig.tls-generic
88
EXTRA_DIST+= zephyr/zephyr_init.c
99
EXTRA_DIST+= zephyr/module.yml
1010
EXTRA_DIST+= zephyr/wolfssl/options.h
11-
EXTRA_DIST+= zephyr/nrf5340dk_nrf5340_user_settings.h
1211
EXTRA_DIST+= zephyr/user_settings.h
13-
EXTRA_DIST+= zephyr/user_settings-tls-generic.h
1412
EXTRA_DIST+= zephyr/README.md
1513
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/
1614
EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/CMakeLists.txt

0 commit comments

Comments
 (0)