13465 Commits

Author SHA1 Message Date
Gilles Peskine
c8b668deae mbedtls_psa_ecp_generate_key: don't calculate the public key
mbedtls_ecp_gen_key() generates a private key and calculates the public key.
Calculating the public key takes most of the CPU time. But the PSA key store
doesn't store the key, in order to simplify the plumbing when drivers are
involved. So the time spent calculating the public key is a waste.

Instead, call mbedtls_ecp_gen_privkey(), which does not calculate the public
key.

This also saves 8 instructions in a sample arm thumb build.

Resolves #9732.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-10-30 12:18:16 +01:00
Gilles Peskine
91972cc13d
Merge pull request #9608 from gilles-peskine-arm/outcome-check-repeated-configurations-all.sh-preliminaries-3.6
Backport 3.6: Fix some all.sh components with sub-components
2024-10-25 11:47:48 +00:00
Gilles Peskine
0b8b7a1ee1
Merge pull request #9448 from valeriosetti/psa-use-static-slots-backport
[Backport 3.6] PSA: use static key slots to store keys
2024-10-24 07:27:43 +00:00
David Horstmann
0f170ad60b
Merge pull request #9714 from ThePassionate/mbedtls-1022-3.6.0
[Backport 3.6] net/mbedtls_net_connect: Preventing double close problem
2024-10-22 16:49:18 +00:00
makejian
66b39d4cf1 net/mbedtls_net_connect: Preventing double close problem
In the test examples and real usage scenarios, 'mbedtls_net_free' is called after 'mbedtls_net_connect' fails, which will cause the problem of double close the same fd. It is possible to close this closed fd which has been applied by other link.

Signed-off-by: makejian <makejian@xiaomi.com>
2024-10-22 20:02:51 +08:00
Valerio Setti
fe0f09e35f Documentation: fix some nits
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
ce84921298 psa: move default definition of MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE
Move the default definition of MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE
from psa_crypto_core.h to the public header crypto_extra.h in order
to solve documentation build issues.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
dbfb2ab4ea psa: zeroize static key buffer content when key slot is freed
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
f51488b95d psa: fix some macro definition
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
70fa89c1f9 psa-core: remove unnecessary element in psa_key_slot_t
Instead of checking for "in_use" to be true/false or "key.data"
to be not NULL, simply check that "key.bytes" is 0/not-0.
psa_allocate_buffer_to_slot() will update this value whenever
a new slot is allocated (for the fully static case "allocated"
actually mean "taken").

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
faed169e57 psa_crypto_core: take also cipher's key length into account when sizing static key buffer
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
1980bb781e psa-core: properly set PSA_CRYPTO_MAX_STORAGE_SIZE
If MBEDTLS_PSA_STATIC_KEY_SLOTS is set then limit PSA_CRYPTO_MAX_STORAGE_SIZE
to MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE, otherwise keep the previous
PSA_BITS_TO_BYTES(PSA_MAX_KEY_BITS) size.

This commit also removes changes to test_suite_psa_crypto_persistent_key.data
done previously since MBEDTLS_PSA_STATIC_KEY_SLOTS is always up to date
with key buffer size.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
8d4f15013f psa: allow to use static key buffers instead of dynamic ones
This helps reducing heap memory usage and, if heap memory is
not used anywhere else in an embedded device, it also reduces
code footprint since there is no need for heap management code
in this case.

A new build symbol is added for this purpose, named
MBEDTLS_PSA_STATIC_KEY_SLOTS. It's disabled by default so that
normal usage of Mbed TLS library is not affected.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
David Horstmann
e905442f7e
Merge pull request #9675 from eleuzi01/backport-9673
[Backport 3.6] Move TLS auxiliary test scripts to the framework
2024-10-17 17:18:57 +00:00
Elena Uziunaite
5adc9c304b Add "common.h"
Needed after b81cd1af6418823a2b5ffbd3710ceac9b0e0afa4 (#9671)
since generate_ssl_debug_helpers.py was moved to the framework

Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-10-15 16:58:16 +01:00
David Horstmann
78542bf85d
Merge pull request #9698 from gilles-peskine-arm/3.6.2-rc2-mergeback-3
Merge 3.6.2 into 3.6 (updated cmake gcc+Asan build flags)
2024-10-15 14:00:21 +00:00
Elena Uziunaite
7f5ec13a12 Adjust file path for generate_ssl_debug_helpers.py
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-10-15 12:41:42 +01:00
David Horstmann
bfb9f71fa3 Revert "Add generated files"
This reverts commit 0d1117692ee261d6d89e2819a742c64e06e5bd42.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-10-15 12:06:18 +02:00
Gilles Peskine
a712d8dda5 Bump version to 3.6.2
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-10-14 11:04:31 +02:00
Valerio Setti
5f1c8a720f pkwrite: fix buffer overrun
This commit fixes potential buffer overrun in:
- pk_write_rsa_der
- pk_write_ec_pubkey

In both functions, when dealing with opaque keys, there was no
check that the provided buffer was large enough to contain the
key being exported. This commit fixes this problem and it also
adds some testing in test_suite_pkwrite to trigger these checks.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-14 10:37:00 +02:00
Manuel Pégourié-Gonnard
8536c3c792
Merge pull request #9161 from mpg/doc-guards
[3.6 only] Document transitional feature macros / guards
2024-10-09 10:30:50 +00:00
Gilles Peskine
698a90da40 Ignore and clean generated assembly
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 17:34:46 +02:00
Gilles Peskine
925e9ad5a7 Add target to compile to assembly
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 17:34:46 +02:00
Gilles Peskine
5a668dd5af Reduce level of non-error debug message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 07:44:36 +02:00
Gilles Peskine
015d222008 Remove transitional always-on internal option
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 07:44:36 +02:00
Gilles Peskine
78df03aaa5 Separate accepting TLS 1.3 middlebox compatibility from sending it
The compile-time option MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE gates both
support for interoperability with a peer that uses middlebox compatibility
mode, and support for activating that mode ourselves. Change code that is
only needed for interoperability to be guarded by
MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE.

As of this commit, MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE is always
enabled: there is no way to disable it, and there are no tests with it
disabled.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 07:40:02 +02:00
Gilles Peskine
26fc0390c9
Merge pull request #9498 from minosgalanakis/bugfix/return_early_in_ccm_star_bp36
[Backport 3.6] ccm.c: Return early when ccm* is used without tag.
2024-09-13 09:35:12 +00:00
Manuel Pégourié-Gonnard
32bdf19a01 Minor updates in doc/comments/debug
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-10 10:58:47 +02:00
Manuel Pégourié-Gonnard
8cd0dfaa32
Merge pull request #9537 from mpg/tickets13-followup
[3.6] Follow-up to 9507 Disable new session tickets at runtime
2024-09-10 07:05:29 +00:00
Manuel Pégourié-Gonnard
f59d7b9292
Merge pull request #9493 from yanesca/rsapub_additional_tests
[3.6] Rsapub additional tests
2024-09-09 09:36:33 +00:00
Manuel Pégourié-Gonnard
1116de3ca1 Add guard on internal 1.2-only function
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-04 10:56:08 +02:00
Manuel Pégourié-Gonnard
15fa9ceedd Misc improvements to comments
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-03 10:10:18 +02:00
Manuel Pégourié-Gonnard
33a2918a48
Merge pull request #9390 from eleuzi01/backport-9327
[Backport 3.6] Remove hacks about asm vs constant-flow testing
2024-09-03 07:37:07 +00:00
Manuel Pégourié-Gonnard
4bc15d89cb Fix guards on #include
The rest of the file uses mbedtls_mpi_uint_t unconditionally, so its
definition should also be #include'd unconditionally.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 11:12:09 +02:00
Manuel Pégourié-Gonnard
126cfedba4 Fix code style
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 10:42:46 +02:00
Janos Follath
96cfd7a77a Move bignum code path testing out of the library
Without this, it's not at all obvious that turning on MBEDTLS_TEST_HOOKS
doesn't change the functional behavior of the code.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-02 10:30:47 +02:00
Janos Follath
2f8ad595db Explain the choice of the value of MBEDTLS_MPI_IS_PUBLIC
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-02 10:30:47 +02:00
Janos Follath
e86607c498 Initial local variables to secure default
Unfortunately compilers aren't good at analyzing whether variables are
analyzed on all code paths, and it is better to initialize to the
safe-path values.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-02 10:30:47 +02:00
Janos Follath
42f72b3ea5 Introduce MBEDTLS_MPI_IS_TEST
A + B + 1 is not a good way to get a number that's neither A nor B.
This can be a problem for example if values later are changed to
A = 0 and B = -1.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-02 10:30:47 +02:00
David Horstmann
fbc34eeb69 Revert "Add generated files"
This reverts commit 0d1117692ee261d6d89e2819a742c64e06e5bd42.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-08-30 11:03:51 +01:00
David Horstmann
0d1117692e Add generated files
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-08-28 20:56:16 +01:00
David Horstmann
1d2dcfce6f Bump version to 3.6.1
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-08-28 20:56:16 +01:00
David Horstmann
9f10979853 Merge branch 'mbedtls-3.6-restricted' into mbedtls-3.6.1rc0-pr
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-08-28 20:48:27 +01:00
Ronald Cron
c46edd4423 Fix/Improve documentation
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-28 18:15:36 +02:00
Ronald Cron
9f44c883f4 Rename some "new_session_tickets" symbols
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-28 17:47:46 +02:00
Ronald Cron
ba45a44f13 Move session tickets getter functions to ssl_misc.h
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-28 13:22:26 +02:00
Ronald Cron
97dc5832c5 Improve debug logs
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-28 10:42:01 +02:00
Ronald Cron
d67f801c63 Do not add a new field in the SSL config
We cannot add a new field in SSL config in
an LTS. Use `session_tickets` field instead.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-28 10:41:54 +02:00
Ronald Cron
b675b2ba5d TLS 1.3: Ignore tickets if disabled at runtime
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-27 15:41:24 +02:00
Ronald Cron
bedddd707a Add mbedtls_ssl_conf_enable_new_session_tickets() API
Add mbedtls_ssl_conf_enable_new_session_tickets() API
to be able to enable and disable the handling of TLS 1.3
NewSessionTicket messages.

The TLS 1.2 equivalent function is named
mbedtls_ssl_conf_session_tickets() thus the most
natural name would have been
mbedtls_ssl_conf_new_session_tickets() but it is
already used on server side thus rather
mbedtls_ssl_conf_enable_new_session_tickets().

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-27 15:41:18 +02:00