31006 Commits

Author SHA1 Message Date
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
Gilles Peskine
b5891cc2cd Dynamic key store: disable full-key-store tests
It's impractical to fill the key store when it can grow to accommodate
millions of keys.

A later commit will restore those tests in test configurations with the
dynamic key store.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:52:50 +02:00
Gilles Peskine
5064af62b6 Dynamic key store: preparatory refactoring
Add some abstractions around code that traverses the key store, in
preparation for adding support for MBEDTLS_PSA_KEY_STORE_DYNAMIC.

No intended behavior change. The generated machine code should be
almost the same with an optimizing compiler (in principle, it could be the
same with sufficient constant folding and inlining, but in practice it will
likely be a few byes larger),

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:52:33 +02:00
Gilles Peskine
2bfd749e86 Dynamic key store: new compilation option
Create a new compilation option for a dynamically resized key store. The
implementation will follow in subsequent commits.

This option is off by default with custom configuration files, which is best
for typical deployments on highly constrained platforms. This option is on
by default with the provided configuration file, which is best for typical
deployments on relatively high-end platforms.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-09 13:52:30 +02:00
Gilles Peskine
3b41e1d2a5
Merge pull request #9403 from gilles-peskine-arm/psa-keystore-dynamic-prep-3.6
Backport 3.6: prepare for dynamic key store
2024-08-09 08:00:03 +00:00
Gilles Peskine
aaa96721d1 Improve documentation in some tests
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-08 15:56:46 +02:00
Gilles Peskine
a9083b752c PSA_DONE: account for MBEDTLS_TEST_PSA_INTERNAL_KEYS
Replace the hard-coded 1 by the proper constant now that the proper constant
exists.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 20:09:08 +02:00
Gilles Peskine
5eca4029c2 Fix inverted assertion message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 20:08:23 +02:00
Tom Cosgrove
4306a69931
Merge pull request #9437 from tom-daubney-arm/bp_3-6_standardise_proj_detection
[3.6 Backport] Standardise Project Detection
2024-08-07 07:18:43 +00:00
Thomas Daubney
a542420e6d Call in_mbedtls_repo
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 18:01:42 +01:00
Gilles Peskine
7ee1a4e5d6
Merge pull request #9235 from gilles-peskine-arm/psa_generate_key_custom-3.6
Backport 3.6: psa_generate_key_custom
2024-08-06 16:41:34 +00:00
Thomas Daubney
5f0b64aadf Move some proj detection code inside pre_check_environment
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 17:38:19 +01:00
Gilles Peskine
14b87f6318 Match spacing in pointer types in documentation with the code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:05 +02:00
Gilles Peskine
4a85ff3997 Rename one more deprecated identifier
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:05 +02:00
Gilles Peskine
0d619b2dc7 Documentation improvements
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:05 +02:00
Gilles Peskine
52504f8568 Rename internal function psa_key_production_parameters_are_default
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:05 +02:00
Gilles Peskine
472c10f4a5 key_custom: update analyze_outcomes.py
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:05 +02:00
Gilles Peskine
f5db72bbb9 Test cpp_dummy_build in pedantic mode
In public headers, we want to avoid things that are not standard C++,
including features that GCC and Clang support as extensions, such as
flexible array members. So compile with `-pedantic`.

Non-regression for https://github.com/Mbed-TLS/mbedtls/issues/9020.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:13:04 +02:00
Gilles Peskine
d865c42776 Changelog entry for the move from key_ext to key_custom functions
Document psa_generate_key_ext() and psa_key_derivation_output_key_ext() as
deprecated in favor of psa_generate_key_custom() and
psa_key_derivation_output_key_custom(), and no longer declared in C++ builds.

Resolves #9020.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:12:07 +02:00
Gilles Peskine
14134e7ddc Remove some tests of psa_generate_key_ext
We know it's a thin wrapper around psa_generate_key_custom, so we just need
to check that it's passing the information through, we don't need coverage
of the parameter interpretation.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:12:06 +02:00
Gilles Peskine
e65cca2ee5 Document the key_ext functions as deprecated
Don't formally deprecate them because we don't do that in a
long-time support branch. But do point readers away from them.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:12:06 +02:00
Gilles Peskine
603b5b842b Documentation: point to key_custom instead of key_ext
Replace references to the deprecated functions `psa_generate_key_ext()` and
`psa_key_derivation_output_key_ext()` by their replacements
Implement `psa_generate_key_custom()` and
`psa_key_derivation_output_key_custom()`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:12:06 +02:00
Gilles Peskine
a8e39f2156 Update PSA wrappers
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:12:06 +02:00
Gilles Peskine
f36d785188 Implement psa_generate_key_custom
Implement `psa_generate_key_custom()` and
`psa_key_derivation_output_key_custom()`. These functions replace
`psa_generate_key_ext()` and `psa_key_derivation_output_key_ext()`.
They have the same functionality, but a slightly different interface:
the `ext` functions use a structure with a flexible array member to pass
variable-length data, while the `custom` functions use a separate parameter.

Keep the `ext` functions for backward compatibility with Mbed TLS 3.6.0.
But make them a thin wrapper around the new `custom` functions.

Duplicate the test code and data. The test cases have to be duplicated
anyway, and the test functions are individually more readable this way.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-06 13:12:06 +02:00
Manuel Pégourié-Gonnard
095cf69bc6
Merge pull request #9444 from minosgalanakis/all-sh-separate-components_36bp
Backport 3.6:  Separate all.sh from its components
2024-08-06 07:58:03 +00:00
Minos Galanakis
bd6b98fd40 all.sh/components: Removed components.sh
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:20:26 +01:00
Minos Galanakis
bb427371e6 all.sh/components: Moved build_aes_via_padlock to platform component.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:20:26 +01:00
Minos Galanakis
5f6d2e3120 all.sh/components: Moved driver components to configuration crypto.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:20:26 +01:00
Minos Galanakis
0c0c3e1713 all.sh/components: Moved more components to configuration crypto.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:20:26 +01:00
Minos Galanakis
4ca7b14060 all.sh/components: Fixed a typo in configuration-tls.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:20:21 +01:00
Minos Galanakis
85347d15c6 all.sh/components: Moved more components to configuration tls.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:19:27 +01:00
Minos Galanakis
4a2a351df8 Extract sanitizer components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:02:39 +01:00
Minos Galanakis
f0cd95b6f6 Extract platform components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:02:39 +01:00
Minos Galanakis
93a8c08910 Extract configuration components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:02:37 +01:00
Minos Galanakis
27968c1660 Extract configuration-x509 components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:01:55 +01:00
Minos Galanakis
5b4386c640 Extract configuration-platform components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:01:53 +01:00
Minos Galanakis
3ece57e173 Extract configuration-crypto-components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-05 12:01:08 +01:00
Gilles Peskine
b49e884c87
Merge pull request #9309 from gilles-peskine-arm/psa-keystore-design-doc-3.6
Backport 3.6: Document the key store design
2024-08-02 07:16:19 +00:00
Minos Galanakis
b298d1f8d2 Extract compliance-components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-02 02:08:54 +01:00
Minos Galanakis
3bd6c30e13 Extract compiler-components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-02 02:08:54 +01:00
Minos Galanakis
2148e5c603 Extract build-components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-02 02:08:54 +01:00
Minos Galanakis
e431739c72 Extract basic-components into a separate file.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-02 02:08:54 +01:00
Minos Galanakis
f7d1cb0275 Separate all.sh from components.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-02 02:08:54 +01:00
Bence Szépkúti
52992e5c38
Merge pull request #9395 from sezrab/mbedtls_test_ssl_message_queue_pop_info-3.6
[Backport 3.6] tests/ssl_helpers: Check that message queue is popped
2024-08-01 18:38:31 +00:00
Minos Galanakis
f1f086e4a3 Applied consistent style.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-01 18:37:41 +01:00
Minos Galanakis
7771119069 Created placeholder component files.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-01 18:37:33 +01:00
Ronald Cron
d289fa1c98
Merge pull request #9432 from gabor-mezei-arm/9158_bp36_update_framework
[Backport 3.6] Adapt config.py to configuration file split
2024-08-01 12:51:34 +00:00
Gabor Mezei
fef3cc30f9
Update framework
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2024-08-01 12:07:11 +02:00