1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-10-23 01:52:40 +03:00
Commit Graph

13672 Commits

Author SHA1 Message Date
Minos Galanakis
bafcf5bddf Merge remote-tracking branch 'restricted/mbedtls-3.6-restricted' into mbedtls-3.6.5rc0-pr
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-10-02 15:37:04 +01:00
Ben Taylor
6e73b2f2fd Backport time_t type conversions
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-09-29 15:35:28 +01:00
Gilles Peskine
b6bf893c70 Qualify "reference implementation" wording
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-17 14:04:10 +02:00
Gilles Peskine
334dfa8799 Merge remote-tracking branch '3.6' into restricted-3.6-merge-public-20250916
Conflicts:

* `framework`: update submodule to the merge of `main` and `main-restricted`.
2025-09-16 16:16:53 +02:00
Gilles Peskine
c2b94d45d4 Merge pull request #10401 from gilles-peskine-arm/psa_can_do-declare-publicly-3.6
Backport 3.6: Declare psa_can_do_cipher() publicly
2025-09-15 12:02:50 +00:00
Janos Follath
753036edb3 Merge pull request #10336 from gilles-peskine-arm/generated-files-lib-build-3.6
Backport 3.6: fix `make lib GEN_FILES=` sometimes requiring python
2025-09-12 13:27:26 +00:00
Gilles Peskine
3aee15b8e5 Declare psa_can_do_cipher() in a public header
Integrators in a client-server architecture need to provide this function on
the client side.

Fixes mbedtls/issues#10341.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-12 11:27:07 +02:00
Manuel Pégourié-Gonnard
3e59e0ae08 Merge pull request #1411 from mpg/bypass-wrappers
[3.6] Bypass GCD/modinv wrappers when possible
2025-09-11 12:25:23 +02:00
Manuel Pégourié-Gonnard
c6b28b31ef Be explicit about modinv output range
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-09-11 09:58:45 +02:00
Gilles Peskine
cc908ad04c Remove redundant memset on freshly initialized buffer
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-08 12:22:39 +02:00
Gilles Peskine
04dfd70432 psa_cipher_decrypt: treat status and output length as sensitive
In `psa_cipher_decrypt()` and in the corresponding function in our built-in
implementation `mbedtls_psa_cipher_decrypt()`, treat `status` and
`*output_length` as sensitive variables whose value must not leak through a
timing side channel. This is important when doing decryption with unpadding,
where leaking the validity or amount of padding can enable a padding oracle
attack.

With this change, `psa_cipher_decrypt()` should be constant-time if the
underlying legacy function (including the cipher implementation) is.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-08 12:22:39 +02:00
Gilles Peskine
3b380daedb psa_cipher_finish: treat status and output length as sensitive
In `psa_cipher_finish()` and in the corresponding function in our built-in
implementation `mbedtls_psa_cipher_finish()`, treat `status` and
`*output_length` as sensitive variables whose value must not leak through a
timing side channel. This is important when doing decryption with unpadding,
where leaking the validity or amount of padding can enable a padding oracle
attack.

With this change, `psa_cipher_finish()` should be constant-time if the
underlying legacy function (including the cipher implementation) is.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-08 12:22:39 +02:00
Gilles Peskine
e74b42832e Return PSA_ERROR_INVALID_PADDING in constant time
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-08 12:22:39 +02:00
Gilles Peskine
d179dc80a5 Use mbedtls_psa_cipher_finish() in PSA
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-08 12:22:39 +02:00
Gilles Peskine
9d7d0e63ae Merge pull request #1407 from gilles-peskine-arm/mbedtls_cipher_finish_padded-3.6
Backport 3.6: Introduce mbedtls_cipher_finish_padded
2025-09-08 12:18:50 +02:00
Gilles Peskine
9f7ac0371f Fix code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-08-29 10:46:52 +02:00
Gilles Peskine
7e43145bac Typo
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-08-29 09:35:29 +02:00
Gilles Peskine
2324a02602 Create threading_internal.h
This is meant to hold threading-related definitions that are not public, but
are used in the test framework.

To be populated later.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-08-29 08:59:27 +02:00
Manuel Pégourié-Gonnard
c18eea6d43 Minor grammar fix in comment
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-26 11:34:45 +02:00
Manuel Pégourié-Gonnard
b46432930e ecdsa: rm unused variable
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-26 11:33:12 +02:00
Manuel Pégourié-Gonnard
6ab0f519b8 dhm: remove unused variable (and improve comment)
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-26 11:31:52 +02:00
Manuel Pégourié-Gonnard
9e1c532847 RSA: use CT gcd-modinv in deduce_private_exponent()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-14 09:40:05 +02:00
Manuel Pégourié-Gonnard
a4bf680e92 RSA: refactor: avoid code duplication
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-14 09:40:05 +02:00
Manuel Pégourié-Gonnard
630148e67f RSA: use constant-time modinv in deduce_crt()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-14 09:40:05 +02:00
Manuel Pégourié-Gonnard
7dcfd73731 RSA: use constant-time GCD in deduce_primes()
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-14 09:18:52 +02:00
Manuel Pégourié-Gonnard
0d73de5ee0 ecdsa: use CT modinv
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-14 09:18:52 +02:00
Manuel Pégourié-Gonnard
f35d30799c ECP: use CT modinv
A function that was previously called in multiple places is now called
only once, hence more susceptible to being inlined, hence the test fix.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-14 09:18:52 +02:00
Manuel Pégourié-Gonnard
c2d210ea0d DHM: use CT modinv for blinding
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-14 09:18:52 +02:00
Manuel Pégourié-Gonnard
a56a05b015 RSA: use CT gcd-modinv in prepare_blinding()
While at it, draw the blinding value uniformly in the permissible range.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-14 09:18:52 +02:00
Janos Follath
210f8bc4d7 Merge pull request #1408 from mpg/improve-gcd-3.6
[3.6] Make GCD (a lot) less leaky
2025-08-13 19:44:57 +01:00
Manuel Pégourié-Gonnard
30f0732369 bignum: gcd: improve comments
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-13 09:01:55 +02:00
Manuel Pégourié-Gonnard
87e77d6516 bignum: fix memory leak in GCD with 0 as an input
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-13 09:01:55 +02:00
Manuel Pégourié-Gonnard
381d4ba03b Make mbedtls_mpi_gcd() more consistent
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-13 09:01:45 +02:00
Manuel Pégourié-Gonnard
c6a9d84555 bignum: use CT gcd for mbedtls_mpi_gcd()
The overall function is still not constant-time, but it just got a lot
less leaky.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-13 09:01:45 +02:00
Manuel Pégourié-Gonnard
a08faf9070 bignum: follow customs for ret initialisation
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-12 11:55:22 +02:00
Manuel Pégourié-Gonnard
7a5447ff65 Fix a few typos
Co-authored-by: Felix Conway <felix.conway@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-12 11:55:15 +02:00
Manuel Pégourié-Gonnard
65b8011f7e bignum: make mbedtls_mpi_lsb() less leaky
The path using builtin should be OK, as it should be using dedicated CPU
instructions which are constant time.

This fixes the no-builing path.

GCC gained support for __has_builtin in version 10. We're still testing
with older GCC on the CI, so the non-builtin path is tested on the CI.

https://gcc.gnu.org/gcc-10/changes.html

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-11 09:36:26 +02:00
Manuel Pégourié-Gonnard
40dfc811ef bignum: remove dead variable-time inv_mod code
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-11 09:35:28 +02:00
Manuel Pégourié-Gonnard
1ac0a1e071 bignum: use CT modinv when A is odd (any range)
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-11 09:35:28 +02:00
Manuel Pégourié-Gonnard
e41709c17e bignum: use CT modinv when A is odd and in [2, N)
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-11 09:35:28 +02:00
Manuel Pégourié-Gonnard
cdfd1c9c7d bignum: use CT modinv when N is odd
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-08-11 09:35:28 +02:00
Gilles Peskine
6cb9f35d8c Switch legacy cipher to constant-time invalid padding reporting
In internal `get_padding` functions, report whether the padding was invalid
through a separate output parameter, rather than the return code. Take
advantage of this to have `mbedtls_cipher_finish_padded()` be the easy path
that just passes the `invalid_padding` through. Make
`mbedtls_cipher_finish()` a wrapper around `mbedtls_cipher_finish_padded()`
that converts the invalid-padding output into an error code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-08-08 15:14:47 +02:00
Gilles Peskine
155de2ab77 New function mbedtls_cipher_finish_padded
New function `mbedtls_cipher_finish_padded()`, similar to
`mbedtls_cipher_finish()`, but reporting padding errors through a separate
output parameter. This makes it easier to avoid leaking the presence of a
padding error, especially through timing. Thus the new function is
recommended to defend against padding oracle attacks.

In this commit, implement this function naively, with timing that depends on
whether an error happened. A subsequent commit will make this function
constant-time.

Copy the test decrypt_test_vec and decrypt_test_vec_cf test cases into
variants that call `mbedtls_cipher_finish_padded()`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-08-08 15:14:47 +02:00
Felix Conway
a1c95e378a Adjust mpi_gcd_modinv_odd() internals
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-08-06 09:54:11 +01:00
Felix Conway
eefdfe99a4 Change A=0 (null) handling in mpi_gcd_invmod_odd()
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-08-05 14:35:53 +01:00
Felix Conway
d9c4c9c441 Update mpi_gcd_invmod_odd() related comments/documentation
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-08-05 14:33:32 +01:00
Felix Conway
f4df43b6c4 Fix gcd_invmod_odd wrapper when A is 0 (null)
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-08-04 17:00:10 +01:00
Felix Conway
54a94c1598 Adjust mpi_gcd_modinv_odd docs and precondition checking
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-08-04 11:34:19 +01:00
Felix Conway
bd7ede3f33 bignum: add mpi wrapper for gcd_modinv
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-08-04 11:33:48 +01:00
Gilles Peskine
618307046a Also test make clean in library
Don't test `make clean` at the toplevel, that would be too much work (we'd
need to support `$(RM)` in all makefiles, and arrange for `find` as well for
`clean_more_on_top`).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-07-31 14:15:27 +02:00