Commit Graph

13726 Commits

Author SHA1 Message Date
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
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
685a1ce6f4 Merge remote-tracking branch 'mbedtls-3.6' into merge-3.6-restricted-20260304 2026-03-04 14:39:06 +01:00
Bence Szépkúti
34fcd9ae4f Merge pull request #10603 from ronald-cron-arm/dtls-client-hello-defragmentation-prep-3.6
Backport 3.6: Some preparatory work for DTLS client hello defragmentation
2026-02-22 23:30:44 +00:00
Ronald Cron
3b6bd65334 ssl_msg.c: Improve handshake message fragmenting message
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:41:57 +01:00
Ronald Cron
a02505a7be ssl_msg.c: Improve HS message reassembly completed message
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:41:56 +01:00
Ronald Cron
c065fdd4d4 ssl_tls.c: Rename and expand ssl_tls13_get_hs_msg_name
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-02-18 14:41:56 +01:00
Manuel Pégourié-Gonnard
fbfd13e22b Merge pull request #10597 from valeriosetti/fix-tls12-sha-guards-backport
[backport] library: check_config: fix required hash algorithms for TLS 1.2
2026-02-18 08:23:38 +00:00
David Horstmann
85426311e3 Fix missing type conversion in the TLS-Exporter
In the TLS-Exporter for TLS 1.3 we mistakenly call PSA_HASH_LENGTH() on
an mbedtls_md_type_t when it should be called on a psa_algorithm_t.

Fortunately, these two types have almost the same values, since we have
previously aligned them to make conversion more efficient. As a result,
PSA_HASH_LENGTH() produces exactly the same value when called on an
mbedtls_md_type_t as with the equivalent psa_algorithm_t.

Thanks to this happy coincidence, fix a largely cosmetic issue (rather
than a major functional bug).

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2026-02-16 17:07:30 +00:00
David Horstmann
7c2f728178 Merge pull request #1429 from yanesca/1427_buffer_underflow-backport-3.6
Fix buffer underflow in `x509_inet_pton_ipv6()` [3.6 backport]
2026-02-16 11:58:38 +00:00
Valerio Setti
a372f1a5cb library: check_crypto_config: remove redundant check on hash algorithms for TLS 1.2
TLS-PRF uses either SHA-256 and SHA-384, so the removed paragraph was not
correct. The correct version is already available in "check_config.h".

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-02-12 22:09:06 +01:00
David Horstmann
48c3b179c5 Merge pull request #10589 from daverodgman/backport_gcc_bswap
[Backport 3.6] fix error in GCC bswap
2026-02-11 14:04:47 +00:00
David Horstmann
610f4997c2 Merge pull request #10565 from minosgalanakis/bugfix/fix-intrisic-aesce-clang-36
[3.6 Backport] Fixed clang arm intrinsics for older compiler versions
2026-02-11 11:58:55 +00:00
Manuel Pégourié-Gonnard
20118b65bd pkwrite: RSA: avoid large stack buffer
In the default build, it was 2363 bytes which is a lot to put on the
stack for constrained devices. Fortunately we already have a large
enough buffer at hand: the user-provided output buffer. Use it.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-02-10 11:34:00 +01:00
Dave Rodgman
4f6c8ef2ac fix error in GCC bswap
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2026-02-06 10:10:42 +00:00
Valerio Setti
32ef705024 library: alignment: add "may_alias" attribute to mbedtls_uintXX_unaligned_t structs
Tell the GCC compiler that pointers to types "mbedtls_uintXX_unaligned_t"
(where XX is 16, 32 or 64) might alias with other types. This helps at
high optimizations level (i.e. "-O3") so that the compiler does not mess
up with instruction reordering and memory accesses.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-28 00:07:44 +01:00
Valerio Setti
be0c788105 library: alignment.h: add internal symbol to disable optimizations on x86
MBEDTLS_ALIGNMENT_DISABLE_EFFICENT_UNALIGNED_ACCESS is used to forcedly
prevent MBEDTLS_EFFICIENT_UNALIGNED_ACCESS from being set. This prevents
optimizations from being used on x86 which is useful for testing
purposes.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-28 00:07:44 +01:00
Minos Galanakis
2f384c82a5 built-in drivers(aesce): Fixed clang arm intrinsics for verions < 7
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-01-26 11:06:58 +00:00
Janos Follath
72e18e0032 inet_pton: simplify IPv4 walkback loop
Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-01-21 17:29:07 +00:00
Minos Galanakis
a35f5326f5 drivers sha256|512: Adjusted tf_psa_crypto_common.h inclusion
This patch adjusts the include order so that some ACLE
intrinsics macros are configured before
the inclusion of `neon.h`. This fixes issues with older
clang compilers but has no effect in modern versions.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-01-21 14:16:18 +00:00
Janos Follath
4595bb47d2 inet_pton: fix buggy condition
The flawed condition made us accept invalid IPv6 addresses and in some
cases lead to a buffer underread.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2026-01-20 18:46:52 +00:00
Gilles Peskine
ad6ceaa4e7 Indicate which Clang version stops requiring the workaround
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-12-11 16:10:41 +01:00
Gilles Peskine
85e28b266e AESCE: fix the build with Clang <<16
As indicated in a comment, with older Clang, we need to define
`__ARM_FEATURE_CRYPTO` before we include `arm_neon.h`, which is done via
`common.h`. 4c44990d65
accidentally broke this. Fix it, while taking care not to include another
header before `common.h`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-12-11 16:09:53 +01:00
David Horstmann
419f302dcd Merge pull request #10526 from gilles-peskine-arm/include-common-first-202510-3.6
Backport 3.6: Include common header first
2025-12-09 16:50:12 +00:00
Manuel Pégourié-Gonnard
f6f837aec5 rsa: clarify drawing at random with the CRT
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-09 09:39:07 +01:00
Manuel Pégourié-Gonnard
d251d73d06 rsa: clarify CRT computation
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-09 09:26:20 +01:00
Manuel Pégourié-Gonnard
ec5bc19996 Fix some typos in comments
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-09 09:16:25 +01:00
Manuel Pégourié-Gonnard
83e3b37e9d rsa: rm unused variable + fix typos
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-03 13:27:19 +01:00
Manuel Pégourié-Gonnard
f90c04d646 RSA: remove undocumented check
This only made the function harder to use.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-03 11:35:28 +01:00
Manuel Pégourié-Gonnard
fbd7388482 RSA: handle low-probability events in a uniform way
Previously we were looping in one case but not even checking the other.
Let's check both cases and error out immediately. The error path should
never be taken in pratice anyway.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-03 11:26:09 +01:00
Gilles Peskine
4c44990d65 Include common.h before system headers
In library source files, the order of things should be:

1. Define macros that affect the behavior of system headers, such as
   `_POSIX_C_SOURCE` and `_GNU_SOURCE`.
2. Include the library's common header: `common.h`.
   It takes care of many things, including defining the library
   configuration, granting access to private fields in structures, and
   activating platform-specific hacks.
3. Possibly a few header inclusions and macro definitions.
4. Guard everything else by `#if defined(MBEDTLS_XXX_C)` or some such.

Enforce this order in files that previously did things they shouldn't have
before including `common.h`. To locate the potentially
problematic files:

```
grep -m1 '^#' library/*.c | grep -v -F common.h
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-12-02 22:35:16 +01:00
Manuel Pégourié-Gonnard
8b0ee342fa rsa: use the CRT to generate blinding values
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-11-18 12:02:33 +01:00
Manuel Pégourié-Gonnard
b13033dd3e rsa: extract helper function for CRT
Was only used in one place so far, but will be used in
rsa_gen_rand_with_inverse()'s upcoming CRT-based implementation.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-11-18 11:39:40 +01:00
Manuel Pégourié-Gonnard
3be31bf21b rsa: extract helper function
Will gain a new implementation using the CRT, so we want to hide the
upcoming complexity in a dedicated function.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-11-18 11:38:47 +01:00
Valerio Setti
14ada7f73c Merge pull request #10473 from valeriosetti/issue488-3.6
[3.6] psa_load_builtin_key_into_slot: prevent accessing the PSA storage if key ID is in volatile range
2025-11-11 12:31:15 +00:00
Juha-Pekka Kesonen
b11d969e2c ssl_msg.c: change log level for record checking
Signed-off-by: Juha-Pekka <juha-pekka.kesonen@nordicsemi.no>
2025-11-05 15:06:02 +02:00
Juha-Pekka Kesonen
a535836d14 ssl_tls12: change log level for ECDH computation
Signed-off-by: Juha-Pekka <juha-pekka.kesonen@nordicsemi.no>
2025-11-05 15:05:23 +02:00
Valerio Setti
cc0385852d Merge pull request #10471 from yanesca/fix_dead_code_231025
Fix dead code - 3.6 Backport
2025-10-31 12:49:57 +00:00
Valerio Setti
667e56a0a7 Merge pull request #10478 from Cube707/backport/iar-compiler-warning
[backport] add cast to fix IAR compiler errors
2025-10-31 12:33:11 +00:00
Jan Wille
8d59423fe5 format: apply suggestions (add spaces)
Signed-off-by: Jan Wille <jan.wille@siemens.com>
2025-10-29 15:50:57 +01:00
Jan Spannberger
73d5398f02 add cast to fix IAR compiler errors
IAR throws a warning "mixed ENUM with other type"

backport of a5384bdf09

Signed-off-by: Jan Spannberger <jan.spannberger@siemens.com>
2025-10-28 15:14:30 +01:00
Valerio Setti
1b93588d93 psa_crypto_slot_management: check key ID range when loading a persistent key
Do not try to load a persistent key whose key ID is in the volatile range.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2025-10-27 11:12:07 +01:00
Luc Schrijvers
7a399a6ed6 Add library/CMakeList.txt to the changes
Signed-off-by: Luc Schrijvers <begasus@gmail.com>
2025-10-24 13:00:40 +02:00
Janos Follath
94700198fb Remove dead code
Signed-off-by: Janos Follath <janos.follath@arm.com>
2025-10-23 14:43:52 +01:00
Minos Galanakis
ddffba970b Revert "Added generated files"
This reverts commit 335197e60c.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-10-22 10:51:01 +01:00
Minos Galanakis
5a3d0214b3 Merge tag 'mbedtls-3.6.5' into mbedtls-3.6.5_mergeback
Mbed TLS 3.6.5

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-10-15 18:41:13 +01:00