Aarch64 asm: convert to generated - #9284
Conversation
980a7b3 to
7cc4556
Compare
|
retest this please (twice) . /host/pkgs/sdk-arm_24.60372.0/environment-setup-cortexa8hf-neon-poky-linux-gnueabi |
dgarske
left a comment
There was a problem hiding this comment.
Really great work on this!! I am having an issue with Pi4 with armv8 without crypto on release build (works with debug or latest master).
PI4:pi@raspberrypi:~/wolfssl $ ./configure --enable-armasm=no-crypto CFLAGS="-g" --disable-shared && make
PI4:pi@raspberrypi:~/wolfssl $ gdb ./wolfcrypt/test/testwolfcrypt
GNU gdb (Debian 8.2.1-2+b3) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./wolfcrypt/test/testwolfcrypt...done.
(gdb) r
Starting program: /home/pi/wolfssl/wolfcrypt/test/testwolfcrypt
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
Math: Multi-Precision: Wolf(SP) word-size=64 bits=4096 sp_int.c
Assembly Speedups: ARMASM NO_HW_CRYPTO ALIGN
------------------------------------------------------------------------------
wolfSSL version 5.8.2
------------------------------------------------------------------------------
error test passed!
MEMORY test passed!
base64 test passed!
asn test passed!
SHA test passed!
SHA-224 test passed!
SHA-256 test passed!
SHA-384 test passed!
SHA-512 test passed!
SHA-512/224 test passed!
SHA-512/256 test passed!
SHA-3 test passed!
Program received signal SIGSEGV, Segmentation fault.
__memcpy_generic () at ../sysdeps/aarch64/multiarch/../memcpy.S:99
99 ../sysdeps/aarch64/multiarch/../memcpy.S: No such file or directory.
(gdb) bt
#0 __memcpy_generic () at ../sysdeps/aarch64/multiarch/../memcpy.S:99
#1 0x000000555556b730 in Sha256Update (len=3434320218, data=0x825a15a7e57d21f0 <error: Cannot access memory at address 0x825a15a7e57d21f0>, sha256=0x7fffffef10)
at wolfcrypt/src/sha256.c:1419
#2 wc_Sha256Update (sha256=sha256@entry=0x7fffffef10, data=data@entry=0x825a15a7e57d21f0 <error: Cannot access memory at address 0x825a15a7e57d21f0>,
len=len@entry=3434320218) at wolfcrypt/src/sha256.c:1607
#3 0x000000555556a45c in Hash_df (drbg=drbg@entry=0x7ffffff020, out=0x7ffffff048 "",
out@entry=0x7ffffff028 "n/\217\343\315͉B\274\031\211\vp\350\235\323~\364m\373\334\027\302\t\224\033\033#d\027\263p", type=<optimized out>,
type@entry=4 '\004', inA=0x825a15a7e57d21f0 <error: Cannot access memory at address 0x825a15a7e57d21f0>,
inA@entry=0x7ffffff150 "\246Z\320\363E\333N\016\377\350uâ\347\037B\307\022\235b\017\365\301\031\251\357U\360Q\205\340\373\205\201\371\061u\027'n\006\351`}\333\313\314.c63w\344\036\206F\215\353\n\264\250\355h?j\023NG\340", <incomplete sequence \307>, inASz=3434320218, inASz@entry=48, inB=inB@entry=0x0,
inBSz=inBSz@entry=0, outSz=23) at wolfcrypt/src/random.c:422
#4 0x000000555556a590 in Hash_DRBG_Instantiate (drbg=drbg@entry=0x7ffffff020,
seed=0x7ffffff150 "\246Z\320\363E\333N\016\377\350uâ\347\037B\307\022\235b\017\365\301\031\251\357U\360Q\205\340\373\205\201\371\061u\027'n\006\351`}\333\313\314.c63w\344\036\206F\215\353\n\264\250\355h?j\023NG\340", <incomplete sequence \307>, seedSz=48, nonce=nonce@entry=0x0, nonceSz=nonceSz@entry=0,
heap=heap@entry=0x0, devId=-2) at wolfcrypt/src/random.c:745
#5 0x000000555556ad98 in wc_RNG_HealthTest_ex (reseed=0, nonce=nonce@entry=0x0, nonceSz=nonceSz@entry=0, seedA=<optimized out>, seedASz=<optimized out>,
seedB=0x0, seedBSz=0, output=0x7ffffff2b0 "\210\205\354\367\177", outputSz=128, heap=heap@entry=0x0, devId=devId@entry=-2) at wolfcrypt/src/random.c:2200
#6 0x000000555556ae8c in wc_RNG_HealthTest (reseed=<optimized out>, seedA=<optimized out>, seedASz=<optimized out>, seedB=<optimized out>,
seedBSz=<optimized out>, output=<optimized out>, outputSz=<optimized out>) at wolfcrypt/src/random.c:2159
#7 0x00000055555612ac in random_test () at wolfcrypt/test/test.c:18868
#8 0x00000055555672dc in wolfcrypt_test (args=0x7ffffff398) at wolfcrypt/test/test.c:1798
#9 0x0000005555567b28 in wolfcrypt_test_main (argc=<optimized out>, argv=<optimized out>) at wolfcrypt/test/test.c:2721
#10 0x00000055555530ac in main (argc=<optimized out>, argv=<optimized out>) at wolfcrypt/test/test.c:2626
(gdb)
|
This is Aarch32 SHA-256 assembly with no hardware crypto? Does the inline assembly in the C file work? (Can't get it to fail with emulator.) |
7cc4556 to
516d263
Compare
|
Rebase |
Its Aarch64 with no crypto assembly instructions and only in release build (-O2). |
Not sure if this is useful, but get error with: |
|
retest this please |
That happens in master too. Not sure it its related. |
Algorithms now generated: SHA-256 SHA-512 ChaCha20 Poly1305 AES-ECB AES-CBC AES-CTR AES-GCM + streaming AES-XTS AES SetKey ARM32 asm algorithms generated now too: SHA-256 SHA-512 ChaCha20 AES-ECB AES-CBC AES-CTR AES-GCM AES-XTS AES SetKey Removed use of ARM specific implementations of algorithms. (armv8-aes.c)
516d263 to
9c1462a
Compare
|
Love this PR! Thank you Sean! Note: this PR cleans up a bunch of duplicate code in the wolfcrypt/src/port/armv8-*.c. For example wolfBoot will need the following patches after this PR is merged: |
There was a problem hiding this comment.
Pull Request Overview
This PR converts Aarch64 and ARM32 assembly implementations from hand-written C/assembly to generated code, covering multiple cryptographic algorithms including SHA-256, SHA-512, ChaCha20, Poly1305, and various AES modes.
Key Changes:
- Replaced hand-written ARM assembly implementations with generated versions for major cryptographic algorithms
- Removed deprecated ARM-specific implementation files (armv8-aes.c, armv8-sha256.c, armv8-sha512.c, armv8-chacha.c, armv8-poly1305.c)
- Updated function signatures and naming conventions across ARM assembly implementations
- Modified build configuration to use generated assembly source files
Reviewed Changes
Copilot reviewed 58 out of 66 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| zephyr/CMakeLists.txt | Updated build to use generated assembly files instead of hand-written C implementations |
| wolfssl/wolfcrypt/sha512.h | Changed function declarations to use WOLFSSL_LOCAL and updated naming conventions |
| wolfssl/wolfcrypt/sha256.h | Added transform function declarations for ARM assembly variants |
| wolfssl/wolfcrypt/settings.h | Removed WOLFSSL_ARMASM from NO_HASH_RAW condition |
| wolfssl/wolfcrypt/poly1305.h | Updated Poly1305 structure definitions and function declarations for ARM platforms |
| wolfssl/wolfcrypt/chacha.h | Changed function visibility to WOLFSSL_LOCAL for ARM assembly functions |
| wolfssl/wolfcrypt/aes.h | Extensive updates to AES function declarations for both Aarch64 and ARM32 platforms |
| wolfcrypt/test/test.c | Added conditional compilation guards for AES_128 specific tests |
| wolfcrypt/src/sha512.c | Added ARM assembly transform implementation with dynamic dispatch |
| wolfcrypt/src/sha256.c | Added ARM assembly support with conditional compilation |
| wolfcrypt/src/port/arm/* | Updated assembly implementations with naming changes and constraint fixes |
| tests/api/test_sha256.c | Removed WOLFSSL_ARMASM from conditional compilation checks |
| tests/api/test_ossl_cipher.c | Added additional feature checks for AES tests |
Comments suppressed due to low confidence (4)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
It is true that the registers have changed. Intentionally. |
…9284: in configure.ac, add BUILD_FIPS_V5_PLUS and BUILD_FIPS_V6_PLUS conditionals, and fix BUILD_FIPS_V6 conditional to match v6 only; in src/include.am, add LEGACY_ARMASM_foo and NEW_ARMASM_foo helper variables, restore pre-PR9284 armasm clauses, and add or update several FIPS gates as needed; add empty wolfcrypt/src/port/arm/{armv8-aes.c,armv8-sha256.c,armv8-sha512.c} to mollify autotools, and in wolfcrypt/src/include.am, restore them to EXTRA_DIST if FIPS v5 or v6.
Description
Algorithms now generated:
SHA-256
SHA-512
ChaCha20
Poly1305
AES-ECB
AES-CBC
AES-CTR
AES-GCM + streaming
AES-XTS
AES SetKey
ARM32 asm algorithms generated now too:
SHA-256
SHA-512
ChaCha20
AES-ECB
AES-CBC
AES-CTR
AES-GCM
AES-XTS
AES SetKey
Removed use of ARM specific implementations of algorithms. (armv8-aes.c)
Testing
Regression tested Aarch64 and Aarch32.
Checklist