Commit graph

44 commits

Author SHA1 Message Date
Dave Rodgman
c8d81ad54d
Merge pull request #7784 from daverodgman/aesce-unroll 2023-07-04 18:41:13 +01:00
Dave Rodgman
8c5fae2610 Add explanatory comment
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-06-27 09:43:55 +01:00
Dave Rodgman
9e868be13a Fix clang warning from -Wasm-operand-widths
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-06-27 09:27:27 +01:00
Dave Rodgman
4e5c63d652
Improve documentation in bn_mul.h
Co-authored-by: Tom Cosgrove <tom.cosgrove@arm.com>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-06-23 15:17:37 +01:00
Dave Rodgman
e6c9996d04 Work around updating pointers from ILP32
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-06-21 21:16:23 +01:00
Dave Rodgman
0400ae2f9b Fix pointer constraint in bn_mul.h
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-06-21 16:31:52 +01:00
Dave Rodgman
7fdfd70b19 Introduce MBEDTLS_COMPILER_IS_GCC
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-06-15 18:42:25 +01:00
Dave Rodgman
9a676a7f98 Comment tidy-up
Signed-off-by: Dave Rodgman <dave.rodgman@gmail.com>
2023-06-04 20:43:05 -04:00
Dave Rodgman
b6e06549f5 Rename MULADDC_PRESERVE_R1 etc to MULADDC_PRESERVE_SCRATCH etc
Signed-off-by: Dave Rodgman <dave.rodgman@gmail.com>
2023-06-04 20:42:17 -04:00
Dave Rodgman
f89e3c5fbd Improve docs & check for non-gcc compilers
Signed-off-by: Dave Rodgman <dave.rodgman@gmail.com>
2023-06-04 20:41:52 -04:00
Dave Rodgman
6df1e54c1d Do not use assembly on Thumb 1 / clang
Signed-off-by: Dave Rodgman <dave.rodgman@gmail.com>
2023-06-02 13:51:31 -04:00
Dave Rodgman
3964fe0f5e Improve ISA detection
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-25 18:53:57 +01:00
Dave Rodgman
12b14b2c97 Simplify ifdefs
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-25 13:02:13 +01:00
Dave Rodgman
b047bf64e2 Restrict use of r7 in Thumb 1 code
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-25 12:54:56 +01:00
Dave Rodgman
cee166e3f5 Don't use r7 in generic codepath
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-25 11:00:05 +01:00
Dave Rodgman
7d6ec95517 Revert to detecting __GNUCC__ instead of armclang
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-25 09:41:42 +01:00
Dave Rodgman
92e8a88390 Improve comments
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-25 08:10:33 +01:00
Dave Rodgman
5c5a6dece6 Give options clearer names
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-24 23:24:16 +01:00
Dave Rodgman
6adaca6062 Minor tidy-up
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-24 19:53:21 +01:00
Dave Rodgman
ffbb7c5edc Tidy-up macros and fix guards around option B
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-24 18:28:46 +01:00
Dave Rodgman
1416cba81f Gate all arm asm on Armv6 or better architecture
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-24 18:07:48 +01:00
Dave Rodgman
0ffc6f48fa First draft at fixing the choice of asm
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-24 17:19:10 +01:00
Dave Rodgman
4489c8dcef Disable bignum assembly for certain Arm M-class CPUs
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-05-24 12:06:48 +01:00
Dave Rodgman
cb0f2c4491 Tidy-up - move asm #define into build_info.h
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-01-20 14:04:48 +00:00
Gilles Peskine
449bd8303e Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:50:10 +01:00
David Horstmann
bec95320ba Don't restyle end of file
Move the *INDENT-ON* annotation to the end of the file so that
uncrustify does not restyle the later sections (since it introduces a
risk of future problems).

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-01-05 09:50:47 +00:00
David Horstmann
cb3b6ae580 Disable code style correction for bignum assembly
The inline assembly defined in bn_mul.h confuses code style parsing,
causing code style correction to fail. Disable code style correction for
the whole section gated by "#if defined(MBEDTLS_HAVE_ASM)" to prevent
this.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-01-04 17:50:08 +00:00
David Horstmann
e3d8f31ba1 Workaround Uncrustify parsing of "asm"
The following code:

 #ifndef asm
 #define asm __asm
 #endif

causes Uncrustify to stop correcting the rest of the file. This may be
due to parsing the "asm" keyword in the definition.

Work around this by wrapping the idiom in an *INDENT-OFF* comment
wherever it appears.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-01-03 11:07:09 +00:00
Dave Rodgman
92cd8642fa
Merge pull request #6090 from hanno-arm/fix_bnmul_arm_v7a
Remove encoding width suffix from Arm bignum assembly
2022-08-18 08:48:03 +01:00
Dave Rodgman
919ff15ecf
Merge pull request #4686 from Kazuyuki-Kimura/patch_#2020
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined
2022-07-29 17:08:11 +01:00
Peter Korsgaard
c0546e351f bn_mul.h: fix x86 PIC inline ASM compilation with GCC < 5
Fixes #1910

With ebx added to the MULADDC_STOP clobber list to fix #1550, the inline
assembly fails to build with GCC < 5 in PIC mode with the following error:

include/mbedtls/bn_mul.h:46:13: error: PIC register clobbered by ‘ebx’ in ‘asm’

This is because older GCC versions treated the x86 ebx register (which is
used for the GOT) as a fixed reserved register when building as PIC.

This is fixed by an improved register allocator in GCC 5+.  From the release
notes:

Register allocation improvements: Reuse of the PIC hard register, instead of
using a fixed register, was implemented on x86/x86-64 targets.  This
improves generated PIC code performance as more hard registers can be used.

https://www.gnu.org/software/gcc/gcc-5/changes.html

As a workaround, detect this situation and disable the inline assembly,
similar to the MULADDC_CANNOT_USE_R7 logic.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
2022-07-18 17:31:13 +01:00
Hanno Becker
907a367b50 Remove explicit width suffixes from Arm bignum assembly
Within the M-profile of the Arm architecture, some instructions
admit both a 16-bit and a 32-bit encoding. For those instructions,
some assemblers support the use of the .n (narrow) and .w (wide)
suffixes to force a choice of instruction encoding width.
Forcing the size of encodings may be useful to ensure alignment
of code, which can have a significant performance impact on some
microarchitectures.

It is for this reason that a previous commit introduced explicit
.w suffixes into what was believed to be M-profile only assembly
in library/bn_mul.h.

This change, however, introduced two issues:
- First, the assembly block in question is used also for Armv7-A
  systems, on which the .n/.w distinction is not meaningful
  (all instructions are 32-bit).
- Second, compiler support for .n/.w suffixes appears patchy,
  leading to compilation failures even when building for M-profile
  targets.

This commit removes the .w annotations in order to restore working
code, deferring controlled re-introduction for the sake of performance.

Fixes #6089.

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-07-15 12:00:58 +01:00
Kazuyuki Kimura
b88dbdded6 fix issue #2020
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined.

Signed-off-by: Kazuyuki Kimura <kim@wing.ocn.ne.jp>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-05-30 17:55:07 +01:00
Hanno Becker
606cb1626f Add comment explaining structure of UMAAL assembly
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-04-17 06:59:33 +01:00
Hanno Becker
d46d96cc3f Add 2-fold unrolled assembly for umaal based multiplication
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-04-17 06:19:55 +01:00
Hanno Becker
eacf3b9eb4 Simplify organization of inline assembly for bignum
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-04-17 06:16:03 +01:00
Hanno Becker
efdc519864 Reintroduce though-to-be unused variable in correct place
The variable is a local variable for the i386 bignum assembly only;
introduce it as part of the start/finish macros.

It can be noted that the variable is initialize to 0 within MULADDC_INIT,
so there are no data dependencies across blocks of MULADDC_INIT/CORE/STOP.

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-04-11 10:44:02 +01:00
David Horstmann
11c81df707 Fix aarch64 assembly for bignum multiplication
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 #4962, #4943
for further details.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2021-09-22 18:31:35 +01:00
Gilles Peskine
d337fbc4cb x86_64 MULADDC assembly: add missing constraints about memory
MULADDC_CORE reads from (%%rsi) and writes to (%%rdi). This fragment is
repeated up to 16 times, and %%rsi and %%rdi are s and d on entry
respectively. Hence the complete asm statement reads 16 64-bit words
from memory starting at s, and writes 16 64-bit words starting at d.

Without any declaration of modified memory, Clang 12 and Clang 13 generated
non-working code for mbedtls_mpi_mod_exp. The constraints make the unit
tests pass with Clang 12.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-09-15 15:51:43 +02:00
Dave Rodgman
34d8cd2892 Merge remote-tracking branch 'restricted/development-restricted' into mbedtls-3.0.0rc0-pr 2021-06-30 22:51:02 +01:00
Bence Szépkúti
c662b36af2 Replace all inclusions of config.h
Also remove preprocessor logic for MBEDTLS_CONFIG_FILE, since
build_info.h alreadyy handles it.

This commit was generated using the following script:

# ========================
#!/bin/sh
git ls-files | grep -v '^include/mbedtls/build_info\.h$' | xargs sed -b -E -i '
/^#if !?defined\(MBEDTLS_CONFIG_FILE\)/i#include "mbedtls/build_info.h"
//,/^#endif/d
'
# ========================

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2021-06-28 09:24:07 +01:00
Janos Follath
1107ee4e44 Add prefix to BYTES_TO_T_UINT_*
These macros were moved into a header and now check-names.sh is failing.
Add an MBEDTL_ prefix to the macro names to make it pass.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-25 12:46:40 +01:00
Janos Follath
8c70e815dd Move mpi constant macros to bn_mul.h
Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-24 14:48:38 +01:00
Chris Jones
4c5819c318 Move bn_mul.h to library/
Move `include/mbedtls/bn_mul.h` to `library/bn_mul.h`.

Update includes and references to `bn_mul.h` to new location.

Also remove internal headers from `cpp_dummy_build.cpp` as it should only
test public headers in the library.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
2021-03-10 12:52:37 +00:00
Renamed from include/mbedtls/bn_mul.h (Browse further)