diff --git a/ChangeLog.d/fix-tricore-muladdc-clobber.txt b/ChangeLog.d/fix-tricore-muladdc-clobber.txt new file mode 100644 index 0000000000..66ff793d2b --- /dev/null +++ b/ChangeLog.d/fix-tricore-muladdc-clobber.txt @@ -0,0 +1,8 @@ +Bugfix + * Fix the TriCore MULADDC inline assembly in library/bn_mul.h which was + missing register d5 (the high half of the e4 carry-in pair) from its + clobber list. On TriCore 1.8 (AURIX TC4xx) the compiler could allocate + a live value in d5 across the asm block, which the asm then overwrote, + corrupting the carry chain. This produced wrong results in + mbedtls_mpi_core_mla, making mbedtls_mpi_mod_mpi loop forever. Declare + all data registers the asm writes so the compiler does not reuse them. diff --git a/library/bn_mul.h b/library/bn_mul.h index 0738469db4..84053a1c46 100644 --- a/library/bn_mul.h +++ b/library/bn_mul.h @@ -653,7 +653,8 @@ "st.a %2, %%a2 \n\t" \ : "=m" (c), "=m" (d), "=m" (s) \ : "m" (s), "m" (d), "m" (c), "m" (b) \ - : "d0", "d1", "e2", "d4", "a2", "a3" \ + : "d0", "d1", "d2", "d3", "d4", "d5", \ + "a2", "a3" \ ); #endif /* TriCore */