17681 Commits

Author SHA1 Message Date
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
David Horstmann
89bf31d361 Add exemption for make.bat in checks for tabs
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-03-17 13:59:10 +00:00
David Horstmann
e04d492aad Ignore mbedtls macros causing warnings
Sphinx's breathe plugin cannot readily parse the Mbed TLS macros, so
define the less essential ones away at the doxygen step to reduce the
number of warnings.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-03-17 13:59:10 +00:00
David Horstmann
7f7aadded1 Add configuration for Read The Docs
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-03-17 13:59:10 +00:00
David Horstmann
241b0408c3 Add initial API doc configuration
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-03-17 13:59:10 +00:00
David Horstmann
62ef621c24 Tell Doxygen to generate XML
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-03-17 13:59:10 +00:00
David Horstmann
c9d8c3305d Add space to appease doxygen bug
See doxygen/doxygen#8706

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-03-17 13:59:10 +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
Demi Marie Obenour
6b8e8ff079 Fix segfault in mbedtls_oid_get_numeric_string
When passed an empty OID, mbedtls_oid_get_numeric_string would read one
byte from the zero-sized buffer and return an error code that depends on
its value.  This is demonstrated by the test suite changes, which
check that an OID with length zero and an invalid buffer pointer does
not cause Mbed TLS to segfault.

Also check that second and subsequent subidentifiers are terminated, and
add a test case for that.  Furthermore, stop relying on integer division
by 40, use the same loop for both the first and subsequent
subidentifiers, and add additional tests.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
2023-03-16 01:07:35 -04:00
Yanray Wang
3d1d418f9e Fix failure in check_generated_files
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-03-16 11:10:17 +08:00
Yanray Wang
e16808cddc Move #define Directive into ssl_helpers.h
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-03-16 11:10:17 +08:00
Yanray Wang
d2696f2aa2 Fix issue of conversion from size_t to int
ssl_helpers.c is treated with W3 warning level in MSVC complier.
So that it's reported as error for warning of conversion from
size_t to int. This change fixes all this type of warning seen in
Microsoft Visual Studio 12.0. Besides, some potential problems of
type conversion are also handled.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-03-16 11:10:17 +08:00