Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aarch64: make code compile when no hardware crypto avail #8277

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

SparkiDev
Copy link
Contributor

@SparkiDev SparkiDev commented Dec 11, 2024

Description

Detects availability of instructions for Aarch64.

Testing

With and without WOLFSSL_ARMASM_NO_HW_CRYPTO

./configure --enable-armasm CFLAGS="-DWOLFSSL_ARMASM_NO_HW_CRYPTO" && make check

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@SparkiDev SparkiDev self-assigned this Dec 11, 2024
@SparkiDev SparkiDev force-pushed the aarch64_no_crypto branch 3 times, most recently from ada3af9 to 7c9b38d Compare December 11, 2024 11:58
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Rpi4 that does not support aes/sha instructions.

./configure --enable-armasm && make
$ ./wolfcrypt/test/testwolfcrypt
Math: 	Multi-Precision: Wolf(SP) word-size=64 bits=4096 sp_int.c
------------------------------------------------------------------------------
 wolfSSL version 5.7.4
------------------------------------------------------------------------------
error    test passed!
MEMORY   test passed!
base64   test passed!
asn      test passed!
Illegal instruction
./configure --enable-armasm CFLAGS="-DWOLFSSL_ARMASM_NO_HW_CRYPTO" && make
  CCLD     src/libwolfssl.la
/usr/bin/ld: wolfcrypt/src/port/arm/.libs/src_libwolfssl_la-armv8-aes.o: in function `wc_AesSetIV':
armv8-aes.c:(.text+0x100): multiple definition of `wc_AesSetIV'; wolfcrypt/src/.libs/src_libwolfssl_la-aes.o:aes.c:(.text+0x1620): first defined here
/usr/bin/ld: wolfcrypt/src/port/arm/.libs/src_libwolfssl_la-armv8-aes.o: in function `wc_AesSetKey':
armv8-aes.c:(.text+0x148): multiple definition of `wc_AesSetKey'; wolfcrypt/src/.libs/src_libwolfssl_la-aes.o:aes.c:(.text+0x1668): first defined here
/usr/bin/ld: wolfcrypt/src/port/arm/.libs/src_libwolfssl_la-armv8-aes.o: in function `wc_AesCbcEncrypt':
armv8-aes.c:(.text+0x230): multiple definition of `wc_AesCbcEncrypt'; wolfcrypt/src/.libs/src_libwolfssl_la-aes.o:aes.c:(.text+0x1e18): first defined here
/usr/bin/ld: wolfcrypt/src/port/arm/.libs/src_libwolfssl_la-armv8-aes.o: in function `wc_AesCbcDecrypt':
armv8-aes.c:(.text+0x2a8): multiple definition of `wc_AesCbcDecrypt'; wolfcrypt/src/.libs/src_libwolfssl_la-aes.o:aes.c:(.text+0x1f78): first defined here
/usr/bin/ld: wolfcrypt/src/port/arm/.libs/src_libwolfssl_la-armv8-aes.o: in function `GenerateM0':
armv8-aes.c:(.text+0x320): multiple definition of `GenerateM0'; wolfcrypt/src/.libs/src_libwolfssl_la-aes.o:aes.c:(.text+0x2f70): first defined here
/usr/bin/ld: wolfcrypt/src/port/arm/.libs/src_libwolfssl_la-armv8-aes.o: in function `wc_AesGcmSetKey':
armv8-aes.c:(.text+0xb60): multiple definition of `wc_AesGcmSetKey'; wolfcrypt/src/.libs/src_libwolfssl_la-aes.o:aes.c:(.text+0x37b0): first defined here
/usr/bin/ld: wolfcrypt/src/port/arm/.libs/src_libwolfssl_la-armv8-aes.o: in function `wc_AesGcmEncrypt':
armv8-aes.c:(.text+0xbf8): multiple definition of `wc_AesGcmEncrypt'; wolfcrypt/src/.libs/src_libwolfssl_la-aes.o:aes.c:(.text+0x3878): first defined here
/usr/bin/ld: wolfcrypt/src/port/arm/.libs/src_libwolfssl_la-armv8-aes.o: in function `wc_AesGcmDecrypt':
armv8-aes.c:(.text+0xf60): multiple definition of `wc_AesGcmDecrypt'; wolfcrypt/src/.libs/src_libwolfssl_la-aes.o:aes.c:(.text+0x3c28): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:6383: src/libwolfssl.la] Error 1

@SparkiDev
Copy link
Contributor Author

SparkiDev commented Dec 11, 2024

Need to specify WOLFSSL_ARMASM_NO_HW_CRYPTO to force compilation without use of hardware crypto instructions.
It will detect instructions availability based on supported OSes. You don't have an OS, so, if you have the "mrs" instruction available then define WOLFSSL_AARCH64_PRIVILEGE_MODE.
Otherwise it has to go on build flags.

@dgarske
Copy link
Contributor

dgarske commented Dec 11, 2024

Need to specify WOLFSSL_ARMASM_NO_HW_CRYPTO to force compilation without use of hardware crypto instructions. It will detect instructions availability based on supported OSes. You don't have an OS, so, if you have the "mrs" instruction available then define WOLFSSL_AARCH64_PRIVILEGE_MODE. Otherwise it has to go on build flags.

The second test uses WOLFSSL_ARMASM_NO_HW_CRYPTO and gets duplicate symbols.

@SparkiDev SparkiDev force-pushed the aarch64_no_crypto branch 5 times, most recently from df4712f to 92c74e5 Compare December 12, 2024 00:48
@SparkiDev SparkiDev assigned wolfSSL-Bot and unassigned SparkiDev Dec 12, 2024
dgarske
dgarske previously approved these changes Dec 12, 2024
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works wonderfully now! Anyway to get WOLFSSL_ARMASM_NO_HW_CRYPTO as a configure option??

Detects availability of instructions for Aarch64.
@SparkiDev
Copy link
Contributor Author

SparkiDev commented Dec 12, 2024

Added support for --enable-armasm=no-crypto

@dgarske dgarske merged commit 79d9b2d into wolfSSL:master Dec 12, 2024
145 checks passed
@douzzer
Copy link
Contributor

douzzer commented Dec 16, 2024

note, reverted by #8290, then merged again after rework as #8293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants