Commit Graph

34100 Commits

Author SHA1 Message Date
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
Ronald Cron
67152f3049 Merge pull request #10543 from gilles-peskine-arm/split-crypto-makefiles
Split crypto part of Mbed TLS makefiles
2026-01-07 15:18:32 +00:00
Ronald Cron
a271e934ed Merge pull request #10555 from gilles-peskine-arm/sort-config_check_user-mbedtls
Fix non-determinism when generating mbedtls_config_check_user.h
2026-01-07 11:45:51 +00:00
Gilles Peskine
6250af4c9c Merge pull request #10554 from gilles-peskine-arm/sha3-cleanup-202512-prep
SHA3 cleanup prep
2026-01-07 10:35:10 +00:00
Gilles Peskine
dd255696a5 Make use of some intermediate variables
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +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
562677945b Use intermediate variable for TF-PSA-Crypto's contribution to LOCAL_LDFLAGS
Fix a bug whereby `crypto-common.make` was appending to `LOCAL_LDFLAGS`
before `common.make` set the initial value. This broke the build with
pthread enabled: `THREADING` was correctly getting autodetected, but the
addition of `-lpthread` to `LOCAL_LDFLAGS` didn't work.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
8a528cfed5 Split the rules to generate config tests
Have crypto handle the crypto part and tls handle the tls part.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
49d698588b Move crypto-specific code from tests/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 generated .data files in crypto
* Rules to generate .data files in crypto
* List of test suites in crypto
* List of generated .h files in crypto
* Rules to generate .h in crypto

What didn't get moved:

* Rules to generate the crypto part of `$(GENERATED_CONFIG_DATA_FILES)`,
  because they are currently mixed with the rule for the mbedtls part. This
  will be done in a subsequent commit.
* Rules to generate .c files from .function files, and to compile the
  resulting .c files. At least for now, we let Mbed TLS decide how to do
  that on its own.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
cffc11878f Move crypto-specific code from programs/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 generated .c files in crypto
* Rules to build generated .c files in crypto
* List of apps in crypto
* Rules to build apps in crypto

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
ef25955786 Move THREADING autodetection to crypto-common.make
Note that `THREADING` detection must be done after
`TF_PSA_CRYPTO_LIBRARY_PUBLIC_INCLUDE` is defined. Otherwise it won't detect
whether pthread is needed, and will never link with `-lpthread`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
c00bd2a6fb THREADING autodetection: only check the crypto config
When running the preprocessor to determine whether pthread is enabled, only
use TF-PSA-Crypto include paths. Don't use the rest of `LOCAL_CFLAGS`,
including Mbed TLS include paths, which aren't really useful here.

This will simplify later refactorings, because it simplifies a dependency
chain [crypto paths] → `LOCAL_CFLAGS` → `THREADING` → `LOCAL_LDFLAGS`
into just [crypto paths] → `THREADING` → `LOCAL_LDFLAGS`.

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
d78060bda6 Get a clean run from make --warn-undefined-variables
Except in psasim, which I am not touching at this time.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 11:17:43 +01:00
Gilles Peskine
f79f4014b6 Fix missing dependencies of test_certs.h
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
Gilles Peskine
4185efafe4 Fix non-determinism when generating mbedtls_config_check_user.h
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-07 10:28:40 +01:00
Gilles Peskine
40b11f59df Remove component_test_sha3_variations
TF-PSA-Crypto is getting a component with similar coverage in
https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/618

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-06 17:07:17 +01:00
Gilles Peskine
d0f6b5476d Don't call SHA3 selftest when SHA3 is accelerated
`mbedtls_sha3_self_test` only exists in the built-in implementation.

The SHA3 self-test won't run until the tf-psa-crypto submodule moves past
https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/618

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-06 17:05:58 +01:00
Gilles Peskine
64ab9a287e Merge pull request #10548 from gilles-peskine-arm/config-checks-generator-current-mbedtls
mbedtls: generate_config_checks.py: use current data
2026-01-06 10:07:34 +00:00
Gilles Peskine
168c6ec50c Improve out-of-date message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00
Gilles Peskine
b6c30c3639 Print a useful message when the file is out of date
Don't print the differences: interested users can just run `git diff` (or
save the old file and run `comm`).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00
Gilles Peskine
93ef003cdc Check that the config option list shadow file is up to date
Test that `scripts/data_files/config-options-current.txt` is up-to-date.
This file needs to change every time we add or remove a config option.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00
Gilles Peskine
43784b54cd Create the config option list shadow file
```
tests/scripts/check_option_lists.py -u
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00
Gilles Peskine
0e2eb22145 New script to check or update config-options-current.txt
This script may be generalized to check other files that need lists of
current options. But for now, the script just checks
`scripts/data_files/config-options-current.txt`.

This script is identical to the file in crypto. If the file grows to support
multiple targets, we'll probably want to split it, with a generic part in
the framework and a project-specific part (probably little more than the
list of targets) in each project. But for now the file is too simple to split.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00
Gilles Peskine
1de879c6dd Also reject internal macros that weren't options in 3.6
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00
Gilles Peskine
30323afa6c Read current data rather than data about 4.0
It doesn't matter how a macro was used in a previous minor version of the
library. What matters is current information about options and internal
symbols, and information about past versions from which a macro may have
been removed.

The output is mostly the same, but:

* Macros that were options in 3.6, became internal in 4.0 and have now
  been completely removed are now shown as removed, not internal.
* Macros that were options in 3.6, were completely removed in 4.0, and are
  now back but internal, are now shown as internal, not removed.
* Macros that were options in 3.6, were removed in 4.0 and are back to
  being options are no longer rejected.
* Macros that were options in 3.6, were removed in 4.0 and are back to
  being internal derived macros in TF-PSA-Crypto are no longer rejected.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00
Gilles Peskine
35821e7c77 Switch from config_history to config_macros
Switch from the `config_history` module to the new module `config_macros`.
No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00
Gilles Peskine
262d9cab42 Update framework with config_macros.py
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:17 +01:00
Gilles Peskine
fe34bc8ea0 Merge pull request #10550 from bjwtaylor/restore-failure
Re-instate failure when disabling non-existing option
2026-01-02 20:14:58 +00:00
Gilles Peskine
da7aa7678c Merge pull request #10549 from bjwtaylor/replace-mbedtls_ecp_set_map_ops
Replace references of mbedtls_ecp_set_max_ops
2025-12-31 15:43:49 +00:00
Ben Taylor
27c22840b4 Re-instate failure when disabling non-existing option
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-12-24 08:20:09 +00:00
Ben Taylor
23aad2cdad Replace references of mbedtls_ecp_set_max_ops with psa_interruptible_set_max_ops as it is now internal
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-12-23 16:11:49 +00:00
David Horstmann
216c1950f3 Merge pull request #10539 from valeriosetti/issue10518
Remove temporary fix for secp192 curves in `test_psa_crypto_without_heap`
2025-12-15 10:26:57 +00:00
Valerio Setti
a7fd88ae74 framework: update reference
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-11 22:54:39 +01:00
Valerio Setti
3b74e0ee60 tf-psa-crypto: update reference
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-11 21:17:35 +01:00
Valerio Setti
a7337251f7 tests: remove temporary fix for secp192 curves in test_psa_crypto_without_heap
secp192 curves are no more supported in tf-psa-crypto and also all the
temporary fixes has been removed. This one can be removed as well.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-12-11 17:37:06 +01:00
Manuel Pégourié-Gonnard
abb0b22954 Merge pull request #10505 from valeriosetti/issue10453
Remove use of `pk_can_do()`
2025-12-10 11:56:13 +00: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