Skip to content

Aarch64 asm: convert to generated - #9284

Merged
JacobBarthelmeh merged 1 commit into
wolfSSL:masterfrom
SparkiDev:aarch64_asm_gen
Oct 22, 2025
Merged

JacobBarthelmeh merged 1 commit into
wolfSSL:masterfrom
SparkiDev:aarch64_asm_gen

Conversation

@SparkiDev

Copy link
Copy Markdown
Contributor

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

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

@SparkiDev SparkiDev self-assigned this Oct 8, 2025
@SparkiDev
SparkiDev force-pushed the aarch64_asm_gen branch 8 times, most recently from 980a7b3 to 7cc4556 Compare October 9, 2025 22:20
@SparkiDev

SparkiDev commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

retest this please (twice)
log too old

. /host/pkgs/sdk-arm_24.60372.0/environment-setup-cortexa8hf-neon-poky-linux-gnueabi
Running configure script...
configure: error: unrecognized options: --with-libtool-sysroot
CONFIG RESULT = 1
Configuration Failed
�[1;31mError: OE2: without PAA test failed�[0m
Exiting with status: 3

@SparkiDev SparkiDev assigned wolfSSL-Bot and unassigned SparkiDev Oct 13, 2025
@SparkiDev
SparkiDev requested a review from wolfSSL-Bot October 13, 2025 00:25
@dgarske
dgarske requested review from dgarske and removed request for wolfSSL-Bot October 13, 2025 17:00

@dgarske dgarske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) 

@SparkiDev

Copy link
Copy Markdown
Contributor Author

This is Aarch32 SHA-256 assembly with no hardware crypto?
Or is it Aarch64?

Does the inline assembly in the C file work?

(Can't get it to fail with emulator.)

@SparkiDev

Copy link
Copy Markdown
Contributor Author

Rebase

@dgarske

dgarske commented Oct 14, 2025

Copy link
Copy Markdown
Member

This is Aarch32 SHA-256 assembly with no hardware crypto? Or is it Aarch64?

Does the inline assembly in the C file work?

(Can't get it to fail with emulator.)

Its Aarch64 with no crypto assembly instructions and only in release build (-O2). ./configure --enable-armasm=no-crypto CFLAGS="-g" --disable-shared && make.

@dgarske

dgarske commented Oct 14, 2025

Copy link
Copy Markdown
Member

This is Aarch32 SHA-256 assembly with no hardware crypto? Or is it Aarch64?
Does the inline assembly in the C file work?
(Can't get it to fail with emulator.)

Its Aarch64 with no crypto assembly instructions and only in release build (-O2). ./configure --enable-armasm=no-crypto CFLAGS="-g" --disable-shared && make.

Not sure if this is useful, but get error with: ./configure --enable-armasm=no-crypto,inline CFLAGS=-g --disable-shared && make

wolfcrypt/src/port/arm/armv8-sha512-asm_c.c: In function ‘Transform_Sha512_Len_neon’:
wolfcrypt/src/port/arm/armv8-sha512-asm_c.c:85:5: error: asm operand 3 probably doesn’t match constraints [-Werror]
     __asm__ __volatile__ (
     ^~~~~~~
wolfcrypt/src/port/arm/armv8-sha512-asm_c.c:85:5: error: asm operand 4 probably doesn’t match constraints [-Werror]
wolfcrypt/src/port/arm/armv8-sha512-asm_c.c:85:5: error: impossible constraint in ‘asm’

@SparkiDev

Copy link
Copy Markdown
Contributor Author

retest this please

@dgarske

dgarske commented Oct 14, 2025

Copy link
Copy Markdown
Member

This is Aarch32 SHA-256 assembly with no hardware crypto? Or is it Aarch64?
Does the inline assembly in the C file work?
(Can't get it to fail with emulator.)

Its Aarch64 with no crypto assembly instructions and only in release build (-O2). ./configure --enable-armasm=no-crypto CFLAGS="-g" --disable-shared && make.

Not sure if this is useful, but get error with: ./configure --enable-armasm=no-crypto,inline CFLAGS=-g --disable-shared && make

wolfcrypt/src/port/arm/armv8-sha512-asm_c.c: In function ‘Transform_Sha512_Len_neon’:
wolfcrypt/src/port/arm/armv8-sha512-asm_c.c:85:5: error: asm operand 3 probably doesn’t match constraints [-Werror]
     __asm__ __volatile__ (
     ^~~~~~~
wolfcrypt/src/port/arm/armv8-sha512-asm_c.c:85:5: error: asm operand 4 probably doesn’t match constraints [-Werror]
wolfcrypt/src/port/arm/armv8-sha512-asm_c.c:85:5: error: impossible constraint in ‘asm’

That happens in master too. Not sure it its related.

@dgarske dgarske assigned SparkiDev and unassigned SparkiDev Oct 20, 2025
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)
@dgarske

dgarske commented Oct 21, 2025

Copy link
Copy Markdown
Member

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:

diff --git a/arch.mk b/arch.mk
index b823cb44..39055ac8 100644
--- a/arch.mk
+++ b/arch.mk
@@ -105,9 +105,6 @@ ifeq ($(ARCH),AARCH64)
     ARCH_FLAGS=-mstrict-align
     CFLAGS+=$(ARCH_FLAGS) -DWOLFSSL_ARMASM -DWOLFSSL_ARMASM_INLINE -DWC_HASH_DATA_ALIGNMENT=8 -DWOLFSSL_AARCH64_PRIVILEGE_MODE
     WOLFCRYPT_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/cpuid.o \
-                      $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-sha256.o \
-                      $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-sha512.o \
-                      $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-aes.o \
                       $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-sha512-asm_c.o \
                       $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-sha3-asm_c.o
   endif
@@ -284,7 +281,6 @@ ifeq ($(CORTEX_A5),1)
   else
     MATH_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_arm32.o
     ifneq ($(NO_ARM_ASM),1)
-      OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-sha256.o
       OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-32-sha256-asm.o
       OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-32-sha256-asm_c.o
       CFLAGS+=-DWOLFSSL_SP_ARM32_ASM -DWOLFSSL_ARMASM -DWOLFSSL_ARMASM_NO_HW_CRYPTO \
@@ -296,10 +292,6 @@ else
   OBJS+=src/boot_arm.o
   ifneq ($(NO_ARM_ASM),1)
     CORTEXM_ARM_EXTRA_OBJS= \
-          $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-aes.o \
-          $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-chacha.o \
-          $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-sha256.o \
-          $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/armv8-sha512.o \
           $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-aes-asm.o \
           $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-aes-asm_c.o \
           $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-sha256-asm.o \
diff --git a/lib/wolfssl b/lib/wolfssl
index a06268f7..9c1462a9 160000
--- a/lib/wolfssl
+++ b/lib/wolfssl
@@ -1 +1 @@
-Subproject commit a06268f7050190600dd5353ec0d0a008ec3f0866
+Subproject commit 9c1462a9ecb5106ba7de9e257274c0ef232b86ed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread wolfcrypt/src/port/arm/armv8-32-mlkem-asm_c.c
Comment thread wolfcrypt/src/port/arm/armv8-32-mlkem-asm_c.c
@JacobBarthelmeh
JacobBarthelmeh merged commit 4daab8a into wolfSSL:master Oct 22, 2025
259 checks passed
dgarske added a commit to dgarske/wolfBoot that referenced this pull request Oct 22, 2025
@SparkiDev

Copy link
Copy Markdown
Contributor Author

It is true that the registers have changed. Intentionally.
The first 4 parameters are passed in the r0-r3 and the rest are on the stack.
The new code explicitly uses the registers and not using explicit registers appears to work too - due the fact that all other registers are reserved.

douzzer added a commit to douzzer/wolfssl that referenced this pull request Oct 23, 2025
…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.
danielinux pushed a commit to wolfSSL/wolfBoot that referenced this pull request Oct 23, 2025
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.

5 participants