33046 Commits

Author SHA1 Message Date
Gilles Peskine
02b2b50fb0 Update framework with unix detection improvements
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-08 20:31:59 +01:00
Gilles Peskine
8f8b70aff1 Merge remote-tracking branch 'mbedtls-3.6' into merge-3.6-restricted-20260309 2026-03-08 20:26:08 +01:00
Gilles Peskine
4b571add25
Merge pull request #10621 from gilles-peskine-arm/unix-detection-202601-3.6
Backport 3.6: Simplify platform requirements
2026-03-06 18:06:04 +00:00
David Horstmann
f858b47709
Merge pull request #1500 from gilles-peskine-arm/inet_pton-changelog-attribution-3.6
Update attribution to conform to contributor's request
2026-03-05 15:00:22 +00:00
Minos Galanakis
e54d769fe8 Updated Changelog
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-05 14:20:15 +00:00
Minos Galanakis
a397bb13a3 test_suite_psa_crypto: Extended aead_multipart_state_test for PSA_ALG_CCM
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-05 14:20:15 +00:00
Bence Szépkúti
5dcfb01b52 Add abi_check.py bridge script
The bulk of the script that was moved to the framework is now a pure
python module - bridge scripts like this one will remain in each
individual branch, and continue to be the way to invoke the ABI checks.

This way we can use the bridge scripts to encode branch-specific
information in a more convenient way.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2026-03-05 14:55:00 +01:00
Bence Szépkúti
34bbc72190 Move abi_check.py into the framework
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2026-03-05 14:52:38 +01:00
Manuel Pégourié-Gonnard
174c323479 FFDH: fix some typos in test case titles
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 14:26:06 +01:00
Manuel Pégourié-Gonnard
e1d64c5ce2 Fix misplaced blank line in test data file
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 13:10:35 +01:00
Manuel Pégourié-Gonnard
35aec41600 Add Changelog entry for FFDH missing peerkey check
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 13:07:23 +01:00
Manuel Pégourié-Gonnard
f22ed632b4 FFDH: also test peer key 1 byte too long
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 13:04:50 +01:00
Manuel Pégourié-Gonnard
20a84bd287 FFDH: also test peer key = p, p+1, ff...ff
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:57:20 +01:00
Manuel Pégourié-Gonnard
7453b664af tests: use derive_setup when applicable
There was a single case for key_agreement_setup that was failing when
setting up the derivation operation. Move this test case to use
derive_setup() instead. Add a corresponding positive test with
derive_setup() to make it more obvious that KEY_AGREEEMENT(ECDH, KDF)
works and the problem really is that the KDF is unknown.

Not the expected_status_setup argument of key_agreement_setup is no
longer needed and can be removed.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:57:05 +01:00
Manuel Pégourié-Gonnard
8eb4fba6fb FFDH: expand comment on peerkey check
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:56:53 +01:00
Manuel Pégourié-Gonnard
c173dfb035 FFDH: improve sanity checks
- avoid grouping checks, for a better debugging experience (breakpoints)
- use a more logical order, checking the key type first

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:56:45 +01:00
Manuel Pégourié-Gonnard
5cce3c8a75 Add comment in raw key agreement test function
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:56:35 +01:00
Manuel Pégourié-Gonnard
7a4e2c67b4 FFDH: reorder checks to satisfy picky test
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:56:22 +01:00
Manuel Pégourié-Gonnard
fb70b7f849 FFDH: test with key derivation and bad peer key
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:53:19 +01:00
Manuel Pégourié-Gonnard
118dc8c347 DH: clean up test function key_agreement_setup()
See the comment that was there. I chose not to split the test function
in two, but just have two arguments for each expected status.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:53:03 +01:00
Manuel Pégourié-Gonnard
10c5db67be FFDH: clean up size check
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:52:19 +01:00
Manuel Pégourié-Gonnard
470ee785ca FFDH: rm useless variable
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:51:47 +01:00
Manuel Pégourié-Gonnard
7d9f1b55fc FFDH: validate peer's key as per RFC 7919
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:44:20 +01:00
Manuel Pégourié-Gonnard
7644b0d9e5 FFDH: Add tests for invalid peer key
Failing right now, will fix the library in the next commit.

For 8192-bit, we don't have any positive test, because we have a stupid
line length limitation [1] and we can't fit both our key, the peer's
key, and the output. But for negative tests we don't need the output and
the rest fits, so let's have those.

[1] https://github.com/Mbed-TLS/mbedtls/issues/1866

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:32:18 +01:00
Manuel Pégourié-Gonnard
0c5accb716 DH: Update title in test data
The function is testing both psa_raw_key_agreement() and
psa_key_agreement().

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:32:06 +01:00
Manuel Pégourié-Gonnard
0b91bdea2e DH: update name of test function
Aligning on the name in development, which is also acceptable for 3.6,
and should reduce conflicts when backporting.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:31:09 +01:00
Manuel Pégourié-Gonnard
51bae4b813 DH: add expected_status to key_agreement test func
Also, while at it, add a test for input buffer too small. This had been
added previously in development but not backported.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-05 12:16:04 +01:00
Gilles Peskine
7147da8783 Update attribution to conform to contributor's request
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-05 12:11:08 +01:00
Minos Galanakis
de24220853 ccm_finish: Updated to only accept lens set by ccm_set_lengths
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-05 09:10:47 +00:00
Gilles Peskine
de1a7f2fbb Remove documentation about fork protection
It's coming, but not here yet.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
a863415205 New API psa_random_set_prediction_resistance()
Let applications configure prediction resistance at runtime.

Prediction resistance is always considered disabled when there is no actual
entropy source, only a nonvolatile seed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
5093f08415 New API psa_random_deplete(): force a reseed on the next RNG query
In some scenarios, application or integration code knows that the random
generator should be reseeded, but the reseed cannot or must not happen
immediately and there is no way to report errors. In such scenarios, users
can call the new function `psa_random_deplete()`, which just marks the DRBG
as needing a reseed.

This change requires DRBG modules to treat `reseed_counter == reseed_interval`
as a condition that requires a reseed. Historically they reseeded when
`reseed_counter > reseed_interval`, but that made it impossible to require
a reseed when `reseed_interval == MAX_INT`. Note that this edge case is not
tested.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
bd57d52490 DRBG: make reseed_counter not be off by 1
Change `reseed_counter` to be the number of requests made since the last
reseed, rather than this number minus 1. Thus, reseed when
`reseed_counter >= reseed_interval` rather than
`reseed_counter > reseed_interval`. The field `reseed_counter` is private so
this is not an API change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
48e37275ec Reseed tests: the number of entropy queries depends on the config
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
ccfb7357a3 New function psa_random_reseed()
Explicit reseed of the PSA random generator.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
fb6503bf62 Add internal function to reseed PSA RNG
Not applicable to an external RNG.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
4de8b1043a Move PSA internal RNG functions to a new module
Move the PSA internal RNG functions (i.e. the parts of the PSA random
generator that are used when `MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG` is not
enabled) to a separate source file.

`mbedtls_psa_crypto_configure_entropy_sources` stays where it is, at least
for now, because it accesses global data directly and because I have no
immediate reason to move it.

Refactoring only, no behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
bfaa6a5c81 Allow dependencies on platform features in PSA tests
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
2a92659034 Define derived config macros for entropy sources
Define `MBEDTLS_ENTROPY_TRUE_SOURCES` and `MBEDTLS_ENTROPY_HAVE_SOURCES`
similarly to TF-PSA-Crypto 1.0. Also define
`MBEDTLS_ENTROPY_HAVE_TRUE_SOURCES` for test function dependencies.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
178cda8cc6 Move entropy-related tests to test_suite_psa_crypto_entropy
They were in test_suite_psa_crypto_init, but their only connection to init
is that RNG setup is part of init. When testing how the RNG is set up, the
fact that it happens during init is incidental, what matters is the
difficulties around collecting entropy.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-04 17:54:56 +01:00
Gilles Peskine
a1d7a81d39
Merge pull request #1496 from gilles-peskine-arm/merge-3.6-restricted-20260304
Merge public 3.6 into restricted
2026-03-04 16:00:20 +01:00
Gilles Peskine
685a1ce6f4 Merge remote-tracking branch 'mbedtls-3.6' into merge-3.6-restricted-20260304 2026-03-04 14:39:06 +01:00
Gilles Peskine
31934f47c5 Note platforms with known improvements
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
2393fddd60 clock_gettime: don't assume more than 1 second since the origin of time
With e.g. `CLOCK_BOOTTIME`, it's plausible that less than 1 second has
passed since the boot reference time.

Only assert that the returned time is nonzero (because all-bits-zero is
highly implausible as an actual clock value, but likely indicates that the
intended value was not copied out correctly).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
b17d0f3028 Let test suites see strtoull() on FreeBSD if building with -std=c99
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
fa62af0a47 Let test suites see gettimeofday() on FreeBSD
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
08614e1e96 Skip printf("%zu") tests with MinGW
MinGW uses a legacy printf by default which doesn't support the `z` modifier
for `size_t`. Skip these test cases on MinGW.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
5c6ec6bcc0 Add smoke test for gettimeofday()
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
60cfb78882 Fix the build on non-Unix-like platforms that define CLOCK_REALTIME as a macro
Needed for MinGW builds in our CI.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
9cd92b207f Support testing baremetal builds without the UNIXLIKE code
When `MBEDTLS_TEST_PLATFORM_IS_NOT_UNIXLIKE` is defined, do not enable
`MBEDTLS_PLATFORM_IS_UNIXLIKE`. This lets us test baremetal builds as such
even if we happen to be building for Linux or other Unix-like platform.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00