17581 Commits

Author SHA1 Message Date
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
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
Janos Follath
35f5ef01f2 Threat Model: adjust to 2.28
MBEDTLS_AESCE_C is not available in 2.28., remove it from workarounds.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:43:08 +00:00
Janos Follath
6cd045905f Threat Model: adjust modality
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
e3d677c6aa Threat Model: remove references
Remove references to scientific papers as they are too specific and
might be misleading.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
08094b8313 Threat Model: clarify stance on timing attacks
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
6ce259d287 Threat Model: improve wording and grammar
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
8257d8aa00 Threat Model: clarify attack vectors
Timing attacks can be launched by any of the main 3 attackers. Clarify
exactly how these are covered.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
18ffba6100 Threat Model: improve wording
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
5e68d3b05f Threat Model: move the block cipher section
The block cipher exception affects both remote and local timing attacks.
Move them to the Caveats section and reference it from both the local
and the remote attack section.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
389cdf43ab Threat model: explain dangling countermeasures
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
adc8a0bcef Threat Model: increase classification detail
Originally for the sake of simplicity there was a single category for
software based attacks, namely timing side channel attacks.

Be more precise and categorise attacks as software based whether or not
they rely on physical information.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
5adb2c2328 Threat Model: reorganise threat definitions
Simplify organisation by placing threat definitions in their respective
sections.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
e57ed98f9e Threat Model: Miscellaneous clarifications
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
661c88f2ba Threat Model: Improve wording
Signed-off-by: Janos Follath <janos.follath@arm.com>

Co-authored-by: Dave Rodgman <dave.rodgman@arm.com>
2023-03-15 15:35:29 +00:00
Janos Follath
ce2985b22c Add Threat Model Summary
Signed-off-by: Janos Follath <janos.follath@arm.com>
2023-03-15 15:35:29 +00:00
Gilles Peskine
a93b06dd5b
Merge pull request #7204 from lpy4105/issue/backport-all_sh-do-not-list-unsupported-cases
Backport 2.28: all.sh: Do not list unsupported cases
2023-03-14 10:34:12 +01:00
Dave Rodgman
39987ebde7
Merge pull request #7172 from daverodgman/fix_UB_in_ssl_read-2.28
Backport 2.28: Fix undefined behavior in ssl_read if buf parameter is NULL
2023-03-13 10:46:24 +00:00
Gilles Peskine
ed36bbeb9a
Merge pull request #7238 from davidhorstmann-arm/2.28-move-getting-started-guide
[Backport 2.28] Move docs/getting_started.md to docs repo
2023-03-10 10:59:25 +01:00
Dave Rodgman
362142f6d3
Merge pull request #7223 from gilles-peskine-arm/doc-tls13-psa_crypto_init-2.28
2.28: Document the need to call psa_crypto_init() with USE_PSA_CRYPTO
2023-03-09 15:44:39 +00:00
David Horstmann
29216d21e7 Move docs/getting_started.md to docs repo
Delete docs/getting_started.md as it has been moved to the dedicated
documentation repo.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-03-09 09:59:46 +00:00
Janos Follath
803dbdbd22
Merge pull request #7232 from tom-cosgrove-arm/update-changelog-230308-2.28
Backport 2.28: Update ChangeLog to make "fix" explicit
2023-03-09 08:47:37 +00:00
Dave Rodgman
8a8e75e127
Merge pull request #7219 from tom-cosgrove-arm/fix-typos-230307-2.28
Fix typos in LTS prior to release
2023-03-08 17:20:04 +00:00
Tom Cosgrove
fc09b75023 Update ChangeLog to make "fix" explicit
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-08 15:58:47 +00:00
Gilles Peskine
07ae208f12 Document the need to call psa_crypto_init() with USE_PSA_CRYPTO
When MBEDTLS_USE_PSA_CRYPTO is enabled, the application must call
psa_crypto_init() before directly or indirectly calling cipher or PK code
that will use PSA under the hood. Document this explicitly for some
functions.

To avoid clutter, this commit only documents the need to call
psa_crypto_init() in common, non-obvious cases: using a PK object that was
not constructed using PSA, X.509 processing, or setting up an SSL context.
Functions that are normally only called after such a function (for example,
using a cipher or PK context constructed from a PSA key), or where the need
for PSA is obvious because they take a key ID as argument, do not need more
explicit documentaion.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-07 20:25:02 +01:00
Tom Cosgrove
601e839416 Fix typos
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-03-07 11:43:12 +00:00
Pengyu Lv
d216c0411d all.sh: add support function for build_armcc
With this change, "--list-components" will not list
"build_armcc" on the system which is not installed
with Arm Compilers.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-03-03 18:23:35 +08:00
Pengyu Lv
a19ce12e47 all.sh: Skip build_mingw correctly
If i686-w64-mingw32-gcc is not installed, then
build_mingw should be unsupported.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-03-03 18:21:14 +08:00
Dave Rodgman
40d79cef35
Merge pull request #7199 from daverodgman/armclang-sha-warning-2.28
Backport 2.28: enable -Werror for armclang
2023-03-03 09:01:50 +00:00
Dave Rodgman
6cda3d3b5b Enable -Werror for armclang
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-03-02 15:34:42 +00:00
Gilles Peskine
2b810e3a74
Merge pull request #7104 from AndrzejKurek/pymod-2-28
[Backport 2.28] Use config.py as a module in depends.py
2023-03-02 15:38:45 +01:00
Gilles Peskine
440535e694
Merge pull request #7153 from lpy4105/issue/1785/backport-ssl-test-script-fail
Backport 2.28: compat.sh: Skip static ECDH cases if unsupported in openssl
2023-02-28 18:11:42 +01:00
Gilles Peskine
14b61666a5
Merge pull request #7139 from daverodgman/fix-test-output-length-on-success-only-2.28
Backport 2.28 - Fix test to check output length on PSA_SUCCESS only
2023-02-28 18:09:25 +01:00
Stephan Koch
6ed143635d Feedback from Arm: guarantee that output_length <= output_size even on error, to reduce the risk that a missing error check
escalates into a buffer overflow in the application code

Signed-off-by: Stephan Koch <koch@oberon.ch>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-28 15:13:35 +00:00
oberon-sk
8a23f49ebc asymmetric_encrypt: check output length only if return code is PSA_SUCCESS.
Signed-off-by: Stephan Koch <koch@oberon.ch>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-28 15:13:35 +00:00
Dave Rodgman
7a5168e90d
Merge pull request #7170 from AndrzejKurek/mpi-window-size-2.28
[Backport 2.28] Reduce the default MBEDTLS_ECP_WINDOW_SIZE value to 2
2023-02-27 17:12:29 +00:00
Dave Rodgman
b361e04207
Merge pull request #7167 from gilles-peskine-arm/retval-non-empty-2.28
Backport 2.28: Pacify Clang 15 about empty \retval
2023-02-26 19:52:40 +00:00
Dave Rodgman
cd09d68eb1 Add tests
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-24 16:02:26 +00:00
Dave Rodgman
fb07c37cb1 Improve changelog
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-24 16:02:26 +00:00
Dave Rodgman
1215557e91 Add corresponding fix for mbedtls_ssl_write
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-24 16:02:26 +00:00
Ashley Duncan
13938b84e9 Added changelog entry.
Signed-off-by: Ashley Duncan <ashley.duncan@evnex.com>
2023-02-24 16:02:26 +00:00