31080 Commits

Author SHA1 Message Date
Gilles Peskine
df0ef8a624
Merge pull request #9281 from mpg/rsapub
[3.6] Reduce performance regression in RSA public operations
2024-08-22 16:50:38 +00:00
Janos Follath
4c857c49b4 Fix Changelog formatting
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-22 15:45:18 +01:00
Janos Follath
5f316972b2 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-08-22 15:00:09 +01:00
Janos Follath
5d16334e84
Improve ChangeLog
Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-22 14:49:58 +01:00
Manuel Pégourié-Gonnard
273d07b0c0
Merge pull request #9240 from gilles-peskine-arm/psa-keystore-dynamic-3.6
Backport 3.6: dynamically sized key store
2024-08-22 12:53:32 +00:00
Janos Follath
82976f3548 Make mbedtls_mpi_exp_mod_unsafe internal
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-22 13:00:12 +01:00
Janos Follath
6c2086931d Add changelog
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-22 12:59:36 +01:00
minosgalanakis
7be977a7a7
Merge pull request #9486 from sergio-nsk/sergio-nsk/3.6/lean_and_mean/1
[Backport 3.6] Fix Mbed-TLS build when WIN32_LEAN_AND_MEAN macro is defined globally
2024-08-22 10:08:11 +00:00
Gilles Peskine
11cac75449 Simplify and explain the overflow check for maximum slice length
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-22 10:55:40 +02:00
David Horstmann
9183ba1179 Add overflow check for maximum key slot length
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-08-21 17:05:37 +01:00
David Horstmann
43124912c5 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 15:18:28 +01:00
David Horstmann
a8e13d7c2a 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 14:41:06 +01:00
Janos Follath
878af12807 Fix memory corruption in exp_mod tests
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-20 12:33:42 +01:00
Janos Follath
afb2079652 Clean up initialization in _core_exp_mod()
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-20 11:00:51 +01:00
Janos Follath
8786dd79f7 Disable optionally safe test hook in threading builds
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-20 10:21:54 +01:00
Janos Follath
a11269187e Fix optionally safe hooks declarations
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-20 09:56:16 +01:00
Janos Follath
9d72df8e6d Optimise public RSA operations
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-15 16:06:19 +01:00
Janos Follath
2c62441f96 Fix mpi_core_exp_mod documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-15 15:53:07 +01:00
Tom Cosgrove
28cdd11908
Merge pull request #9479 from gilles-peskine-arm/psa-keystore-static-release-update-3.6
Backport 3.6: Key store spec: update release target for the static key store
2024-08-15 10:09:29 +00:00
Sergey Markelov
68c0e3d3a6 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:22:37 -07:00
Gilles Peskine
39c227207c The fully static key store will miss the 3.6.1 release
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-14 11:40:55 +02:00
Gilles Peskine
fc1b6f54a3 Mention the option name for the dynamic key store
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-14 11:40:20 +02:00
Manuel Pégourié-Gonnard
70658db50a
Merge pull request #9463 from sezrab/psa_util_in_builds_without_psa-3.6
[Backport 3.6] psa_util.c included in builds without PSA, which can break the build
2024-08-14 07:16:13 +00:00
Manuel Pégourié-Gonnard
e196c1a3f1
Merge pull request #9475 from gilles-peskine-arm/framework-update-20240813-3.6
Update framework to the head of the main branch
2024-08-14 07:11:34 +00:00
Janos Follath
7342656098 Add tests for optionally unsafe code paths
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-13 11:39:03 +01:00
Gilles Peskine
4d9981ac5c Update framework to the head of the main branch
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-13 11:44:16 +02:00
Janos Follath
e0842aa751 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-08-13 08:40:31 +01:00
Janos Follath
020b9ab004 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-08-13 07:53:20 +01:00
Janos Follath
a5fc8f342a 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-08-13 07:41:05 +01:00
Janos Follath
0c292b26a5 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-08-12 20:05:09 +01:00
Janos Follath
90b4271ff0 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-08-12 20:05:04 +01:00
Janos Follath
bb3f295e40 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-08-12 20:03:06 +01:00
Janos Follath
38ff70e169 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-08-12 20:03:06 +01:00
Janos Follath
e084964068 Improve documentation of MBEDTLS_MPI_IS_PUBLIC
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-08-12 20:02:59 +01:00
Janos Follath
5435850017
Merge pull request #9457 from gilles-peskine-arm/announce-4.0-removals-202408
3.6 only: Announce the main removals planned for 4.0
2024-08-12 12:41:37 +00:00
Gilles Peskine
7f9470ac02
Merge pull request #9451 from minosgalanakis/fix-v3.6-issues-9186-and-9188-bp
[Backport 3.6] Fix v3.6 issues 9186 and 9188 bp
2024-08-12 09:34:19 +00:00
Gilles Peskine
47bf23f748 PSA PAKE wasn't in 2.28
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-12 11:21:54 +02:00
Gilles Peskine
ce629a6ce7 entropy.h is also going away
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-12 11:21:10 +02:00
Gilles Peskine
ee7332104d Mention interfaces replaced by PSA drivers
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-10 17:22:45 +02:00
Michael Schuster
3001e27f21 Update the submodule to the head of PR in the framework repository
See Mbed-TLS/mbedtls-framework#23

Signed-off-by: Michael Schuster <michael@schuster.ms>
Signed-off-by: Gilles Peskine <gilles.peskine@arm.com>
2024-08-10 07:01:36 +02:00
Sam Berry
6474d906bb Changelog entry
Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-08-09 13:49:44 +01:00
Sam Berry
81a438b7d7 Remove MBEDTLS_PSA_UTIL_HAVE_ECDSA so that functions are only enabled when PSA enabled
Signed-off-by: Sam Berry <sam.berry@arm.com>
2024-08-09 13:49:38 +01:00
Gilles Peskine
1dfb6b595a Clarify some internal documentation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 14:04:46 +02:00
Gilles Peskine
ac43de0e52 Make integer downsizing explicit
Reassure both humans and compilers that the places where we assign an
integer to a smaller type are safe.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:55:05 +02:00
Gilles Peskine
628ad389be Changelog entry for MBEDTLS_PSA_KEY_STORE_DYNAMIC
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:55:01 +02:00
Gilles Peskine
9dc903a316 Add test components with the PSA static key store
We were only testing the static key store (MBEDTLS_PSA_KEY_STORE_DYNAMIC
disabled) with configs/*.h. Add a component with the static key store and
everything else (including built-in keys), and a component with the static
key store and CTR_DBRG using PSA for AES (which means PSA uses a volatile
key internally).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:54:56 +02:00
Gilles Peskine
3bc9d2b5b9 Dynamic key store: make full-key-store tests work effectively
Add a practical way to fill the dynamic key store by artificially limiting
the slice length through a test hook.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:54:54 +02:00
Gilles Peskine
a81282ce30 Microoptimizations when MBEDTLS_PSA_KEY_STORE_DYNAMIC is disabled
Compensate some of the code size increase from implementing dynamic key slots.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:54:19 +02:00
Gilles Peskine
e8199f574c Dynamic key store: implementation
When MBEDTLS_PSA_KEY_STORE_DYNAMIC is enabled, key slots are now organized in
multiple slices. The slices are allocated on demand, which allows the key
store to grow. The size of slices grows exponentially, which allows reaching
a large number of slots with a small (static) number of slices without too
much overhead.

Maintain a linked list of free slots in each slice. This way, allocating a
slot takes O(1) time unless a slice needs to be allocated.

In this commit, slices are only ever freed when deinitializing the key
store. This should be improved in the future to free empty slices.

To avoid growing the persistent key cache without control, the persistent
key cache has a fixed size (reusing MBEDTLS_PSA_KEY_SLOT_COUNT to avoid
creating yet another option).

When MBEDTLS_PSA_KEY_STORE_DYNAMIC is disabled. no semantic change and
minimal changes to the code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:52:56 +02:00
Gilles Peskine
47ad2f7484 psa_key_slot_t: different fields in free vs occupied slots
Place some fields of psa_key_slot_t in a union, to prepare for a new field
in free slots that should not require extra memory.

For occupied slots, place only the registered_readers field in the union,
not other fields, to minimize textual changes. All fields could move to the
union except state (also needed in free slots) and attr (which must stay
first to reduce the code size, because it is accessed at many call sites).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:52:54 +02:00