Skip to content

Commit

Permalink
Fix aarch64 assembly for bignum multiplication
Browse files Browse the repository at this point in the history
Add memory constraints to the aarch64 inline assembly in MULADDC_STOP.
This fixes an issue where Clang 12 and 13 were generating
non-functional code on aarch64 platforms. See Mbed-TLS#4962, Mbed-TLS#4943
for further details.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
  • Loading branch information
davidhorstmann-arm committed Sep 24, 2021
1 parent 02e17c0 commit a23be22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.d/muladdc-aarch64-memory.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bugfix
* Add missing memory constraints in aarch64 inline assembly for
bignum multiplication.
Fixes #4962.
12 changes: 6 additions & 6 deletions include/mbedtls/bn_mul.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,18 @@
#define MULADDC_CORE \
"ldr x4, [%2], #8 \n\t" \
"ldr x5, [%1] \n\t" \
"mul x6, x4, %3 \n\t" \
"umulh x7, x4, %3 \n\t" \
"mul x6, x4, %4 \n\t" \
"umulh x7, x4, %4 \n\t" \
"adds x5, x5, x6 \n\t" \
"adc x7, x7, xzr \n\t" \
"adds x5, x5, %0 \n\t" \
"adc %0, x7, xzr \n\t" \
"str x5, [%1], #8 \n\t"

#define MULADDC_STOP \
: "+r" (c), "+r" (d), "+r" (s) \
: "r" (b) \
: "x4", "x5", "x6", "x7", "cc" \
#define MULADDC_STOP \
: "+r" (c), "+r" (d), "+r" (s), "+m" (*(uint64_t (*)[16]) d) \
: "r" (b), "m" (*(const uint64_t (*)[16]) s) \
: "x4", "x5", "x6", "x7", "cc" \
);

#endif /* Aarch64 */
Expand Down

0 comments on commit a23be22

Please sign in to comment.