Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library: key policies with persistence #19

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8853894
[nrf noup] Remove duplicated legacy Mbed TLS header files
frkv Aug 22, 2024
676e65f
[nrf noup] Remove redefinition ECC_MAX_CURVE_BITS
Vge0rge Nov 28, 2023
57029f3
[nrf noup] Add missing brainpool key sizes
Vge0rge Feb 5, 2024
7248c60
[nrf noup] Remove oberon_config.h inclusion
Vge0rge Feb 6, 2024
18dd07c
[nrf noup] Make Oberon PSA hash operation static
Vge0rge Feb 9, 2024
77f3bda
[nrf noup] Turn the repo into a Zephyr module
SebastianBoe Mar 8, 2024
89285d3
[nrf noup] Align build_info.h with Mbed TLS 3.6.1
SebastianBoe Mar 12, 2024
050fc1f
[nrf toup] Support builtin keys with CMAC KDF
vlilleboe Apr 8, 2024
4e3141b
[nrf noup] keys: Add plausibility checks for ECC keys
mswarowsky Mar 19, 2024
0a93307
[nrf noup] library: psa_crypto_storage.c error
Vge0rge Apr 17, 2024
5724fe6
[nrf noup] testspec: Add test spec to run crypto and TF-M tests
stephen-nordic Mar 8, 2024
3907b92
[nrf noup] Adjust range for builtin keys
vlilleboe Apr 19, 2024
373f6dd
[nrf noup] Allow import and destroy of builtin keys
vlilleboe Apr 3, 2024
e71f27f
[nrf toup] Add missing defined oberon_key_derivation.c
Vge0rge Jul 17, 2024
58dbf90
[nrf noup] Don't ignore error code
vlilleboe Jun 14, 2024
c3443d2
[nrf noup] PSA key attribute ABI compliance
frkv Aug 22, 2024
0de74c2
[nrf noup] psa: Using simpler initialization for operation structs
frkv Aug 23, 2024
825a7fd
[nrf noup]: Change attributes-type to pointer (was struct)
frkv Sep 9, 2024
b8dfab5
[nrf noup]: fix mbedtls_psa_crypto_configure_entropy_sources symbol
frkv Sep 9, 2024
b41e899
Do not use generic header names
krish2718 Sep 26, 2024
21728cf
added skip in ecdsa verify if eddsaph
PFnord Nov 11, 2024
b4d8848
library: key policies with persistence
michalek-no Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[nrf noup] Allow import and destroy of builtin keys
Adds the capability of import and destroying persistent keys
that are "builtin" i.e. handled fully by PSA driver implementation.

Signed-off-by: Vidar Lillebø <vidar.lillebo@nordicsemi.no>
Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
vlilleboe authored and frkv committed Sep 10, 2024
commit 373f6dde9cf5cae3ae0c7d7736734ca986b6363e
21 changes: 13 additions & 8 deletions library/psa_crypto.c
Original file line number Diff line number Diff line change
@@ -870,6 +870,12 @@ psa_status_t psa_destroy_key(mbedtls_svc_key_id_t key)
}
#endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */

#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
if (psa_key_id_is_builtin(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(slot->attr.id))) {
psa_driver_wrapper_destroy_builtin_key(&slot->attr);
}
#endif /* defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) */

exit:
/* Unregister from reading the slot. If we are the last active reader
* then this will wipe the slot. */
@@ -1129,7 +1135,7 @@ static psa_status_t psa_validate_key_attributes(
return PSA_ERROR_INVALID_ARGUMENT;
}
} else {
if (!psa_is_valid_key_id(psa_get_key_id(attributes), 0)) {
if (!psa_is_valid_key_id(psa_get_key_id(attributes), 1)) {
return PSA_ERROR_INVALID_ARGUMENT;
}
}
@@ -1277,7 +1283,11 @@ static psa_status_t psa_finish_key_creation(
#endif

#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
if (!PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)) {
if (!PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
&& !psa_key_id_is_builtin(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(slot->attr.id))
#endif
) {
/* Key material is saved in export representation in the slot, so
* just pass the slot buffer for storage. */
status = psa_save_persistent_key(&slot->attr,
@@ -4396,7 +4406,6 @@ psa_status_t psa_key_derivation_input_key(
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
psa_key_slot_t *slot = NULL;
psa_key_attributes_t attributes;

status = psa_get_and_lock_key_slot_with_policy(
key, &slot, 0, operation->alg);
@@ -4418,12 +4427,8 @@ psa_status_t psa_key_derivation_input_key(
operation->can_output_key = 1;
}

attributes = (psa_key_attributes_t) {
.core = slot->attr
};

status = psa_key_derivation_input_internal(operation,
step, &attributes,
step, &slot->attr,
slot->key.data,
slot->key.bytes);

11 changes: 11 additions & 0 deletions library/psa_crypto_driver_wrappers.c
Original file line number Diff line number Diff line change
@@ -2098,4 +2098,15 @@ psa_status_t psa_driver_wrapper_free_random(
return PSA_SUCCESS;
}

psa_status_t psa_driver_wrapper_destroy_builtin_key(const psa_key_attributes_t *attributes)
{
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->core.lifetime);

switch (location) {
/* Add cases for drivers here */
}

return PSA_ERROR_NOT_SUPPORTED;
}

#endif /* MBEDTLS_PSA_CRYPTO_C */
3 changes: 3 additions & 0 deletions library/psa_crypto_driver_wrappers.h
Original file line number Diff line number Diff line change
@@ -154,6 +154,9 @@ psa_status_t psa_driver_wrapper_derive_key(
const uint8_t *input, size_t input_length,
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length);

psa_status_t psa_driver_wrapper_destroy_builtin_key(
const psa_key_attributes_t *attributes);

/*
* Cipher functions
*/
2 changes: 1 addition & 1 deletion library/psa_crypto_slot_management.c
Original file line number Diff line number Diff line change
@@ -531,7 +531,7 @@ psa_status_t psa_validate_key_persistence(psa_key_lifetime_t lifetime)
return PSA_SUCCESS;
} else {
/* Persistent keys require storage support */
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) || defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
if (PSA_KEY_LIFETIME_IS_READ_ONLY(lifetime)) {
return PSA_ERROR_INVALID_ARGUMENT;
} else {