31182 Commits

Author SHA1 Message Date
Gowtham Suresh Kumar
c2ec6fa25b Free allocated memory where methods were returning without freeing
Signed-off-by: Sam Berry <sam.berry@arm.com>
Signed-off-by: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
2024-08-19 11:50:10 +01:00
Elena Uziunaite
04db1fb481 Add test cases for extKeyUsage
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-08-16 17:19:37 +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
Elena Uziunaite
e74c840b5e Rationalize extKeyUsage tests
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-08-15 15:33:26 +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
Manuel Pégourié-Gonnard
cdd5b07eb1 Use P_CLI when O_CLI's status is not reliable
Generally speaking, in this group of test we use O_SRV when testing our
client's behaviour, and O_CLI when testing our server's behaviour. I
don't think that's essential, but why not.

Well, for these two tests there's a reason why not: O_CLI often exits 0,
seemingly not minding that the server aborted the handshake with a fatal
alert, but sometimes it exits 1. (I've observed 0 on my machine, on two
runs of OpenCI and Internal CI, and 1 in some test in one run of
Internal CI.)

So, use our client instead, which exits non-zero consistently.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-08-12 09:50:18 +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
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
a11687e543 Revised presentation of cipher suites
Include patterns on the official names.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-08 14:58:35 +02:00
Gilles Peskine
6df289a56f More relevant characterisation of PSA being from before 3.0
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-08 14:45:57 +02:00
Gilles Peskine
086bc91179 Improve mechanism grouping
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-08 14:45:35 +02:00
Gilles Peskine
5e64de034e Fix missing bits in crypto mechanisms
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-08 14:41:12 +02:00
Manuel Pégourié-Gonnard
52c0f5a0fd Rationalize keyUsage testing, round 2
- cli-auth 1.2 was missing a test with an irrelevant bit set in addition
to the relevant bit (which was added for 1.3 previously)
- use consistent naming for fail (hard/soft)

Note: currently there are no "fail (soft)" cases for 1.3 authentication
of server by client, as server auth is mandatory in 1.3 (this will
change in 3.6.1).

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-08-08 12:34:56 +02:00
Manuel Pégourié-Gonnard
013d0798c0 Always print detailed cert errors in test programs
Previously the client was only printing them on handshake success, and
the server was printing them on success and some but not all failures.

This makes ssl-opt.sh more consistent as we can always check for the
presence of the expected message in the output, regardless of whether
the failure is hard or soft.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-08-08 12:34:56 +02:00
Manuel Pégourié-Gonnard
ef41d8ccbe Fix 1.3 failure to update flags for (ext)KeyUsage
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-08-08 12:34:56 +02:00