32727 Commits

Author SHA1 Message Date
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
Gilles Peskine
dec0d500a8 Test printf integer format modifiers more
In particular, test `"%zu"` for `size_t` and `"%lld"` for `long long`, which
older Windows runtimes do not support, but which Mbed TLS uses.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
f994fe05cd Fix the build on non-UNIXLIKE platforms
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
5ca8894b59 Fix the build with dietlibc
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
df9fdae4c4 Add smoke test for availability of some Unix functions
The goal isn't to do any functional testing, but to have a simple diagnostic
if some Unix platform function isn't available, and to have a record of
success in the outcome file.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
168461a3a9 Unify the detection of Unix-like platforms
We were using slightly different guards to decide whether to include
`<unistd.h>` in different places. Unify those.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
15c041c465 Fix wrong pointer type passed to printf
It works in practice, but clang on FreeBSD rightfully complains about it.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
f2c25e0133 test_suite_debug: test the printf used by debug.c
In `test_suite_debug`, test `mbedtls_debug_snprintf()`, which uses
`mbedtls_vsnprintf()` like `mbedtls_debug_print_msg()`. Do this instead of
testing `mbedtls_snprintf()`, which might be subtly different (older
Windows runtimes had slightly different behavior for vsnprintf() vs
snprintf(); TF-PSA-Crypto might pick up a different function if the
platform configuration is different in TF-PSA-Crypto and Mbed TLS).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
a7de32a719 Disable Unix-like integration code in baremetal builds in all.sh
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Gilles Peskine
59c6afcd46 Update framework with TEST_ASSERT_ERRNO
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-03 15:19:58 +01:00
Minos Galanakis
24081fe484 Added Changelog
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-03 11:24:35 +00:00
Minos Galanakis
ee9829a32e ccm_finish: Only reject tag_len missmatch when it has been set.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-03 11:24:35 +00:00
Minos Galanakis
53ab8a525b ccm_finish: Added a boundary check for tag-len.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-03 11:24:35 +00:00
Minos Galanakis
d6f635e3f3 test_suite_ccm: Added a test for invalid tag_len inputs.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-03 11:24:23 +00:00
Gilles Peskine
95be019fb2
Merge pull request #10599 from valeriosetti/backport-fix-ans1write
[backport] include: fix guard in asn1write.h
2026-03-03 09:59:24 +00:00
Manuel Pégourié-Gonnard
c763c2e837 PK: use EC macro for EC key size
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-03 09:53:08 +01:00
Manuel Pégourié-Gonnard
4c4cfe98de PK: use PSA size macros when exporting to PSA
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-03 09:50:53 +01:00
Gilles Peskine
3f8f4a0c3f Improve advice
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-27 20:45:48 +01:00
Gilles Peskine
6f63121a00 Change the default from /dev/urandom to /dev/random
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-27 20:37:28 +01:00
Ronald Cron
500c155de9 tls13: Commit to session resume only when we actually do it
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-27 16:03:32 +01:00