32853 Commits

Author SHA1 Message Date
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
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
Manuel Pégourié-Gonnard
1fee3da79a PK: require more option combinations in tests
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:48:48 +01:00
Manuel Pégourié-Gonnard
023c51b282 PK: adjust size macro in case PSA is disabled
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:37:34 +01:00
Manuel Pégourié-Gonnard
127b0352b3 PK: move another large buffer to the heap
Was previously missed as it only exists when USE_PSA_CRYPTO is enabled.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:32:19 +01:00
Manuel Pégourié-Gonnard
571d78361a PK: zeroize dummy signature just to be sure
The signature of a dummy hash for which no pre-image is know is probably
not sensitive, but zeroize it anyway.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:32:04 +01:00
Manuel Pégourié-Gonnard
81ecc37372 PK: clarify comment about key export
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:32:04 +01:00
Manuel Pégourié-Gonnard
bc69abd2cb PK: use existing macros and functions
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-27 10:32:04 +01:00
David Horstmann
0d48251122 Add ChangeLog entry for NULL dereference fix
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-26 14:05:13 +00: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
David Horstmann
bfaf4a47fd Fix null pointer dereference in string to names
In mbedtls_x509_string_to_names() we were not checking for allocation
failures. An allocation failure would lead to a memcpy() to a null
pointer address.

Fix this by checking the result of the call to mbedtls_calloc() and
returning MBEDTLS_ERR_X509_ALLOC_FAILED in the error case.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-26 13:22:35 +00:00
Gilles Peskine
409baa7b7b Document /dev/random vs /dev/urandom on Linux
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-25 22:43:19 +01:00
Gilles Peskine
8f962c1b22 Add MBEDTLS_PLATFORM_DEV_RANDOM as a compile-time option
Document when this is not used. This was the case in TF-PSA-Crypto 1.0.0,
but not yet in Mbed TLS 3.6.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-25 22:43:19 +01:00
Gilles Peskine
2ccda0f48c Make the random device configurable
Instead of unconditionally using `/dev/urandom`, make the device path
configurable at compile time through `MBEDTLS_PLATFORM_DEV_RANDOM` or
at run time through `mbedtls_platform_dev_random`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-25 22:10:17 +01:00
Ronald Cron
7d022d3275 ssl-opt.sh: DTLS fragmenting: Do not check for ServerKeyExchange fragmentation
In DTLS fragmenting tests, do not check for
ServerKeyExchange message fragmentation as
depending on the configuration and consequently
the chosen ciphersuite the server may not
send the message.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-25 20:18:19 +01:00
Ronald Cron
6b529ff50d component_test_tls1_2_ccm_psk_dtls_psa: Enable MBEDTLS_HAVE_TIME
As done in component_test_tls1_2_ccm_psk_dtls_legacy
enable MBEDTLS_HAVE_TIME in
component_test_tls1_2_ccm_psk_dtls_psa.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-25 17:49:53 +01:00
Ronald Cron
97a25e4c68 ssl_tls12_server.c: Update hs status after some validations of the ClientHello
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:37:33 +01:00
Ronald Cron
38213a7856 Add change log
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:37:30 +01:00
Ronald Cron
1bdb0901c9 Update mbedtls_ssl_handshake() documentation
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:37:28 +01:00
Ronald Cron
82d549a297 ssl-opt.sh: Use more diverse MTUs
Do not use only power of 2 MTUs.
Use diverse MTUs in DTLS reassembly/
fragmenting/proxy tests.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00
Ronald Cron
404daf5f6d ssl-opt.sh: DTLS reassembly: Improve max_content_len requirements
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00
Ronald Cron
50d1a74ad8 ssl-opt.sh: Fix/improve comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00
Ronald Cron
f44b6545fe ssl-opt.sh: Add tests with CH fragmented with DTLS in default config
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00
Ronald Cron
f20d48f719 ssl-opt.sh: Add interop test of DTLS defragmentation on server side
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-24 15:30:00 +01:00