17635 Commits

Author SHA1 Message Date
Sachin Parekh
15b55d406d ecp: Add support for hardware implementation of ECP routines
ESP32C2 has a hardware ECC accelerator that supports NIST P-192 and NIST P-256 curves,
which can increase the performance of the point multiplication and point
verification operation.

Provision is also added to fallback to software implementation in
case the curve is not from the supported curves

(cherry picked from commit e46cff44a1c47593aaf85d2e2686a464f8835a11)
2023-04-03 11:47:09 +05:30
Mahavir Jain
47fc4960b5 bignum: add provision for combined software and hardware MPI approach
For exponential mod (API mbedtls_mpi_exp_mod) operation, some ESP target
chips needs to have ability for both hardware and software implementation.

Hardware implementation provided performance advantage but it can only
support upto 3072 bit operations (e.g., ESP32-C3) and hence we fallback
to software implementation in such cases (e.g., 4096 bit operations).

Earlier this was handled using linker "--wrap" flag but that does not
work in all scenarios as API `mbedtls_mpi_exp_mod` is being used in
same tranlation (compilation unit).

This approach was found to be next best option with minimal changes in
mbedTLS library.

(cherry picked from commit 30c6840e0e85d9018f8fdcd9765c7f5102745691)
2023-04-03 11:45:05 +05:30
Angus Gratton
18a7b51814 mbedtls: Re-apply MBEDTLS_BIGNUM_ALT & related macros for custom bignum functions
(IDF-specific patch.)

(cherry picked from commit 1981b5462148f144ced63545d74168618be75aa2)
2023-04-03 11:43:40 +05:30
Paul Elliott
981743de6f
Merge pull request #1009 from paul-elliott-arm/mbedtls-2.28.3rc0-pr
Mbedtls 2.28.3rc0 pr - DO NOT MERGE
mbedtls-2.28.3
2023-03-24 15:54:53 +00:00
Dave Rodgman
e4f1aac0fd Bump version to 2.28.3
Command used: ./scripts/bump_version.sh --version 2.28.3

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-03-23 18:06:54 +00:00
Paul Elliott
2454a16fdd Update BRANCHES.md
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-03-23 11:27:21 +00:00
Paul Elliott
f18db1f631 Assemble changelog for 2.28.3 release
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-03-23 11:26:53 +00:00
Paul Elliott
0e4a4c570e Fix changelog formatting
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-03-23 11:21:38 +00:00
Paul Elliott
f10eb92751 Rename misnamed changelog entries
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-03-23 11:18:17 +00:00
Tom Cosgrove
9bf344fddd Add security entry to ChangeLog for AES-NI
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-23 11:14:27 +00:00
Paul Elliott
a183e1d53d Merge branch 'mbedtls-2.28-restricted' into mbedtls-2.28.3rc0-pr
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-03-21 15:34:35 +00:00
Paul Elliott
18573354f7
Merge pull request #7276 from yanrayw/2.28-6173-split-TLS-connection-func-into-ssl_helpers
Backport 2.28: Move TLS connection helper code from test_suite_ssl.function to ssl_helpers.c
2023-03-21 10:54:06 +00:00
Paul Elliott
fc28ffa4c8
Merge pull request #7320 from tom-cosgrove-arm/static-assert-2.28
Backport 2.28: Implement and use MBEDTLS_STATIC_ASSERT()
2023-03-20 22:55:32 +00:00
Dave Rodgman
61495ba7cf
Merge pull request #1003 from tom-cosgrove-arm/aesni-intrinsics-2.28
Backport 2.28: Implement AESNI with intrinsics
2023-03-20 18:20:47 +00:00
Tom Cosgrove
410594c002 Have MBEDTLS_STATIC_ASSERT() match current development more closely
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-20 15:10:11 +00:00
Tom Cosgrove
bdd01a74ef Implement and use MBEDTLS_STATIC_ASSERT()
Fixes #3693

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-20 15:08:21 +00:00
Tom Cosgrove
b5eb831803 Add tests for unaligned AES contexts
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-20 10:57:42 +00:00
Tom Cosgrove
640b761e49 Print out AESNI mechanism used by GCM in self-test
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-19 15:07:06 +00:00
Tom Cosgrove
2c942a35ff Fix code style nit
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-19 14:04:04 +00:00
Tom Cosgrove
9149e12767 Stop selftest hanging when run on CI
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-18 14:49:07 +00:00
Tom Cosgrove
20458c0963 Have selftest print more information about the AESNI build
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-18 14:48:49 +00:00
Tom Cosgrove
e0c75342fc Fix another backport issue: it's VS2010/ not VS2013/
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-18 13:54:26 +00:00
Tom Cosgrove
3b53caed9f Remove references to MBEDTLS_AESCE_C and MBEDTLS_HAVE_ARM64
that aren't needed in this backport

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-17 18:25:36 +00:00
Tom Cosgrove
779199faac Document that MBEDTLS_AESNI_HAVE_INTRINSICS and MBEDTLS_AESNI_HAVE_CODE are internal
macros, despite appearing in a public header file.

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-17 17:16:53 +00:00
Tom Cosgrove
58550acba0 Fix merge errors in backporting
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-17 16:54:59 +00:00
Gilles Peskine
9494a99c2f Fix preprocessor conditional
This was intended as an if-else-if chain. Make it so.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:36:05 +00:00
Gilles Peskine
3efd3149f8 Finish sentence in comment
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:35:54 +00:00
Gilles Peskine
9a8bf9f85d Announce the expanded AESNI support
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:32:03 +00:00
Gilles Peskine
e5038c666e Document the new state of AESNI support
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:32:01 +00:00
Gilles Peskine
6dec541e68 AESNI: Overhaul implementation selection
Have clearly separated code to:
* determine whether the assembly-based implementation is available;
* determine whether the intrinsics-based implementation is available;
* select one of the available implementations if any.

Now MBEDTLS_AESNI_HAVE_CODE can be the single interface for aes.c and
aesni.c to determine which AESNI is built.

Change the implementation selection: now, if both implementations are
available, always prefer assembly. Before, the intrinsics were used if
available. This preference is to minimize disruption, and will likely
be revised in a later minor release.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:59 +00:00
Gilles Peskine
b71d40228d Clean up AES context alignment code
Use a single auxiliary function to determine rk_offset, covering both
setkey_enc and setkey_dec, covering both AESNI and PADLOCK. For AESNI, only
build this when using the intrinsics-based implementation, since the
assembly implementation supports unaligned access.

Simplify "do we need to realign?" to "is the desired offset now equal to
the current offset?".

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:58 +00:00
Gilles Peskine
3ba81d3217 Remove the dependency of MBEDTLS_AESNI_C on MBEDTLS_HAVE_ASM
AESNI can now be implemented with intrinsics.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:55 +00:00
Gilles Peskine
30c356c540 Use consistent guards for padlock code
The padlock feature is enabled if
```
defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86)
```
with the second macro coming from `padlock.h`. The availability of the
macro `MBEDTLS_PADLOCK_ALIGN16` is coincidentally equivalent to
`MBEDTLS_HAVE_X86` but this is not meaningful.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:38 +00:00
Gilles Peskine
6978e73939 Fix unaligned access if the context is moved during operation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:34 +00:00
Gilles Peskine
5f1677f582 Fix typo in comment
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:31 +00:00
Gilles Peskine
de34578353 Fix code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:28 +00:00
Gilles Peskine
563c492bf6 Travis: run selftest on Windows
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:26 +00:00
Gilles Peskine
2e8d8d1fd6 Fix MSVC portability
MSVC doesn't have _mm_storeu_si64. Fortunately it isn't really needed here.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:23 +00:00
Gilles Peskine
d4a239310b Improve variable names
To some extent anyway.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:21 +00:00
Tom Cosgrove
790756d439 Get aesni.c compiling with Visual Studio
Clang is nice enough to support bitwise operators on __m128i, but MSVC
isn't.

Also, __cpuid() in MSVC comes from <intrin.h> (which is included via
<emmintrin.h>), not <cpuid.h>.

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-17 16:31:18 +00:00
Gilles Peskine
e7dc21fabb AESNI: add implementation with intrinsics
As of this commit, to use the intrinsics for MBEDTLS_AESNI_C:

* With MSVC, this should be the default.
* With Clang, build with `clang -maes -mpclmul` or equivalent.
* With GCC, build with `gcc -mpclmul -msse2` or equivalent.

In particular, for now, with a GCC-like compiler, when building specifically
for a target that supports both the AES and GCM instructions, the old
implementation using assembly is selected.

This method for platform selection will likely be improved in the future.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:16 +00:00
Gilles Peskine
2c8ad9400b AES, GCM selftest: indicate which implementation is used
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:14 +00:00
Gilles Peskine
5511a34566 New preprocessor symbol indicating that AESNI support is present
The configuration symbol MBEDTLS_AESNI_C requests AESNI support, but it is
ignored if the platform doesn't have AESNI. This allows keeping
MBEDTLS_AESNI_C enabled (as it is in the default build) when building for
platforms other than x86_64, or when MBEDTLS_HAVE_ASM is disabled.

To facilitate maintenance, always use the symbol MBEDTLS_AESNI_HAVE_CODE to
answer the question "can I call mbedtls_aesni_xxx functions?", rather than
repeating the check `defined(MBEDTLS_AESNI_C) && ...`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:12 +00:00
Gilles Peskine
2808a6047c Improve the presentation of assembly blocks
Uncrustify indents
```
    asm("foo"
        HELLO "bar"
              "wibble");
```
but we would like
```
    asm("foo"
        HELLO "bar"
        "wibble");
```
Make "bar" an argument of the macro HELLO, which makes the indentation from
uncrustify match the semantics (everything should be aligned to the same
column).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:10 +00:00
Gilles Peskine
18d521a57d Don't warn about Msan/Valgrind if AESNI isn't actually built
The warning is only correct if the assembly code for AESNI is built, not if
MBEDTLS_AESNI_C is activated but MBEDTLS_HAVE_ASM is disabled or the target
architecture isn't x86_64.

This is a partial fix for #7236.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:07 +00:00
Gilles Peskine
6055b78328 Update bibliographic references
There are new versions of the Intel whitepapers and they've moved.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:05 +00:00
Paul Elliott
01298e635a Merge remote-tracking branch 'development/mbedtls-2.28' into mbedtls-2.28-restricted
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-03-17 11:12:59 +00:00
Dave Rodgman
b3b905953d
Merge pull request #999 from yanesca/threat_model_summary-2.28
Threat model summary 2.28
2023-03-16 21:58:25 +00:00
Janos Follath
83050519a7 Threat Model: fix copy paste
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-16 15:00:03 +00:00
Dave Rodgman
4a1de0f1a4
Merge pull request #7295 from DemiMarie/oid-fix-2.28
[Backport 2.28] Fix segfault in mbedtls_oid_get_numeric_string
2023-03-16 12:21:25 +00:00