Commit Graph

12059 Commits

Author SHA1 Message Date
Bence Szépkúti
c5f0f738ed Merge pull request #1497 from gilles-peskine-arm/psa-rng-reseed-3.6
Backport 3.6: API to reseed the PSA RNG
2026-03-16 13:53:53 +01:00
Manuel Pégourié-Gonnard
0d48c34169 Merge pull request #1490 from ronald-cron-arm/tls12-2nd-client-hello-3.6
Backport 3.6: Fix TLS 1.2 client hello after HRR
2026-03-16 10:58:44 +01:00
Gilles Peskine
900b7dc5ac Test that the compile-time and run-time entropy source counts match
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-15 19:52:16 +01:00
Manuel Pégourié-Gonnard
2d0aa97f81 Merge pull request #1501 from mpg/restricted-ffdh-peerkey-checks
[Backport 3.6] FFDH peer key checks
2026-03-13 12:44:30 +01:00
Manuel Pégourié-Gonnard
01b04ab723 Merge pull request #1489 from davidhorstmann-arm/fix-psa-ffdh-buffer-overflow-3.6
[Backport 3.6] Fix buffer overflow in FFDH public key export
2026-03-13 09:56:43 +01:00
Ronald Cron
668e677faf tls13_hrr_then_tls12_second_client_hello: Improve client and server state checks
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 19:26:14 +01:00
Ronald Cron
7b3af46c40 tls13_hrr_then_tls12_second_client_hello: Improve some comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 19:26:08 +01:00
Ronald Cron
a76e7c65bc tls13_hrr_then_tls12_second_client_hello: Various improvements
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-10 17:08:22 +01:00
David Horstmann
89f132d3fa Add buffer-too-small case for FFDH-8192
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-03-10 09:07:20 +00:00
David Horstmann
14b37ec1c4 Add small buffer case for P521 import/export
Specifically for the simple import/export case and also the
import/export-public case.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-03-10 09:05:37 +00:00
David Horstmann
cc4e191d4f Add missing buffer-too-small tests
Add tests for key import-export and key import followed by public-key
export when the output buffer is too small. Add these tests for the
following curves:
* p256 as an example of a Weierstrass curve
* Curve25519
* Curve448

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-03-10 09:05:37 +00:00
David Horstmann
443300e700 Add testcase for FFDH buffer overflow
This testcase calls psa_export_public_key() on an FFDH key with an
output buffer that is too small. Since the size is calculated based on
the required key size but not checked against the available buffer size,
we overflow the buffer.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-03-10 09:05:37 +00: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
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
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
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
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
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
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
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
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
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
685a1ce6f4 Merge remote-tracking branch 'mbedtls-3.6' into merge-3.6-restricted-20260304 2026-03-04 14:39:06 +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
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
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
Ronald Cron
365a16dc38 tls13: Do not negotiate TLS 1.2 after an HRR
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-27 16:03:30 +01:00
Ronald Cron
3b244905bc Add unit test with TLS 1.2 nego after HRR
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-27 16:00:11 +01:00
Bence Szépkúti
1937efdd94 Merge pull request #10615 from gilles-peskine-arm/generate-psa_test_wrappers-3.6
Backport 3.6: generate psa test wrappers
2026-02-26 13:44:15 +00:00
Gilles Peskine
d841a6a782 Generate psa_test_wrappers.{h,c} automatically
This is not only convenient, but now necessary, because if the content of
the generated files changes due to changes in Python files in the framework,
`all.sh check_generated_files` will fail in the framework CI.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-22 20:33:27 +01:00
Ronald Cron
d8b97c6a28 ssl-opt.sh: Revert leftover debug level increase
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:41:57 +01:00