Commit Graph

35074 Commits

Author SHA1 Message Date
Gilles Peskine 38d9d83ae7 mldsa_test_generator refactor: extend API class to Generator
Turn functions that generate test cases into methods of the generator class.
Functions that used to take an API argument are now implemented in the
generic class, and API-specific functions are now methods of the
corresponding API-specific concrete class.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-31 15:19:41 +02:00
Gilles Peskine 31bae441f6 mldsa_test_generator refactor: preliminary rearrangement
Move code around, to make subsequent diffs easier to review.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-31 15:19:41 +02:00
Gilles Peskine 72f178bdbd Move most of generate_mldsa_tests.py into a module
We are moving the command line entry point to the consuming branch.

The move will be completed when the consuming branch no longer needs the
script to exist in the framework.
https://github.com/Mbed-TLS/mbedtls-framework/issues/294

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-31 15:19:41 +02:00
Gilles Peskine 7f537471bd Clean up overly complicated typing in read_file_lines
The `read_file_lines` context manager supported either text or binary
streams, based on a parameter passed to the constructor. But the type
annotation on the iterator claimed that all lines were text. The version of
mypy that we use on the CI was happy with that, but modern versions are not.

The advantage of `read_file_lines` over built-in functions is better
tracking of line numbers. We never took advantage of this in our code with
binary streams. Change the one place where `read_file_lines` was used with a
binary stream to use built-in functions instead, and specialize
`read_file_lines` to text streams.

This fixes a legitimate complaint of modern mypy on `macro_collectory.py`.

There was no runtime bug: the behavior was correct, only the type
annotations were wrong.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-31 15:19:41 +02:00
Gilles Peskine a0e5850d61 Fix the Mbed TLS build when TF-PSA-Crypto only has a little MLDSA
When building Mbed TLS with test drivers, "psa_crypto_mldsa.h" is not on the
include path. Rather than get it on, which seems complicated and is not
desirable in the long term, arrange to do without this header. We just need
to define the macro PSA_ALG_IS_ML_DSA, and its behavior is defined by the
PSA Crypto API specification so pretty much set in stone.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-31 15:19:41 +02:00
Gilles Peskine c8672388d8 Fix the build when TF-PSA-Crypto only has a little MLDSA
When TF-PSA-Crypto has pure ML-DSA, we need to handle it in the test driver
for signatures. But we must not try to reference ML-DSA identifiers in
TF-PSA-Crypto branches where they don't exist yet, even though the
compilation option already exists (which notably includes the TF-PSA-Crypto
1.1.0 release).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-31 15:19:41 +02:00
Gilles Peskine e10d0ffc81 Add passthrough for pure ML-DSA to the test driver
We don't support ML-DSA in libtestdriver1 yet, because it's a copy of the
`builtin` driver but ML-DSA is provided by the `pqcp` driver. This means
that we can't test “driver-only” ML-DSA builds, but it should be possible to
enable ML-DSA in a build that dispatches through the test driver. This is
currently impossible because pure ML-DSA is not a sign-the-hash algorithm,
but the code in the test driver for signatures assumes that all signature
algorithms are sign-the-hash. Fix this in a minimal way by making the test
driver activate the fallback mechanism of driver dispatch when the algorithm
is pure ML-DSA. (Don't do this for all algorithms that are not sign-the-hash,
because in general, we do want the test driver to fail if it's given an
algorithm that it doesn't support.)

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-31 15:19:41 +02:00
Gilles Peskine d1a8b5b596 Merge pull request #289 from gilles-peskine-arm/iar-1.1.0-framework
IAR build fixes before 1.1.0/4.1.0/3.6.6: framework support
2026-03-16 14:48:45 +01:00
Gilles Peskine c3d6599465 Merge pull request #283 from gilles-peskine-arm/audit_validity_dates-move-from-mbedtls
Move some scripts from mbedtls
2026-03-12 09:57:39 +01:00
Gilles Peskine 96b9d674eb Switch off overeager IAR warning
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-11 20:11:47 +01:00
Gilles Peskine 4ad123d54f IAR: let test code use stdio FILE functions
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-11 20:11:47 +01:00
Gilles Peskine 25c1750beb Sort out inclusions of <test/build_info.h> vs "test_common.h"
Include `"test_common.h"` as the first thing in C files, and
`<test/build_info.h>` as the first thing in header files.

This requires moving `<test/test_common.h>` to its intended location
`"test_common.h"`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-11 20:11:47 +01:00
Gilles Peskine 30d9a6210b Split <test/build_info.h> out of test_common.h
The header `test_common.h` contains two kinds of things:

* Things to do at the beginning of individual C files. Specifically,
  defining macros that notify system headers about what we want from them.
  Keep those in `test_common.h`, which will subsequently be moved out of
  the include directory.
* Things to do at the beginning of every header. In particular, read the
  library configuration. Move them to a new header `build_info.h`,
  which is the only one intended to be included from headers.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-11 20:11:47 +01:00
Gilles Peskine c5135a0c47 Add pylint duplicate-code exceptions for newly moved files
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-09 10:50:57 +01:00
Gilles Peskine 345b13a2b4 Run pylint and mypy on all files in mbedtls_framework
We were missing `mbedtls_framework/code_wrapper/*.py` because we were not
traversing the directory recursively.

Also improve the comment explaining the duplicate-code workaround for code
that's being moved between files in different repositories.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-09 10:50:57 +01:00
Gilles Peskine 95367dbdf1 Remove temporary code from the tf-psa-crypto split
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-09 10:50:57 +01:00
Gilles Peskine c77ecf059c Fix or silence minor issues reported by pylint
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-09 10:50:57 +01:00
Gilles Peskine d393ebd792 Fix cosmetic issues reported by pylint
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-09 10:50:57 +01:00
Gilles Peskine 7bc3cdfd12 Update paths after moving some scripts to the framework
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-09 10:50:57 +01:00
Gilles Peskine 72215295d8 Add requirements in the framework for scripts in the framework
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-09 10:50:57 +01:00
Gilles Peskine 731ff38bf9 Merge remote-tracking branch 'main' into audit_validity_dates-move-from-mbedtls 2026-03-09 10:50:00 +01:00
Valerio Setti 9b92164c47 Merge pull request #280 from ronald-cron-arm/tf-psa-crypto-reorg-prep
Prepare for TF-PSA-Crypto repository reorganization
2026-03-07 14:07:50 +01:00
Gilles Peskine 08e8a79146 Merge pull request #286 from gilles-peskine-arm/psasim-serialize-unsigned-int
psasim serialize: Support a few more standard C types
2026-03-05 22:11:12 +01:00
Gilles Peskine 0058f4c4cb psasim serialize: Support a few more standard C types
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-05 10:59:26 +01:00
Gilles Peskine 7dffa3505a Merge branch 'tmp-branch-move-files-to-framework' into audit_validity_dates-move-from-mbedtls 2026-03-03 13:37:11 +01:00
Gilles Peskine 7e011cca07 Move some scripts from mbedtls into the framework
Move a bunch of files from `scripts` and `mbedtls/scripts` to the framework.

The following files will be added (moved from Mbed TLS `development`):

* `scripts/ecp_comb_table.py`
* `scripts/massif_max.pl`
* `tests/scripts/audit-validity-dates.py` (moved to `scripts/`)
* `tests/scripts/gen_ctr_drbg.pl` (moved to `scripts/`)
* `tests/scripts/gen_gcm_decrypt.pl` (moved to `scripts/`)
* `tests/scripts/gen_gcm_encrypt.pl` (moved to `scripts/`)
* `tests/scripts/gen_pkcs1_v21_sign_verify.pl` (moved to `scripts/`)
* `tests/scripts/generate-afl-tests.sh` (moved to `scripts/`)
* `tests/scripts/generate_server9_bad_saltlen.py` (moved to `scripts/`)
* `tests/scripts/run-metatests.sh` (moved to `scripts/`)
* `tests/scripts/run_demos.py` (moved to `scripts/`)
* `tests/scripts/test_config_script.py` (moved to `scripts/`)

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

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 13:36:26 +01:00
Valerio Setti e07b6643e8 Merge pull request #278 from gilles-peskine-arm/generate_mldsa_tests-create
Support committed generated test data and generate PQCP test data
2026-02-27 11:12:44 +01:00
Gilles Peskine 0879d0c806 Merge pull request #279 from gilles-peskine-arm/unix-detection-202601-framework
Simplify platform requirements before 1.1/4.1: framework support
2026-02-26 19:10:22 +01:00
Bence Szépkúti c2cb8565a5 Merge pull request #10607 from gilles-peskine-arm/timing-use-mstime
Simplify MBEDTLS_TIMING_C to use mbedtls_ms_time()
2026-02-26 14:38:50 +00:00
Gilles Peskine d1bb3a61a5 dilithium_py reproducible output requires pycryptodome
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-25 21:12:46 +01:00
Gilles Peskine d6dce9b3f8 Make the output deterministic
Tests using randomized signatures were currently randomized. We need the
output of the script to be reproducible, so this won't do.

Force randomized signatures to use a specific RNG which is reset before
constructing each test case. This way, the script's output is reproducible.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-25 19:02:22 +01:00
Gilles Peskine 3ddf7bc717 Fix verify test cases not having a randomized signature
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-24 16:06:11 +01:00
Janos Follath 9394d25048 Merge pull request #10584 from davidhorstmann-arm/add-link-to-crypto-security-md
Add link to TF-PSA-Crypto `SECURITY.md`
2026-02-24 08:36:39 +00:00
Ronald Cron 25db08b18b check-doxy-blocks.pl: Add dispatch, extras, platform and utilities directories
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 10:23:01 +01:00
Valerio Setti b41c8f6e04 Merge pull request #10608 from bjwtaylor/DriverVsReference_removal
Remove DriverVsReference tasks from analyze_outcomes.py
2026-02-23 09:01:25 +00:00
Ronald Cron 055618425f check_names.py: Add dispatch, extras, platform and utilities directories
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-23 08:17:50 +01:00
Bence Szépkúti bbf8bbbdb6 Merge pull request #10575 from ronald-cron-arm/dtls-client-hello-defragmentation-prep
Some preparatory work for DTLS client hello defragmentation
2026-02-22 23:30:39 +00:00
Gilles Peskine bd6dfd6d8a Fix check_names complaints about *_platform_requirements.h
Platform requirement headers are expected to define macro names
outside of our namespace.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-21 21:45:27 +01:00
Gilles Peskine b2eb76d575 Revert "Fix check_names complaints about *_platform_requirements.h"
This reverts commit 5452c7747b.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-21 21:45:20 +01:00
Gilles Peskine 99c4159681 Disable Unix-like integration code in baremetal builds in all.sh
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-21 21:20:36 +01:00
Gilles Peskine f004998303 Add issue number
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-21 21:20:34 +01:00
Gilles Peskine 6d5987a954 Include <test/test_common.h> first in test code
This lets us define things that we want to have everywhere in test code. In
particular, this lets us define platform-specific symbols that influence
what system headers declare. This also takes care of including the library
configuration.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-20 21:46:11 +01:00
Gilles Peskine 4f3a21f40d Stop using MBEDTLS_PRINTF_SIZET
Since Mbed TLS 3.6.0, all officially supported versions of Visual Studio
a printf function family that is sufficiently compliant to C99 for our
purposes, in particular supporting `%zu` for `size_t`. The only platform
without `%zu` that we semi-officially support is older versions of MinGW,
still used in our CI. MinGW provides either a Windows legacy printf or a
standards-compliant printf depending on the value of
`__USE_MINGW_ANSI_STDIO` when compiling each C file. Force the use of the
compliant version. Don't rely on `MBEDTLS_PRINTF_SIZET`, which is defined in
`<mbedtls/debug.h>` and no longer considers the Windows legacy version in
Mbed TLS >= 4.1.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-20 20:31:56 +01:00
Ben Taylor d507b46684 Remove DriverVsReference tasks from analyze_outcomes.py
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-02-20 15:08:33 +00:00
Valerio Setti 3b4984243f Merge pull request #10595 from valeriosetti/fix-tls12-sha-guards
library: check_config: fix required hash algorithms for TLS 1.2
2026-02-20 09:14:13 +00:00
Gilles Peskine c88127f488 ML-DSA test case generator
Generate some basic test cases for the mldsa-native functions.

Uses `dilithium_py` from https://github.com/GiacomoPope/dilithium-py
(`pip install dilithium-py`), which requires Python >=3.9.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 18:24:08 +01:00
Gilles Peskine d85217d8f5 Support test data generators in generate_files_helper.py
Support check and always-update mode. Update-if-needed mode falls back to
always-update mode because test_data_generation.py doesn't support
update-if-needed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 18:24:08 +01:00
Gilles Peskine 2fe235d289 Test data generators: add --list-outdated option
As part of a long-term unification effort of generation scripts, add an
option for test generators to list oudated targets without writing to files.
This corresponds to functionality that the new generate_files_helper module
offers.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 18:24:08 +01:00
Gilles Peskine 151585f1a1 New utility Python module: generate_files_helper
A new utility to give a common interface to committed generated files.

For the time being, this module is only intended for committed generated
files, and `make_generated_files_common.py` is only intended for non-committed
generated files. The two may be unified at some point in the future.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 18:24:08 +01:00
Gilles Peskine f9a7620e5b Create a new directory for non-user-facing scripts
Create a directory for scripts that are useful to maintainers, and may be
invoked as part of the CI, but are not part of the normal build.

These scripts may require a recent Python version and may require additional
third-party modules, unlike user-facing scripts where we try to minimize
requirements.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 18:24:08 +01:00