141 Commits

Author SHA1 Message Date
Tom Cosgrove
b80516816d
Merge pull request #9536 from mpg/rsapub-perf-dev
[dev] Rsapub performance fix
2024-09-18 14:20:50 +00:00
Gilles Peskine
de4d5b7855
Merge pull request #9497 from minosgalanakis/bugfix/return_early_in_ccm_star
ccm.c: Return early when ccm* is used without tag.
2024-09-13 09:35:18 +00:00
Ronald Cron
8c95999b38
Merge pull request #9544 from eleuzi01/replace-224k1
Replace MBEDTLS_ECP_HAVE_SECP224K1 with PSA_WANT_ECC_SECP_K1_224
2024-09-06 15:15:35 +00:00
Elena Uziunaite
63cb13e494 Replace MBEDTLS_ECP_HAVE_SECP224K1 with PSA_WANT_ECC_SECP_K1_224
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-09-05 12:43:14 +01:00
Manuel Pégourié-Gonnard
b70ef8690a Move new files to their correct location
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-05 12:55:12 +02:00
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
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
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
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
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
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
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
Elena Uziunaite
9fc5be09cb Replace MBEDTLS_MD_CAN_SHA1 with PSA_WANT_ALG_SHA_1
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-09-04 18:12:59 +01: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
Gabor Mezei
c15ef93aa5
Replace MBEDTLS_MD_CAN_SHA512 with PSA_WANT_ALG_SHA_512
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2024-08-28 18:20:25 +02:00
Gilles Peskine
0a2b6e2945 Merge remote-tracking branch 'development' into development-restricted 2024-08-23 11:14:11 +02:00
Minos Galanakis
83dbac71db ccm.c: Return early when ccm* is used without tag.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-22 16:36:27 +01:00
Sergey Markelov
4ed0fded12 Fix Mbed-TLS build when WIN32_LEAN_AND_MEAN macro is defined globally
Signed-off-by: Sergey Markelov <sergey@solidstatenetworks.com>
2024-08-14 15:15:14 -07:00
Gilles Peskine
b8457fff9f
Merge pull request #9353 from eleuzi01/replace-ecp-have-secp384r1
Replace MBEDTLS_ECP_HAVE_SECP384R1 with PSA_WANT_ECC_SECP_R1_384
2024-08-12 14:37:10 +00:00
Bence Szépkúti
88f3dd9f78
Merge pull request #9402 from tom-daubney-arm/remove_function_level_alt_interface
Remove function level alt interface
2024-08-09 17:59:51 +00:00
Elena Uziunaite
6b4cd48d24 Replace MBEDTLS_ECP_HAVE_SECP384R1 with PSA_WANT_ECC_SECP_R1_384
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-08-09 09:49:03 +01:00
Gilles Peskine
aacbc622a4
Merge pull request #9453 from gilles-peskine-arm/psa-keystore-dynamic-prep-4.0
Prepare for dynamic key store
2024-08-09 08:00:06 +00:00
Minos Galanakis
123a625386 Resolved merge conflicts caused by file moved in #8226
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-08 14:11:53 +01:00
Gilles Peskine
1eaea51978 Fix copypasta
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
0e3704f0a0 Reorder blocks to avoid double negations
Convert `#if !... A #else B #endif` to `#if ... B #else A`. No semantic change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
bdd16d4cb1 Make it possible to enable CTR_DRBG/PSA without a PSA AES driver
Make it possible, but not officially supported, to switch the CTR_DRBG
module to PSA mode even if MBEDTLS_AES_C is defined. This is not really
useful in practice, but is convenient to test the PSA mode without setting
up drivers.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Thomas Daubney
15129195a6 Fix code stlye
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
eb97f2a50f Make missed SHA internal functions static
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
38e64fbce0 Merge if blocks in SHA256/512 code
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
7070d26fa0 Make mbedtls_internal_sha512_process static
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
bfe1b67ec5 Make mbedtls_internal_sha256_process static
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
d4c886e57b Revert to original guarding for mbedtls_internal_aes_encrypt/decrypt
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
8ac215e482 Correct code style
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00