Skip to content

Commit face8b6

Browse files
committed
Experimental support for Intel and ARM ASM with Zephyr. Related to issue #7116.
1 parent 03e306a commit face8b6

6 files changed

Lines changed: 77 additions & 1 deletion

File tree

zephyr/CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,37 @@ if(CONFIG_WOLFSSL)
128128
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/psa/psa_pkcbs.c)
129129
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/st/stm32.c)
130130

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+
set(MCPU_FLAGS "-mcpu=cortex-a53+crypto -mstrict-align")
145+
#set(MCPU_FLAGS "-mcpu=generic+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+
# issues with 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(MCPU_FLAGS "-march=native -maes -msse4 -mpclmul ")
160+
endif()
161+
131162
zephyr_library_link_libraries(wolfSSL)
132163

133164
target_compile_definitions(wolfSSL INTERFACE WOLFSSL_ZEPHYR)

zephyr/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ config WOLFCRYPT_FIPS
7070
Enables FIPS support in wolfCrypt. Requires the wolfSSL FIPS ready
7171
download that includes fips.c/fips_test.c.
7272

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+
7386
config WOLFSSL_DEBUG
7487
bool "wolfSSL debug activation"
7588
depends on WOLFSSL_BUILTIN

zephyr/samples/wolfssl_benchmark/prj.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ CONFIG_LOG_BUFFER_SIZE=15360
2626
#CONFIG_WOLFSSL_DEBUG=y
2727

2828
# Entropy
29+
CONFIG_TEST_RANDOM_GENERATOR=y
2930
CONFIG_ENTROPY_GENERATOR=y
3031
CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR=y
3132

33+
# Optional ARM or Intel Assembly
34+
#CONFIG_WOLFCRYPT_ARMASM=y
35+
#CONFIG_WOLFCRYPT_INTELASM=y

zephyr/samples/wolfssl_test/prj.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ CONFIG_LOG_BUFFER_SIZE=15360
2424
#CONFIG_WOLFSSL_DEBUG=y
2525

2626
# Entropy
27+
CONFIG_TEST_RANDOM_GENERATOR=y
2728
CONFIG_ENTROPY_GENERATOR=y
2829
CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR=y
29-

zephyr/samples/wolfssl_tls_thread/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Kernel options
22
CONFIG_MAIN_STACK_SIZE=16384
33
CONFIG_ENTROPY_GENERATOR=y
4+
CONFIG_TEST_RANDOM_GENERATOR=y
45
CONFIG_INIT_STACKS=y
56
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536
67

zephyr/user_settings.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,33 @@ extern "C" {
380380
#endif
381381
#endif
382382

383+
/* ------------------------------------------------------------------------- */
384+
/* Assembly Speedups for Symmetric Algorithms */
385+
/* ------------------------------------------------------------------------- */
386+
387+
#ifdef CONFIG_WOLFCRYPT_ARMASM
388+
#define WOLFSSL_ARMASM
389+
#define WOLFSSL_NO_HASH_RAW
390+
#define WOLFSSL_ARMASM_INLINE /* use inline .c versions */
391+
#define WOLFSSL_ARMASM_NO_HW_CRYPTO /* enable if processor does not support aes/sha instructions */
392+
#define WOLFSSL_ARMASM_NO_NEON
393+
394+
/* Default is ARMv8 */
395+
396+
#if 0 /* ARMv7 */
397+
#define WOLFSSL_ARM_ARCH 7
398+
#endif
399+
#endif
400+
401+
#ifdef CONFIG_WOLFCRYPT_INTELASM
402+
#define USE_INTEL_SPEEDUP
403+
#define WOLFSSL_X86_64_BUILD /* 64-bit */
404+
//#define WOLFSSL_X86_BUILD /* 32-bit */
405+
406+
/* Issues with building AESNI "_mm_aesimc_si128" always_inline */
407+
//#define WOLFSSL_AESNI
408+
#endif
409+
383410

384411
/* ------------------------------------------------------------------------- */
385412
/* Debugging */

0 commit comments

Comments
 (0)