Commit Graph

34908 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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 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
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
Gilles Peskine 5452c7747b 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-19 17:18:03 +01:00
Gilles Peskine 67538f61bc Remove an unused method
`TextChangelogFormat.version_title_text` never worked: it's missing a
parameter in the call to `re.sub`. Fortunately it's unused, so just remove it.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 12:34:35 +01:00
Gilles Peskine 316ec76508 Modernize usage of re.sub deprecated in Python 3.13
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-18 20:10:40 +01:00
Gilles Peskine f41a9f6056 New macro TEST_ASSERT_ERRNO
Show errno if a test assertion fails.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-17 17:21:20 +01:00
Ronald Cron 8ed11c99fe Merge pull request #274 from ronald-cron-arm/dtls-client-hello-defragmentation-prep
Some preparatory work for DTLS client hello defragmentation
2026-02-16 17:48:56 +01:00
Valerio Setti 4a57bd209d Merge pull request #265 from gilles-peskine-arm/crypto_knowledge-psa_spec_1.4-no_pake
Crypto knowledge: up to PSA Crypto 1.4, XOF test driver
2026-02-16 16:05:56 +01:00
Gilles Peskine c99fb5762d Fix SM3 hash length (bits/bytes confusion)
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-16 11:07:24 +01:00
Gilles Peskine 4857228971 psasim: add XOF operation support
XOF operations are not available on every branch, so their serialization
code needs to be compiled conditionally on the availability of the type.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-10 12:21:28 +01:00
Gilles Peskine 2ffd883d80 Driver entry point test code: add XOF support
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 21:16:28 +01:00
Gilles Peskine 4484c52f9a Support test_suite_psa_crypto_metadata functions for new algorithm categories
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 567f89ade9 Remain compatible with generate_psa_constants.py which is outside the framework
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 43a6e55ece Match field names to algorithm category names
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine d60e412a2d generate_test_keys.py: Support ML-DSA, ML-KEM and SLH-DSA keys
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine dec6c51f7d Add sample keys for ML-DSA, ML-KEM and SLH-DSA
Use NIST test vectors. I copied the first test case for each parameter set.
For ML-KEM and ML-DSA, I did it manually. For SLH-DSA, I used the following
Python script:

```
<gen-val/json-files/SLH-DSA-keyGen-FIPS205/internalProjection.json python -c '
import json, re, sys
data = json.load(sys.stdin)
types = {family: {} for family in ["SHA2_F", "SHA2_S", "SHAKE_F", "SHAKE_S"]}
for group in data["testGroups"]:
  t = group["tests"][0]
  m = re.match(r"SLH-DSA-(\w+)-([0-9]+)(\w+)", group["parameterSet"])
  type = m.group(1) + "_" + m.group(3).upper()
  size = m.group(2)
  prv = t["skSeed"] + t["skPrf"] + t["pkSeed"] + t["pk"]
  pub = t["pkSeed"] + t["pk"]
  types[type][size] = (prv, pub)
for type in sorted(types.keys()):
  print("")
  print(f"    # https://github.com/usnistgov/ACVP-Server/blob/v1.1.0.41/gen-val/json-files/SLH-DSA-keyGen-FIPS205/internalProjection.json")
  print(f"    \x27SLH_DSA(PSA_SLH_FAMILY_{type})\x27: {{")
  for size in sorted(types[type].keys()):
    entry = types[type][size]
    print(f"        {size}: (\"{entry[0]}\",")
    print(f"              \"{entry[1]}\"),")
  print(f"    }},")
'
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 87e3988537 Add all algorithms from PSA Crypto 1.4 PQC extension
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 4c54ebd97d OpFail: only consider categories in which at least one algorithm is supported
Addresses https://github.com/Mbed-TLS/mbedtls-framework/issues/264
but perhaps not in the best way.

Keep an exception for PAKE, for which we already have algorithm
support (`PSA_ALG_JPAKE`) but no `pake_fail` function.
https://github.com/Mbed-TLS/mbedtls-framework/issues/263

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 987737675a OpFail generator: pre-compute the lists of categories and algorithms
No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 29697c90ff Support new destructor in PSA Crypto API 1.4
Recognize `PSA_ALG_SIGN_SUPPORTS_CONTEXT` as a destructor.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 1ef0e676bf Add all mechanisms up to PSA Crypto API 1.4
Define the necessary new categories (key wrap, key encapsulation, XOF).

This completes the list of mechanisms in the PSA Crypto API version 1.4,
except for PAKE that are more challenging (family parametrization, need to
find sample keys in `asymmetric_key_data.py`), and except for the PQC
extension.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine e9f66f7ec2 Add DH family RFC3526
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 1e8f77d47c Add elliptic curve FRP256v1
Sample key from
https://www.ietf.org/archive/id/draft-lspm-cose-c509-test-vectors-00.html#name-weierstrass-ec-public-key-with-f

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine 000b04968f Indicate the provenance of keys
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 18:04:13 +01:00
Gilles Peskine c0a8a9cbed Merge pull request #276 from gilles-peskine-arm/psasim-generate-wrappers-dynamically
psasim: generate wrappers dynamically
2026-02-09 17:58:27 +01:00
Gilles Peskine a9bb80e699 Document the psasim build
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 15:34:29 +01:00
Gilles Peskine 2bc58125fe Add missing dependencies on generated headers
Without those dependencies, the headers don't get generated.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-05 22:23:52 +01:00
Gilles Peskine 3a69598ade Clean up psasim/.gitignore
Add generated files that are no longer checked in.

Remove obsolete things (including things now covered at the framework root).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-05 14:03:57 +01:00
Gilles Peskine b6c23e6e01 Remove psasim generated files
The files are now generated during the build. Stop having them in version
control.

As formerly in Mbed TLS, `make clean` doesn't remove
configuration-independent target-independent generated files, but the new
target `make neat` does.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-05 13:58:22 +01:00