32868 Commits

Author SHA1 Message Date
Manuel Pégourié-Gonnard
9516cc4e70 psa: test buffer too small for RSA decrypt
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-11 11:30:45 +02:00
Manuel Pégourié-Gonnard
d73eec656c psa: test buffer sized just for actual plaintext
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-10 09:57:20 +02:00
Manuel Pégourié-Gonnard
4813b0c093 pk: fix builds without PKCS#1 v1.5
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 12:00:02 +02:00
Manuel Pégourié-Gonnard
c76cfd536e pk: also fix RSA-opaque v1.5 decrypt side channels
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:56:59 +02:00
Manuel Pégourié-Gonnard
88d55b8140 Add ChangeLog for the latest RSA padding issues
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:39:44 +02:00
Manuel Pégourié-Gonnard
31ac657745 rsa: move CT tests to .constant_time.data
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:39:44 +02:00
Manuel Pégourié-Gonnard
7e51c31aef rsa/psa: tune doc about RSA v1.5 decrypt usage
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:39:44 +02:00
Gilles Peskine
fe47e9ed89 Define and use mbedtls_rsa_decrypt_decompose_ret()
Use a more structured way of isolating and translating sensitive error codes
from RSA PKCS#1v1.5 decryption.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-08 11:39:44 +02:00
Manuel Pégourié-Gonnard
ea0a2c6d03 rsa/psa/pk: warn more against PKCS#1 v1.5 decrypt
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-02 11:10:06 +02:00
Manuel Pégourié-Gonnard
54682ec425 rsa: add CF testing for PKCS#1 v1.5 decode
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-02 11:10:06 +02:00
Manuel Pégourié-Gonnard
8f4a4eac98 pk: fix side channel in RSA decryption
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-02 09:36:41 +02:00
Manuel Pégourié-Gonnard
689a05df0b pk: test RSA decrypt with buffer too small
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-02 09:36:38 +02:00
Manuel Pégourié-Gonnard
682d8f3e89 psa-rsa: also protect OUTPUT_TOO_LARGE
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-02 09:24:16 +02:00
Manuel Pégourié-Gonnard
f1dc979f27 psa: avoid leaking padding errors
Padding errors should be indistiguishable from success.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-01 10:10:14 +02:00
Manuel Pégourié-Gonnard
503c1375c8 psa-rsa: fix side channel on invalid padding
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-01 10:08:52 +02:00
Manuel Pégourié-Gonnard
859cf0788d psa-rsa: call pkcs1_v15 function directly
Like the OAEP path calls the OAEP function directly

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-06-01 09:52:33 +02:00
Ronald Cron
4c70413087
Merge pull request #1555 from gilles-peskine-arm/ssl_tls13_prepare_new_session_ticket-psa_get_random-3.6
Backport 3.6: Fix ssl_tls13_prepare_new_session_ticket returning 1 on an RNG failure
2026-05-29 16:19:37 +02:00
Ronald Cron
14ff18114f
Merge pull request #1635 from valeriosetti/issue1569-backport-3.6
[backport 3.6] TLS 1.3 certificate chain signature algorithm policy gap
2026-05-29 13:34:52 +02:00
Manuel Pégourié-Gonnard
e3aaf2e614
Merge pull request #1625 from mpg/restricted-check-small-factors-3.6
[3.6] Fix timing leak in RSA prime generation
2026-05-28 23:52:59 +02:00
Manuel Pégourié-Gonnard
a03dafab12
Merge pull request #1633 from mpg/restricted-everest-small-order-3.6
[3.6] Everest small order
2026-05-28 23:44:35 +02:00
Gilles Peskine
8b7af9d421 Improve changelog wording
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-05-28 16:32:09 +02:00
Valerio Setti
b9c8c9c427 changelog: fix typos
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-05-28 13:19:14 +02:00
Valerio Setti
b66d56bc5f changelog: add note about issue 1569 resolution
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-05-28 13:19:14 +02:00
Valerio Setti
4620095cdd ssl: improve documentation of mbedtls_ssl_conf_sig_algs()
Clarify that the 'sig_algs' set through this function are only enforced
during the key exchange and that 'mbedtls_ssl_conf_cert_profile()' should
instead be used to enforce the same algorithms when verifying certificates.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-05-28 13:19:14 +02:00
Manuel Pégourié-Gonnard
6cfab6ce95 ecdh: fix off-by-1 in test comments/names
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-28 12:24:29 +02:00
Manuel Pégourié-Gonnard
ba5e4c156e Add test for x448 invalid inputs
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-28 12:24:29 +02:00
Manuel Pégourié-Gonnard
db94fb0686 Add tests for x25519 non-standard/invalid inputs
We want to reject small order points for two reasons:
- Those give rise to side channels attacks where the underlying field
  arithmetic is not constant time (which our bignum isn't so far),
  see the "May the Fourth" paper mentioned in ecp.
- Those force the shared secret to be all-bytes zero, which is bad for
  protocols that might require contributory behaviour.

Honest peers will never send low-order points anyway.

While at it, test that we are clipping the input to 255 bits (ie, that
we are unsetting bit 256) as required by the RFC.

Again, honest peers will never send strings with bit 256 set. But the
RFC says to accept such strings anyway, so that's what we do.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-28 12:24:29 +02:00
Manuel Pégourié-Gonnard
c6a1f9c838 bignum: fix a typo in a comment
The exact value doesn't matter anyway, but since we mention it, it might
as well be correct.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-26 10:06:50 +02:00
Manuel Pégourié-Gonnard
075e76b65b bignum: compact primality check for small values
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-22 00:49:08 +02:00
Manuel Pégourié-Gonnard
1a3cfa5fe7 bignum: make small primes product static
Avoid a heap allocation every time it is used.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-22 00:38:10 +02:00
Manuel Pégourié-Gonnard
7a29052238 Fix side-channel in prime checking/generation
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-22 00:35:55 +02:00
Manuel Pégourié-Gonnard
72991252c8
Merge pull request #1621 from mpg/resricted-ecp-modp-polish-3.6
[3.6] Improve ECC optimized modp
2026-05-22 00:01:04 +02:00
Manuel Pégourié-Gonnard
05ce3e90eb ecp: fix a typo in a comment
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-21 12:08:44 +02:00
Manuel Pégourié-Gonnard
51f6079c1b ecp: update doc for Koblitz raw quasi-reductions
Those no longer allocate, so they can no longer return that error. This
was missed in the commit that removed heap allocations.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-21 12:07:32 +02:00
Manuel Pégourié-Gonnard
6cf6172ff0 ecp: improve comments in mbedtls_ecp_mod_p256_raw()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
ba50c86b7f ecp: minor simplification in ecp_mod_koblitz()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
fa157d7d50 ecp: don't re-invent BITS_TO_LIMBS()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
a540f097d8 ecp: 2nd pass over mbedtls_ecp_mod_p448_raw()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
a4ec1e3e10 ecp: update #endif comment
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
e1f96dba80 ecp: pass over mbedtls_ecp_mod_p{192,224,256,384}_raw()
Add comments explaining why 3 passes are enough (except for 224 where 1 is enough).

For p256 and p384, this is a bit different
from some other functions as the carry is signed here.

Rm FIPS reference from the documentation, it's about the implementation.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
42eac21181 ecp: use loops in mbedtls_ecp_mod_p{192,256,384}_raw()
On principle:
- If the code is written with a loop, the compiler can easily unroll the
  loop at high optimisation levels; if we unroll the loop in the source,
  the compiler is unlikely to roll it up at -Os/-Oz. So loops are more
  adaptable.
- All the other functions are using loops, and there's nothing special
  about those functions that would justify a different treatement.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
48e255f31b ecp: pass over mbedtls_ecp_mod_p521_raw()
The comments already explained why the result is in the desired range.

However 2^P521_WIDTH didn't make sense as P521_WIDTH is a number of
limbs no bits, so fix that typo.

Remove the FIPS reference as we're not following it and it doesn't bring
anything useful.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
0d638e42ba ecp: pass over mbedtls_ecp_mod_p255_raw()
The test `if (X_Limbs > P255_WIDTH)` was useless: we know that X_limbs =
2 * P255_WIDTH.

The implementation already had an explicit argument why the result is
in range at the end.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
3b667e8a75 ecp: pass over mbedtls_ecp_mod_p448_raw()
The documentation used to say upon return X < N but that's wrong: if we
comment out the final conditional subtract in the test function
ecp_mod_p_generic_raw() then we have p448 cases that fail.
This was probably a typo. The actual guarantee is X < 2^448 < 2 * N.

Slightly optimize the code in the loop: we know that A1 = B0 is 1 limb,
so we don't need to memset() or memcpy() so many limbs.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 13:18:08 +02:00
Manuel Pégourié-Gonnard
676e95ec4b ecp: pass over ecp_mod_koblitz()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 12:29:13 +02:00
Manuel Pégourié-Gonnard
dc44a9b69c ecp: add general comment about fast quasi-reduction
The function-specific comments promised in the last line will follow.

FAST_QUASI_REDUCTION and NIST_QUASI_REDUCTION will be referenced by
specific functions. They're a single word to simplify looking them up.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 12:12:53 +02:00
Manuel Pégourié-Gonnard
7689f99697 ecp: avoid heap usage in ecp_mod_koblitz()
That's one 32-byte buffer and one 40-byte buffer (at most, when the
256-bit "Koblitz" curve is enabled).

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 12:10:52 +02:00
Manuel Pégourié-Gonnard
37279c1f95 ecp: avoid heap usage in mbedtls_ecp_mod_p255_raw()
The buffer is only 32 bytes...

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 12:01:49 +02:00
Manuel Pégourié-Gonnard
581f773c99 ecp: avoid heap usage in mbedtls_ecp_mod_p448_raw()
With 64-bit limbs, we're using two 64-byte arrays on the stack.
With 32-bit limbs, that's two 60-byte arrays.

This is entirely acceptable, and much better than allocating all the
time in a performance-critical function.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 12:01:49 +02:00
Manuel Pégourié-Gonnard
1b531ff7e5 ecp: make mpi_one const again
That way, it can be stored in read-only memory.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-05-20 12:01:49 +02:00