31656 Commits

Author SHA1 Message Date
Manuel Pégourié-Gonnard
49645f6490 Misc improvements to comments
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-05 10:47:45 +02:00
Manuel Pégourié-Gonnard
3106013e17 Fix code style (for real this time, hopefully)
For some reason I didn't think about other files in the previous commit.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-05 10:47:44 +02:00
Manuel Pégourié-Gonnard
464bf78396 Fix guards on #include
The rest of the file uses mbedtls_mpi_uint_t unconditionally, so its
definition should also be #include'd unconditionally.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-05 10:47:43 +02:00
Manuel Pégourié-Gonnard
e91d924821 Fix code style
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-05 10:47:42 +02:00
Janos Follath
21445c580f Prepare codepath tests for early termination
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:47:42 +02:00
Janos Follath
44eca95ace Fix incorrect test result
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:47:41 +02:00
Janos Follath
514e62c833 Move bignum code path testing out of the library
Without this, it's not at all obvious that turning on MBEDTLS_TEST_HOOKS
doesn't change the functional behavior of the code.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:47:40 +02:00
Janos Follath
7e909c80ea Explain the choice of the value of MBEDTLS_MPI_IS_PUBLIC
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:47:39 +02:00
Janos Follath
47847ca78b Initial local variables to secure default
Unfortunately compilers aren't good at analyzing whether variables are
analyzed on all code paths, and it is better to initialize to the
safe-path values.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:47:38 +02:00
Janos Follath
816a71f85e Introduce MBEDTLS_MPI_IS_TEST
A + B + 1 is not a good way to get a number that's neither A nor B.
This can be a problem for example if values later are changed to
A = 0 and B = -1.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:47:37 +02:00
Janos Follath
e0825bba49 Add tests for optionally safe code paths in RSA
Only add the test hooks where it is meaningful. That is, not adding
where the operation is essentially the same or the target is not the
function that is being tested.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:47:36 +02:00
Janos Follath
64467ff6d2 Add tests for optionally safe code paths in bignum
Not adding _unsafe version to the tests targeting behaviour related to
RR as it is independent from the secret involved in the safe/unsafe
distinction.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:47:35 +02:00
Janos Follath
b6769598c6 Fix Changelog formatting
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:46:55 +02:00
Janos Follath
c870e05a09 Add header for mbedtls_mpi_exp_mod_unsafe()
To silence no previous prototype warnings. And this is the proper way to
do it anyway.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:46:54 +02:00
Janos Follath
6154765c1b Improve ChangeLog
Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:46:54 +02:00
Janos Follath
6872c5f67d Make mbedtls_mpi_exp_mod_unsafe internal
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:46:53 +02:00
Janos Follath
e1d1854a32 Add changelog
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:46:52 +02:00
Janos Follath
a7eb81290b Fix memory corruption in exp_mod tests
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:46:50 +02:00
Janos Follath
76c0e6f3a2 Clean up initialization in _core_exp_mod()
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:45:53 +02:00
Janos Follath
d6aaee10fd Disable optionally safe test hook in threading builds
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:45:50 +02:00
Janos Follath
08091d79dd Fix optionally safe hooks declarations
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:43:26 +02:00
Janos Follath
87253af893 Optimise public RSA operations
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:43:25 +02:00
Janos Follath
b64f1b50ac Fix mpi_core_exp_mod documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:43:24 +02:00
Janos Follath
1fa5f3a929 Add tests for optionally unsafe code paths
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:43:20 +02:00
Janos Follath
df5e55bcb7 Add tests for optionally safe codepaths
The new test hooks allow to check whether there was an unsafe call of an
optionally safe function in the codepath. For the sake of simplicity the
MBEDTLS_MPI_IS_* macros are reused for signalling safe/unsafe codepaths
here too.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:41:04 +02:00
Janos Follath
a099ac9812 Use actual exponent size for window calculation
The allocated size can be significantly larger than the actual size. In
the unsafe case we can use the actual size and gain some performance.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:39:08 +02:00
Janos Follath
8fc736dc4e Move _public parameters next to their target
It is easier to read if the parameter controlling constant timeness with
respect to a parameter is next to that parameter.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:39:07 +02:00
Janos Follath
24fb8c9be5 Make MBEDTLS_MPI_IS_PUBLIC thumb friendly
In Thumb instructions, constant can be:

- any constant that can be produced by shifting an 8-bit value left by any
  number of bits within a 32-bit word
- any constant of the form 0x00XY00XY
- any constant of the form 0xXY00XY00
- any constant of the form 0xXYXYXYXY.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:39:05 +02:00
Janos Follath
5b69fade31 Move MBEDTLS_MPI_IS_* macros to bignum_core.h
These macros are not part of any public or internal API, ideally they
would be defined in the source files. The reason to put them in
bignum_core.h to avoid duplication as macros for this purpose are
needed in both bignum.c and bignum_core.c.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:39:04 +02:00
Janos Follath
4726cb8f00 Move mixed security code to small local functions
The complexity of having functions whose security properties depend on a
runtime argument can be dangerous. Limit risk by isolating such code in
small functions with limited scope.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:39:03 +02:00
Janos Follath
9a8b1f4a4c Make _optionally_safe functions internal
The complexity of having functions whose security properties depend on a
runtime argument can be dangerous. Limit misuse by making any such
functions local.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:39:02 +02:00
Janos Follath
91537eb09d Improve documentation of MBEDTLS_MPI_IS_PUBLIC
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-09-05 10:39:01 +02:00
Manuel Pégourié-Gonnard
7305002799 Add optionally unsafe variant of exp_mod for perf
Attempt to partially solve the performance regression in 3.6.0 without
adding too much code size.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-05 10:38:58 +02:00
David Horstmann
1d98d9d861
Merge pull request #9526 from mpg/refactor-tls123-verif-dev
Refactor tls123 verif dev
2024-09-03 15:29:10 +00:00
David Horstmann
36fe9188e2
Merge pull request #9252 from gabor-mezei-arm/9114_replace_MBEDTLS_MD_CAN_SHA512_with_PSA_WANT
Replace MBEDTLS_MD_CAN_SHA512 with its PSA_WANT counterpart
2024-09-03 14:07:05 +00:00
Manuel Pégourié-Gonnard
f3cd97dd2e
Merge pull request #9327 from eleuzi01/issue-9319
Remove hacks about asm vs constant-flow testing
2024-09-03 07:37:02 +00:00
Manuel Pégourié-Gonnard
c37877f15d
Merge pull request #9515 from mpg/windows-makefile-fixes
Misc small makefile fixes
2024-09-03 07:32:41 +00:00
Manuel Pégourié-Gonnard
c645f1157d
Merge pull request #9508 from eleuzi01/docs-fix
Fix typo in psa-transition.md
2024-09-02 10:57:06 +00:00
Manuel Pégourié-Gonnard
b721cccd82 Add a ChangeLog entry
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
5398e58fcd Fix guards around function now used by 1.3 as well
Actually moved the function rather than trying to edit guards around it,
because the relevant guards are not nearby, the function was part of
larger blocks, so it seemed risky.

Also, that seems logically correct: the function is no longer part of
the "TLS 1.2 handshake functions common to server and client" section,
it's part of the "helper functions common to 1.2 and 1.3 server and
client" block. Ideally in the future perhaps the file structure should
reflect that (`ssl_generic.c` vs `ssl_tls12_generic.c`?) but that's out
of scope here.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
9e3e991d04 Fix typos in comments
Co-authored-by: David Horstmann <david.horstmann@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
67072bf39a Fix two dependency declarations in ssl-opt
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
a040548747 Improve some comments
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
19dd9f59bc Merge 1.2 and 1.3 certificate verification
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
908f57dfba Minor refactoring of generic SSL certificate verif
Rename as there was a name collision with a static function in another
file: ssl_parse_certificate_verify in ssl_tls12_server.c is the function
that parses the CertificateVerify message, which seems appropriate. Here
it meant "the 'verify' step after parsing the Certificate message".
Use a name that focuses on what it does: verify, not parse.

Also, take ciphersuite_info as an argument: when TLS 1.3 calls this
function, it can pass NULL as the ciphersuite has no influence there.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
843a00dec6 Add support for context f_vrfy callback in 1.3
This was only supported in 1.2 for no good reason.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
fd800c2416 Improve a variable's name
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Manuel Pégourié-Gonnard
5bdadbb1eb Restrict the scope of a few variables
In particular, make sure pointer variables are initialized right after
being declared.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Ronald Cron
95dd6f57cd ssl-opt.sh: Test trusted certificate callback in TLS 1.3
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00
Ronald Cron
bfbecf8b34 tls13: Add support for trusted certificate callback
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-02 12:46:03 +02:00