228 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
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
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
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
0b0f090b6e Merge remote-tracking branch 'restricted/development-restricted' into dev-mergeback
* restricted/development-restricted: (30 commits)
  Tiny fix in ChangeLog pt 2
  Tiny fix in ChangeLog
  Changelog entry for the RSA memory leak
  Edit ChangeLog entry
  Update ChangeLog
  Add test cases for extKeyUsage
  Rationalize extKeyUsage tests
  Use P_CLI when O_CLI's status is not reliable
  Rationalize keyUsage testing, round 2
  Always print detailed cert errors in test programs
  Fix 1.3 failure to update flags for (ext)KeyUsage
  Rationalize ssl-opt tests for keyUsage
  Test cert alert KEY_USAGE -> UNSUPPORTED_CERT
  Free allocated memory where methods were returning without freeing
  Force MBEDTLS_PSA_HMAC_DRBG_MD_TYPE based on CTR_DRBG
  Document that MBEDTLS_PSA_HMAC_DRBG_MD_TYPE does not force HMAC
  Clean up constant-flow memsan testing
  Improve description of who is affected
  More diversified sizes in tests
  Fix stack buffer overflow in ECDSA signature format conversions
  ...
2024-09-02 09:18:34 +02: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
ab0af45d11
Merge pull request #9464 from gilles-peskine-arm/psa-keystore-dynamic-development
dynamically sized key store
2024-08-26 10:47:00 +00:00
Gilles Peskine
0a2b6e2945 Merge remote-tracking branch 'development' into development-restricted 2024-08-23 11:14:11 +02:00
Gilles Peskine
4c9fccff5a Simplify and explain the overflow check for maximum slice length
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-22 10:56:19 +02:00
minosgalanakis
d65f4b83f0
Merge pull request #9485 from sergio-nsk/sergio-nsk/lean_and_mean/1
Fix Mbed-TLS build when WIN32_LEAN_AND_MEAN macro is defined globally
2024-08-22 08:01:07 +00:00
David Horstmann
0b2bd071f8 Add overflow check for maximum key slot length
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-08-21 21:49:17 +02:00
David Horstmann
68a4b7453f Tweak macro check to allow 3 extra key slices
We are technically allowed to use all possible values of key slice index
that will fit into the bit width we have allocated, so allow all values.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-08-21 21:49:16 +02:00
David Horstmann
fdcc47c426 Fix incorrect comments on slice numbering
The persistent key cache slice is the last slice (not the first as
previously stated). Update the numbering-related comments accordingly.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-08-21 21:49:14 +02:00
Sam Berry
2547cd3535 Free allocated memory where methods were returning
without freeing

Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-08-16 16:38:34 +01:00
Waleed Elmelegy
e25cb1bcda Fix formatting issue in psa_key_agreement() documentation
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2024-08-16 14:37:46 +01:00
Waleed Elmelegy
d1562407c3 Fix possible issues in testing and implementation of psa_key_agreement()
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2024-08-16 14:37:46 +01:00
Waleed Elmelegy
8faeee24ae Improve documentation of psa_key_agreement()
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2024-08-16 14:37:46 +01:00
Waleed Elmelegy
bdf2c98a27 Add psa_key_agreement() API
Add psa_key_agreement() API and basic testing.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2024-08-16 14:36:47 +01:00
Janos Follath
9e088847ae Clarify IOP key generation restriction
Public keys can't be generated.

Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-15 13:51:05 +01:00
Janos Follath
9f48917b88 Improve IOP documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-15 13:51:05 +01:00
Janos Follath
7311600fd5 Constrain interruptible key generation to key-pairs
Erroring on a symmetric-key type would actually be an extra line of
code.

In theory we could try to save that one line of code, but it is
premature optimisation at this point. Also, this is a predominantly
asymmetric crypto feature, it is less confusing/more user friendly if we
don't allow symmetric keys here.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-15 13:51:05 +01:00
Janos Follath
211ebb51da Don't return success on a stub
We shouldn't return PSA_SUCCESS from a function that isn't implemented.
PSA_ERROR_NOT_SUPPORTED seems like the most appropriate return status
for a function that isn't implemented.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-15 13:51:05 +01:00
Paul Elliott
0c1aa4af38 Add psa_generate_key_iop_abort() documentation
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2024-08-15 13:51:04 +01:00