Skip to content

Commit

Permalink
Experimental support for Intel and ARM ASM with Zephyr. Related to is…
Browse files Browse the repository at this point in the history
…sue wolfSSL#7116.
  • Loading branch information
dgarske committed Mar 18, 2024
1 parent 03e306a commit face8b6
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
31 changes: 31 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,37 @@ if(CONFIG_WOLFSSL)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/psa/psa_pkcbs.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/st/stm32.c)

if(CONFIG_WOLFCRYPT_ARMASM)
# tested with board: "qemu_kvm_arm64"
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-aes.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-32-aes-asm_c.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-sha256.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-32-sha256-asm_c.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-sha512.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-sha512-asm_c.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-sha3-asm_c.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-poly1305.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-chacha.c)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/arm/armv8-curve25519_c.c)

set(MCPU_FLAGS "-mcpu=cortex-a53+crypto -mstrict-align")

This comment has been minimized.

Copy link
@ickochar

ickochar Mar 19, 2024

This is not working as expected in zephyr if I compile for my board. ( intel_socfpga_agilex_socdk )

This comment has been minimized.

Copy link
@ickochar

ickochar Mar 19, 2024

If I override this option in zephyr cmake folder, the I am able to compile and use arm assembly instruction for crypto operation :

diff --git a/cmake/gcc-m-cpu.cmake b/cmake/gcc-m-cpu.cmake

?
--- a/cmake/gcc-m-cpu.cmake
+++ b/cmake/gcc-m-cpu.cmake
@@ -72,7 +72,7 @@ if("${ARCH}" STREQUAL "arm")
endif()
elseif("${ARCH}" STREQUAL "arm64")
if(CONFIG_CPU_CORTEX_A53)

  • set(GCC_M_CPU cortex-a53)
  • set(GCC_M_CPU cortex-a53+crypto -mstrict-align)
    elseif(CONFIG_CPU_CORTEX_A55)
    set(GCC_M_CPU cortex-a55)
    elseif(CONFIG_CPU_CORTEX_A76)
#set(MCPU_FLAGS "-mcpu=generic+crypto -mstrict-align")
endif()

if(CONFIG_WOLFCRYPT_INTELASM)
# tested with board: "qemu_x86_64"
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha256_asm.S)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha512_asm.S)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/sha3_asm.S)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/chacha_asm.S)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/poly1305_asm.S)

# issues with aesni
#zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/aes_asm.S)
#zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/aes_gcm_x86_asm.S)
#set(MCPU_FLAGS "-march=native -maes -msse4 -mpclmul ")
endif()

zephyr_library_link_libraries(wolfSSL)

target_compile_definitions(wolfSSL INTERFACE WOLFSSL_ZEPHYR)
Expand Down
13 changes: 13 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ config WOLFCRYPT_FIPS
Enables FIPS support in wolfCrypt. Requires the wolfSSL FIPS ready
download that includes fips.c/fips_test.c.

config WOLFCRYPT_ARMASM
bool "wolfCrypt ARM Assembly support"
depends on WOLFSSL_BUILTIN
help
wolfCrypt ARM (ARMv8/ARMv7) assembly support for AES, SHA-2, SHA-3,
ChaCha20/Poly1305 and Curve25519

config WOLFCRYPT_INTELASM
bool "wolfCrypt Intel Assembly support"
depends on WOLFSSL_BUILTIN
help
wolfCrypt Intel Aassembly support (AVX/AVX2/AESNI)

config WOLFSSL_DEBUG
bool "wolfSSL debug activation"
depends on WOLFSSL_BUILTIN
Expand Down
4 changes: 4 additions & 0 deletions zephyr/samples/wolfssl_benchmark/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ CONFIG_LOG_BUFFER_SIZE=15360
#CONFIG_WOLFSSL_DEBUG=y

# Entropy
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR=y

# Optional ARM or Intel Assembly
#CONFIG_WOLFCRYPT_ARMASM=y
#CONFIG_WOLFCRYPT_INTELASM=y
2 changes: 1 addition & 1 deletion zephyr/samples/wolfssl_test/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ CONFIG_LOG_BUFFER_SIZE=15360
#CONFIG_WOLFSSL_DEBUG=y

# Entropy
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR=y

1 change: 1 addition & 0 deletions zephyr/samples/wolfssl_tls_thread/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Kernel options
CONFIG_MAIN_STACK_SIZE=16384
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_INIT_STACKS=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536

Expand Down
27 changes: 27 additions & 0 deletions zephyr/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,33 @@ extern "C" {
#endif
#endif

/* ------------------------------------------------------------------------- */
/* Assembly Speedups for Symmetric Algorithms */
/* ------------------------------------------------------------------------- */

#ifdef CONFIG_WOLFCRYPT_ARMASM
#define WOLFSSL_ARMASM
#define WOLFSSL_NO_HASH_RAW
#define WOLFSSL_ARMASM_INLINE /* use inline .c versions */
#define WOLFSSL_ARMASM_NO_HW_CRYPTO /* enable if processor does not support aes/sha instructions */
#define WOLFSSL_ARMASM_NO_NEON
/* Default is ARMv8 */

#if 0 /* ARMv7 */
#define WOLFSSL_ARM_ARCH 7
#endif
#endif

#ifdef CONFIG_WOLFCRYPT_INTELASM
#define USE_INTEL_SPEEDUP
#define WOLFSSL_X86_64_BUILD /* 64-bit */
//#define WOLFSSL_X86_BUILD /* 32-bit */

/* Issues with building AESNI "_mm_aesimc_si128" always_inline */
//#define WOLFSSL_AESNI
#endif


/* ------------------------------------------------------------------------- */
/* Debugging */
Expand Down

0 comments on commit face8b6

Please sign in to comment.