304 Commits

Author SHA1 Message Date
Gilles Peskine
aacbc622a4
Merge pull request #9453 from gilles-peskine-arm/psa-keystore-dynamic-prep-4.0
Prepare for dynamic key store
2024-08-09 08:00:06 +00:00
Gilles Peskine
c51fddbdad Improve documentation in some tests
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-08 15:58:38 +02:00
Gilles Peskine
ec377b1d81 Fix inverted assertion message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-08 15:58:24 +02:00
Minos Galanakis
123a625386 Resolved merge conflicts caused by file moved in #8226
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2024-08-08 14:11:53 +01:00
Gilles Peskine
9e54a4f5ba
Merge pull request #9369 from eleuzi01/replace-ecc-keys
Replace MBEDTLS_PK_HAVE_ECC_KEYS with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
2024-08-08 12:10:43 +00:00
Gilles Peskine
1eaea51978 Fix copypasta
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
35f057330f Keep track of PSA keys used interally
When PSA uses CTR_DRBG for its random generator and CTR_DRBG uses PSA for
AES, as currently implemented, there is one volatile key in permanent use
for the CTR_DRBG instance. Account for that in tests that want to know
exactly how many volatile keys are in use, or how many volatile keys can be
created.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
faa909266a Fix spurious test case failure with accelerated AES
When the PSA RNG uses AES through a PSA driver, it consumes one volatile key
identifier. When MBEDTLS_PSA_KEY_SLOT_DYNAMIC is enabled, that identifier
happens to coincide with the key ID value that the test case assumes not to
exist. Use a different value that avoids this coincidence.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
c0bdb08f83 Improve full-key-store tests
Split the "many transient keys" test function in two: one that expects to
successfully create many keys, and one that expects to fill the key store.
This will make things easier when we add a dynamic key store where filling
the key store is not practical unless artificially limited.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
ab89fcf7f8 Update invalid key id in a test case
PSA_KEY_ID_VOLATILE_MIN-1 is now in the persistent key ID range, so it's no
longer an invalid key ID for registration.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
1e65e64565 Fix overlap between volatile keys and built-in keys
Fix interference between PSA volatile keys and built-in keys
when MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled and
MBEDTLS_PSA_KEY_SLOT_COUNT is more than 4096. This overlap used to make it
possible that a volatile key would receive the identifier of a built-in key,
and is now caught by a static assertion.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
7a0adffd16 Assert that the key ID range for volatile keys is large enough
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
3710e72d78 Assert that key ID ranges don't overlap
Ensure that a key ID can't be in range for more than one of volatile keys,
persistent (i.e. user-chosen) keys or built-in keys.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
2ff81bf03b Add a test for the built-in key range
Restricting the built-in key range would be an API break since applications
can hard-code a built-in key value and expect that it won't clash with
anything else. Make it harder to accidentally break the API.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
b0b1b32914 Prevent mbedtls_psa_register_se_key with volatile keys
mbedtls_psa_register_se_key() is not usable with volatile keys, since there
is no way to return the implementation-chosen key identifier which would be
needed to use the key. Document this limitation. Reject an attempt to create
such an unusable key. Fixes #9253.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
0e3704f0a0 Reorder blocks to avoid double negations
Convert `#if !... A #else B #endif` to `#if ... B #else A`. No semantic change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
bdd16d4cb1 Make it possible to enable CTR_DRBG/PSA without a PSA AES driver
Make it possible, but not officially supported, to switch the CTR_DRBG
module to PSA mode even if MBEDTLS_AES_C is defined. This is not really
useful in practice, but is convenient to test the PSA mode without setting
up drivers.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Gilles Peskine
dc10825ab9 MBEDTLS_STATIC_ASSERT: make it work outside of a function
At the top level, the macro would have had to be used without a following
semicolon (except with permissive compilers that accept spurious semicolons
outside of a function), which is confusing to humans and indenters. Fix
that.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-08-07 12:39:05 +02:00
Thomas Daubney
15129195a6 Fix code stlye
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
eb97f2a50f Make missed SHA internal functions static
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
38e64fbce0 Merge if blocks in SHA256/512 code
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
7070d26fa0 Make mbedtls_internal_sha512_process static
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
bfe1b67ec5 Make mbedtls_internal_sha256_process static
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
d4c886e57b Revert to original guarding for mbedtls_internal_aes_encrypt/decrypt
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
8ac215e482 Correct code style
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
ae5f8cc253 Restore SHA256 & SHA512 prototypes
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
3e0273f41a Internalise functions flagged as internal
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
c65eefa9ab Remove superfluous guard
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
b59c0ba81b Alter guarding in aes.c
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:07 +01:00
Thomas Daubney
2dd830d3c2 Remove superflous comment
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:06 +01:00
Thomas Daubney
28647d8669 Remove MBEDTLS_ECDSA_GENKEY_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:06 +01:00
Thomas Daubney
4864424fea Remove MBEDTLS_ECDSA_SIGN_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:06 +01:00
Thomas Daubney
e3013da240 Remove MBEDTLS_ECDSA_VERIFY_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:06 +01:00
Thomas Daubney
ce5ed8555c Remove MBEDTLS_ECDH_COMPUTE_SHARED_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:06 +01:00
Thomas Daubney
51b90fb6b1 Remove MBEDTLS_ECDH_GEN_PUBLIC_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:06 +01:00
Thomas Daubney
7c0b4adfa2 Remove MBEDTLS_AES_DECRYPT_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:20:03 +01:00
Thomas Daubney
6cf05f9322 Remove MBEDTLS_AES_ENCRYPT_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:15:51 +01:00
Thomas Daubney
955ce58142 Remove MBEDTLS_AES_SETKEY_DEC_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:15:08 +01:00
Thomas Daubney
742a2e3619 Remove MBEDTLS_AES_SETKEY_ENC_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-06 15:09:16 +01:00
Thomas Daubney
2bcf805284 Remove MBEDTLS_DES3_CRYPT_ECB_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-05 15:56:09 +01:00
Thomas Daubney
29561ec658 Remove MBEDTLS_DES_CRYPT_ECB_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-05 15:56:09 +01:00
Thomas Daubney
43874e0a84 Remove MBEDTLS_DES_SETKEY_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-05 15:56:09 +01:00
Thomas Daubney
3ab1b2d00b Remove MBEDTLS_SHA512_PROCESS_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-05 15:56:09 +01:00
Thomas Daubney
297b026d0a Remove MBEDTLS_SHA256_PROCESS_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-05 15:56:09 +01:00
Thomas Daubney
2106f79c49 Remove MBEDTLS_SHA1_PROCESS_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-05 15:56:09 +01:00
Thomas Daubney
64988680c5 Remove MBEDTLS_RIPEMD160_PROCESS_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-05 15:56:09 +01:00
Thomas Daubney
72a88e7255 Remove MBEDTLS_MD5_PROCESS_ALT
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2024-08-05 15:56:09 +01:00
Elena Uziunaite
94dba720e5 Tiny fix in library/constant_time_impl.h
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-08-05 15:55:03 +01:00
Elena Uziunaite
65d102673c Remove the hack in library/constant_time_impl.h
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-08-05 15:54:58 +01:00
Elena Uziunaite
8dde3b3dec Replace MBEDTLS_PK_HAVE_ECC_KEYS with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-08-05 15:41:58 +01:00