Commit Graph

13808 Commits

Author SHA1 Message Date
Valerio Setti
f7173e4389 Merge pull request #10517 from valeriosetti/issue10460
Remove use of pk_debug()
2026-01-09 15:22:13 +00:00
Gilles Peskine
4ffb299208 Remove local copies of makefile helpers
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-08 14:57:50 +01:00
Gilles Peskine
e23b6e4dc8 Use the crypto makefile helpers in tf-psa-crypto
Now that the crypto files have been moved to the crypto repository, consume
them there.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-08 14:57:50 +01:00
Valerio Setti
ebbaca0a99 library: debug: adjust guards for "mbedtls_debug_print_crt"
Keep MBEDTLS_PK_WRITE_C as guard only for "debug_print_pk" but let
"mbedtls_debug_print_crt" to work also when MBEDTLS_PK_WRITE_C is disabled.
In this case the only public key won't be printed, but the rest of the
certificate will be.

This commit also updates test coverage by duplicating test cases: now there
will be one case for when MBEDTLS_PK_WRITE_C is enabled and another one
for !MBEDTLS_PK_WRITE_C.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Valerio Setti
2af638a177 library: debug: fix print format in mbedtls_debug_print_buf_ext()
%zu creates problem in MinGW testing. Use MBEDTLS_PRINTF_SIZET intead.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Valerio Setti
af62bae5c1 library: debug: add PK_WRITE_C guard to mbedtls_debug_print_crt()
In tf-psa-crypto "mbedtls_pk_write_pubkey_psa()" is only available when
MBEDTLS_PK_WRITE_C is defined. Therefore we need to add this guard also
in mbedtls to "debug_print_pk" (and indirectly to
"mbedtls_debug_print_crt") and the corresponding tests using it.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Valerio Setti
f1cb45289b library: debug: improve mbedtls_debug_print_buf()
Move single line printing to a separate function named
mbedtls_debug_print_buf_one_line(). This accepts one extra parameter
'add_text' to tell if the final text chars are to be printed at the end
of the line or not.

Add also mbedtls_debug_print_buf_ext() as a generalized version of
mbedtls_debug_print_buf() by adding the extra 'add_text' param.

debug_print_pk() will now use mbedtls_debug_print_buf_ext() in order not
to print chars while dumping the buffer.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Valerio Setti
c6bf9d8200 library: debug: use mbedtls_pk_write_pubkey_psa() to write public key
Remove usage of mbedtls_pk_debug stuff and related functions
(mbedtls_debug_print_psa_rsa(), mbedtls_debug_print_psa_ec(),
mbedtls_debug_print_integer() and debug_count_valid_bits()) and use
mbedtls_pk_write_pubkey_psa() to get the public key from the PK context.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Valerio Setti
10eaf68acd library: debug: remove mbedtls_debug_print_mpi()
This function is no more used anywhere and can be safely removed.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Gilles Peskine
b988dd8f35 Remove accidentally duplicated definitions
"Move crypto-specific code from library/Makefile to a new file" accidentally
copied two lines instead of moving them. Remove the copy that's now in
`crypto-library.make`, since the variables are defined earlier in
`crypto-common.make`. The variables aren't actually used in
`crypto-common.make`, but they could be (arguably should be used to
define `TF_PSA_CRYPTO_LIBRARY_PRIVATE_INCLUDE`).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
8ac7168799 Move crypto-specific code from library/Makefile to a new file
The new file is in Mbed TLS for now. Once we have finished moving code to
it, it will move to TF-PSA-Crypto.

What got moved:

* List of object files from crypto
* List of generated .c files in crypto
* Rules to build generated .c files in crypto

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
d9c6a411c6 Introduce intermediate variables for various TF-PSA-Crypto lists
Use separate variables for the crypto part of lists of generated C files,
generated objects, sample programs and test data files.

No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
2607134998 Move configurable variables to the top
Define variables that are meant to be possibly overridden on the make
command line (or in a parent makefile) at the top. In particular, define
them before including the crypto and framework makefiles, so these makefiles
can use the default values if there's no parent setting.

Also move some internal variables earlier or later, so that a subsequent
refactoring step can have things in the right order in the mbedtls
per-directory makefile:

1. Define variables consumed by the per-directory crypto makefile.
2. Include the per-directory crypto makefile.
3. Use variables defined by the per-directory crypto makefile.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
e3e4da61a8 Use intermediate variables for TF-PSA-Crypto's contribution to LOCAL_CFLAGS
Define these intermediate variables in the crypto helper file.

No behavior change except possibly an inconsequential reordering of compiler
options.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
46568f3c6e Move some crypto core and drivers variable definitions to crypto-common.make
No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
7bef731f0b Create a TF-PSA-Crypto make helper for Mbed TLS
Currently, Mbed TLS can be built with make, and we rely on this in many
`all.sh` components. Mbed TLS knows how to build TF-PSA-Crypto, but this
changes from time to time, and it's hard to do the necessary changes in both
repositories at the same time.

Create a file that Mbed TLS can consume to find out some information needed
to build TF-PSA-Crypto, such as the locations of various files.

Create this file in Mbed TLS. Once we have finished moving code to it, the
file will move to TF-PSA-Crypto.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
a47cc27657 Fix mixup in dependencies for generated config checks
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
3884bf3d89 Remove a XySSL-era comment that has run its course
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
d13d041ed0 Check for the framework submodule before anything else
If we don't have submodules, we can't do anything.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
a1502f54f5 Drop the ability to build the library without the framework
We put that in 3.6.0 because we wanted to minimize changes in a minor
release, and in particular we wanted users to be able to build the library
if they were checking out a release tag without checking out submodules
recursively. That was possible because 3.6.x release tags contain the
generated files.

Since 4.0.0, it's completely impossible to build Mbed TLS without the
`tf-psa-crypto` submodule. So there's no point in trying to allow a build
without the `framework` submodule.

In the libtestdriver1 build, where we copy part of the framework, copy the
framework makefile as well, which is what we use to check for the presence
of the framework (even though the framework makefile doesn't do anything
useful after all).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Valerio Setti
c0ac4a6933 library: ssl: specify hash algorithm when checking signature in ssl_parse_certificate_verify
Since the hash algorithm is known, this can be used when calling
"mbedtls_pk_can_do_psa()" to get a more accurate answer.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-09 16:18:11 +01:00
Valerio Setti
5ad2bfa6c8 library: ssl: adjust return type of mbedtls_psa_alg_from_pk_sigalg()
The correct return type should have been "psa_algorithm_t" since the
beginning because this is what the function really returns and this is
what the returned value is then used for in the calling functions.

Change also the returned value in the default case from
MBEDTLS_PK_SIGALG_NONE to PSA_ALG_NONE in order to return the same type
as in other cases of the switch case.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-09 16:15:48 +01:00
Valerio Setti
d8f0b37d1a ssl: replace remaining occurrence of pk_can_do with pk_get_key_type
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-05 15:57:39 +01:00
Valerio Setti
9eb5b2a146 x509: replace usage of mbedtls_pk_can_do() with mbedtls_pk_get_key_type()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-04 16:28:44 +01:00
Valerio Setti
902467d62f ssl: replace usage of mbedtls_pk_can_do() with mbedtls_pk_get_key_type()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-04 16:28:44 +01:00
Valerio Setti
1de094fb32 library: x509: replace mbedtls_pk_can_do() with mbedtls_pk_can_do_psa()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-04 16:28:44 +01:00
Valerio Setti
9d1fa1a8d8 library: x509: change order of checks in x509_crt_check_signature()
Checking that parent PK type is OK is definitely faster than computing
an hash, so invert the checks.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-04 16:28:44 +01:00
Valerio Setti
81a5a0914c library: ssl: replace mbedtls_pk_can_do() with mbedtls_pk_can_do_psa()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-04 16:28:44 +01:00
Valerio Setti
92926ff4dc library: common: add helper to get PSA algorithm from PK sigalg
Add a simple helper to convert from PK sigalg to PSA algorithm. This is
handy when calling mbedtls_pk_can_do_psa() knowing the PK sigalg and the
used MD type.

This is being added in a separate file because it's meant to be consumed
by both ssl and x509 modules. It was not added to tf-psa-crypto because
this is only needed on the mbedtls repo and doing so reduce interdependencies
between the repos.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-04 16:28:44 +01:00
Valerio Setti
024c3aeb9e library: ssl: remove duplicate check in ssl_parse_server_key_exchange()
The check being removed is already done few lines above so there is no
need to repeat it twice.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-04 16:28:44 +01:00
Manuel Pégourié-Gonnard
5341c86877 Add comments for remaining internal includes
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-02 12:35:20 +01:00
Manuel Pégourié-Gonnard
ea5718721f Remove two more useless internal includes
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-02 12:06:39 +01:00
Manuel Pégourié-Gonnard
3e6455d50e Remove useless includes of psa_util_internal
Those in SSL modules were redundant because it's already included from
ssl_misc.h.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-02 12:00:34 +01:00
Manuel Pégourié-Gonnard
411282d126 x509: rm useless private include in C file
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-01 11:06:02 +01:00
Manuel Pégourié-Gonnard
eab6d3276b ssl: rm useless private include in C file
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-01 10:26:28 +01:00
Manuel Pégourié-Gonnard
c53c43c296 x509: rm useless private includes in internal headers
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-01 10:24:50 +01:00
Manuel Pégourié-Gonnard
4b663abecc ssl: rm useless private includes in internal headers
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-01 10:24:41 +01:00
Valerio Setti
caf73f885a library: check_config: remove references to secp192 curves
Support for these curves is being removed from tf-psa-crypto, so we need
to remove all the references also in this repo.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-11-20 13:01:18 +01:00
Juha-Pekka Kesonen
5f4cbcd336 ssl_tls12: change log level for ECDH computation
Signed-off-by: Juha-Pekka <juha-pekka.kesonen@nordicsemi.no>
2025-11-05 14:10:52 +02:00
Juha-Pekka Kesonen
666fa2da3d ssl_msg.c: change log level for record checking
Signed-off-by: Juha-Pekka <juha-pekka.kesonen@nordicsemi.no>
2025-11-05 14:08:46 +02:00
Valerio Setti
00d579e953 Merge pull request #10439 from bjwtaylor/remove-all-non-ext-apis
Remove all non ext apis
2025-11-04 09:53:34 +00:00
Gilles Peskine
18f2661c65 Merge pull request #10491 from valeriosetti/issue10229
Remove temporary fixes introduced in #10213
2025-11-04 08:59:16 +00:00
Valerio Setti
a35e332bbb library: debug: remove temporary fixes for RSA key handling
Since crypto#308 has been merged:
- replace MBEDTLS_PK_USE_PSA_RSA_DATA with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
- remove "no-check-names"

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-11-03 10:25:15 +01:00
Valerio Setti
525dd917dc Merge pull request #10477 from Cube707/fix/iar-compiler-warning
add cast to fix IAR compiler errors
2025-10-31 12:33:26 +00:00
Ben Taylor
42074c193f Rename mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg to mbedtls_ssl_get_pk_sigalg_and_md_alg_from_sig_alg
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-10-31 08:40:36 +00:00
Ben Taylor
b76c38334a Update name of mbedtls_ssl_pk_alg_from_sig_pk_alg to mbedtls_ssl_pk_sig_alg_from_sig
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-10-31 08:40:25 +00:00
Ben Taylor
f21e63c6d0 Update pk_alg to use mbedtls_pk_sigalg_t and remove casts in library/x509write_csr.c
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-10-30 15:29:02 +00:00
Ben Taylor
00b04a6590 Update mbedtls_pk_sign_ext in x509write_crt.c to use mbedtls_pk_sigalg_t directly and remove casts
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-10-30 15:11:09 +00:00
Ben Taylor
5f037c7fb3 Rename mbedtls_ssl_pk_alg_from_sig to mbedtls_ssl_pk_alg_from_sig_pk_alg and update to use mbedtls_pk_sigalg_t
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-10-30 14:59:24 +00:00
Ben Taylor
0035cfb1f0 Removed unnecessary cast in mbedtls_pk_sign_ext
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-10-30 13:42:56 +00:00