253 Commits

Author SHA1 Message Date
Ronald Cron
96c6f5eb36
Merge pull request #9492 from eleuzi01/remove-legacy-symbol-definitions
Remove definitions of legacy symbols
2024-10-01 10:33:06 +00:00
Elena Uziunaite
404311a702 Remove MBEDTLS_ECP_HAVE_SECP256R1 leftovers
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-09-26 14:48:59 +01:00
David Horstmann
b268d270ed
Merge pull request #9413 from sezrab/split_numeric_string_conversions_oid-development
Split numeric string conversions out of the OID module
2024-09-26 12:50:37 +00:00
David Horstmann
bae154d76c
Merge pull request #9385 from eleuzi01/replace-ecdsa-some
Replace MBEDTLS_PK_HAVE_ECDSA* with PSA_WANT counterparts
2024-09-19 13:53:18 +00:00
Sam Berry
3da783b468 Move static OID functions to x509.c
This commit moves static functions that are necessary for
mbedtls_oid_get_numeric_string and mbedtls_oid_from_numeric_string from
oid.c to x509.c

Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-09-18 21:23:17 +01:00
Sam Berry
2bb3f4d6d4 Move mbedtls_oid_from_numeric_string unit tests to test_suite_x509write
This commit moves all related mbedtls_oid_from_numeric_string unit tests
from test_suite_oid to test_suite_x509write.

Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-09-18 21:23:17 +01:00
Sam Berry
c71abc3fd3 Move mbedtls_oid_from_numeric_string to x509_create.c
This commit moves the mbedtls_oid_from_numeric_string function
definition from oid.c to x509_create.c

Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-09-18 21:23:17 +01:00
Sam Berry
4aee6a25ca Move mbedtls_oid_get_numeric_string unit tests to test_suite_x509parse
This commit moves all related mbedtls_oid_get_numeric_string unit tests
from test_suite_oid to test_suite_x509parse.

Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-09-18 21:23:17 +01:00
Sam Berry
4f76194eaf Move function mbedtls_oid_get_numeric_string to x509.c
This commit moves the mbedtls_oid_get_numeric_string function definition
from oid.c to x509.c.

Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-09-18 21:23:17 +01:00
Sam Berry
f8db5b6f72 Move the function declarations to x509.h
This commit moves the function declarations for
mbedtls_oid_get_numeric_string and mbedtls_oid_from_numeric_string from
oid.h to x509.h.

Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-09-18 21:23:09 +01:00
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
David Horstmann
7ba04a298c Bump version to 4.0.0
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-09-10 10:43:14 +02:00
Ronald Cron
932878137a Use scripts/project_name.txt in Python scripts
Use scripts/project_name.txt in Python scripts
to detect between Mbed TLS and TF-PSA-Crypto
project.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-09-10 10:43:02 +02:00
Elena Uziunaite
8d8620bf18 Address review comments: add PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-09-09 11:18:10 +01:00
Elena Uziunaite
bed21b55a6 Replace MBEDTLS_PK_CAN_ECDSA_VERIFY with PSA_HAVE_ALG_ECDSA_VERIFY
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-09-09 11:18:10 +01:00
Elena Uziunaite
39c7d5dc4b Replace MBEDTLS_PK_CAN_ECDSA_SIGN with PSA_HAVE_ALG_ECDSA_SIGN
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-09-09 11:18:08 +01:00
Elena Uziunaite
4fd105c3fa Introduce PSA_HAVE_ALG_ECDSA_SIGN and PSA_HAVE_ALG_ECDSA_VERIFY
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-09-09 11:17:36 +01:00
Elena Uziunaite
a6950b8ce7 Replace MBEDTLS_PK_CAN_ECDSA_SOME with PSA_HAVE_ALG_SOME_ECDSA
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-09-09 11:17:36 +01: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
0c4a115442 Remove codepath testing where it's redundant
Constant-time testing with Memsan or Valgrind is much more robust, as it
doesn't require cooperation from the code under test.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-09-05 12:55:11 +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
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
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
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