crypto: Make IPC declaration order follow crypto.h

Order the IPC functions in the same order as the functions are listed in
crypto.h for improved readability.
pull/11315/head
Jaeden Amero 2019-08-21 15:45:09 +01:00
parent dafbf27340
commit b0c83501a4
4 changed files with 948 additions and 967 deletions

View File

@ -40,18 +40,18 @@
/** \brief psa_s_function_t enum defines for all the available functions in PSA Crypto. */ /** \brief psa_s_function_t enum defines for all the available functions in PSA Crypto. */
typedef enum psa_sec_function_s { typedef enum psa_sec_function_s {
PSA_CRYPTO_INVALID, PSA_CRYPTO_INVALID,
PSA_IMPORT_KEY, PSA_SET_KEY_POLICY,
PSA_GET_KEY_POLICY,
PSA_GET_KEY_LIFETIME,
PSA_ALLOCATE_KEY, PSA_ALLOCATE_KEY,
PSA_CREATE_KEY,
PSA_OPEN_KEY, PSA_OPEN_KEY,
PSA_CREATE_KEY,
PSA_CLOSE_KEY, PSA_CLOSE_KEY,
PSA_IMPORT_KEY,
PSA_DESTROY_KEY, PSA_DESTROY_KEY,
PSA_GET_KEY_INFORMATION, PSA_GET_KEY_INFORMATION,
PSA_EXPORT_KEY, PSA_EXPORT_KEY,
PSA_EXPORT_PUBLIC_KEY, PSA_EXPORT_PUBLIC_KEY,
PSA_SET_KEY_POLICY,
PSA_GET_KEY_POLICY,
PSA_GET_KEY_LIFETIME,
PSA_HASH_SETUP, PSA_HASH_SETUP,
PSA_HASH_UPDATE, PSA_HASH_UPDATE,
PSA_HASH_FINISH, PSA_HASH_FINISH,
@ -78,14 +78,14 @@ typedef enum psa_sec_function_s {
PSA_ASYMMETRIC_VERIFY, PSA_ASYMMETRIC_VERIFY,
PSA_ASYMMETRIC_ENCRYPT, PSA_ASYMMETRIC_ENCRYPT,
PSA_ASYMMETRIC_DECRYPT, PSA_ASYMMETRIC_DECRYPT,
PSA_GENERATE_RANDOM,
PSA_GENERATE_KEY,
PSA_GET_GENERATOR_CAPACITY, PSA_GET_GENERATOR_CAPACITY,
PSA_GENERATOR_READ, PSA_GENERATOR_READ,
PSA_GENERATOR_IMPORT_KEY, PSA_GENERATOR_IMPORT_KEY,
PSA_GENERATOR_ABORT, PSA_GENERATOR_ABORT,
PSA_KEY_DERIVATION, PSA_KEY_DERIVATION,
PSA_KEY_AGREEMENT PSA_KEY_AGREEMENT,
PSA_GENERATE_RANDOM,
PSA_GENERATE_KEY,
} psa_sec_function_t; } psa_sec_function_t;
/**@}*/ /**@}*/

View File

@ -13,23 +13,28 @@ extern "C" {
#endif #endif
#define psa_crypto_init psa_sec_crypto_init #define psa_crypto_init psa_sec_crypto_init
#define psa_key_policy_init psa_key_policy_init
#define psa_key_policy_set_usage psa_key_policy_set_usage
#define psa_key_policy_get_usage psa_key_policy_get_usage
#define psa_key_policy_get_algorithm psa_key_policy_get_algorithm
#define psa_set_key_policy psa_sec_set_key_policy
#define psa_get_key_policy psa_sec_get_key_policy
#define psa_get_key_lifetime psa_sec_get_key_lifetime
#define psa_allocate_key psa_sec_allocate_key
#define psa_open_key psa_sec_open_key
#define psa_create_key psa_sec_create_key
#define psa_close_key psa_sec_close_key
#define psa_import_key psa_sec_import_key #define psa_import_key psa_sec_import_key
#define psa_destroy_key psa_sec_destroy_key #define psa_destroy_key psa_sec_destroy_key
#define psa_get_key_information psa_sec_get_key_information #define psa_get_key_information psa_sec_get_key_information
#define psa_export_key psa_sec_export_key #define psa_export_key psa_sec_export_key
#define psa_export_public_key psa_sec_export_public_key #define psa_export_public_key psa_sec_export_public_key
#define psa_key_policy_init psa_key_policy_init
#define psa_key_policy_get_usage psa_key_policy_get_usage
#define psa_key_policy_get_algorithm psa_key_policy_get_algorithm
#define psa_key_policy_set_usage psa_key_policy_set_usage
#define psa_set_key_policy psa_sec_set_key_policy
#define psa_get_key_policy psa_sec_get_key_policy
#define psa_get_key_lifetime psa_sec_get_key_lifetime
#define psa_hash_setup psa_sec_hash_setup #define psa_hash_setup psa_sec_hash_setup
#define psa_hash_update psa_sec_hash_update #define psa_hash_update psa_sec_hash_update
#define psa_hash_finish psa_sec_hash_finish #define psa_hash_finish psa_sec_hash_finish
#define psa_hash_verify psa_sec_hash_verify #define psa_hash_verify psa_sec_hash_verify
#define psa_hash_abort psa_sec_hash_abort #define psa_hash_abort psa_sec_hash_abort
#define psa_hash_clone psa_sec_hash_clone
#define psa_mac_sign_setup psa_sec_mac_sign_setup #define psa_mac_sign_setup psa_sec_mac_sign_setup
#define psa_mac_verify_setup psa_sec_mac_verify_setup #define psa_mac_verify_setup psa_sec_mac_verify_setup
#define psa_mac_update psa_sec_mac_update #define psa_mac_update psa_sec_mac_update
@ -49,21 +54,17 @@ extern "C" {
#define psa_asymmetric_verify psa_sec_asymmetric_verify #define psa_asymmetric_verify psa_sec_asymmetric_verify
#define psa_asymmetric_encrypt psa_sec_asymmetric_encrypt #define psa_asymmetric_encrypt psa_sec_asymmetric_encrypt
#define psa_asymmetric_decrypt psa_sec_asymmetric_decrypt #define psa_asymmetric_decrypt psa_sec_asymmetric_decrypt
#define psa_generate_random psa_sec_generate_random
#define psa_generate_key psa_sec_generate_key
#define psa_get_generator_capacity psa_sec_get_generator_capacity #define psa_get_generator_capacity psa_sec_get_generator_capacity
#define psa_generator_read psa_sec_generator_read #define psa_generator_read psa_sec_generator_read
#define psa_generator_import_key psa_sec_generator_import_key #define psa_generator_import_key psa_sec_generator_import_key
#define mbedtls_psa_crypto_free mbedtls_psa_sec_crypto_free #define psa_generator_abort psa_sec_generator_abort
#define psa_key_derivation psa_sec_key_derivation #define psa_key_derivation psa_sec_key_derivation
#define psa_key_agreement psa_sec_key_agreement #define psa_key_agreement psa_sec_key_agreement
#define psa_generator_abort psa_sec_generator_abort #define psa_generate_random psa_sec_generate_random
#define psa_generate_key psa_sec_generate_key
#define mbedtls_psa_crypto_free mbedtls_psa_sec_crypto_free
#define mbedtls_psa_inject_entropy mbedtls_psa_sec_inject_entropy #define mbedtls_psa_inject_entropy mbedtls_psa_sec_inject_entropy
#define psa_allocate_key psa_sec_allocate_key
#define psa_open_key psa_sec_open_key
#define psa_create_key psa_sec_create_key
#define psa_close_key psa_sec_close_key
#define psa_hash_clone psa_sec_hash_clone
#define MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER 1 #define MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER 1

View File

@ -1137,26 +1137,6 @@ static void psa_key_management_operation(void)
partition_id = msg.client_id; partition_id = msg.client_id;
switch (psa_key_mng.func) { switch (psa_key_mng.func) {
case PSA_GET_KEY_LIFETIME: {
size_t lifetime_length = msg.out_size[0];
psa_key_lifetime_t lifetime;
if (!psa_crypto_access_control_is_handle_permitted(psa_key_mng.handle,
partition_id)) {
status = PSA_ERROR_INVALID_HANDLE;
break;
}
status = psa_get_key_lifetime(psa_key_mng.handle,
&lifetime);
if (status == PSA_SUCCESS) {
psa_write(msg.handle, 0,
&lifetime, lifetime_length);
}
break;
}
case PSA_SET_KEY_POLICY: { case PSA_SET_KEY_POLICY: {
size_t policy_length = msg.in_size[1]; size_t policy_length = msg.in_size[1];
psa_key_policy_t policy; psa_key_policy_t policy;
@ -1195,6 +1175,92 @@ static void psa_key_management_operation(void)
break; break;
} }
case PSA_GET_KEY_LIFETIME: {
size_t lifetime_length = msg.out_size[0];
psa_key_lifetime_t lifetime;
if (!psa_crypto_access_control_is_handle_permitted(psa_key_mng.handle,
partition_id)) {
status = PSA_ERROR_INVALID_HANDLE;
break;
}
status = psa_get_key_lifetime(psa_key_mng.handle,
&lifetime);
if (status == PSA_SUCCESS) {
psa_write(msg.handle, 0,
&lifetime, lifetime_length);
}
break;
}
case PSA_ALLOCATE_KEY: {
status = psa_allocate_key(&psa_key_mng.handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_register_handle(psa_key_mng.handle, partition_id);
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
}
break;
}
case PSA_OPEN_KEY: {
psa_key_id_t id;
id.owner = msg.client_id;
bytes_read = psa_read(msg.handle, 1, &(id.key_id), msg.in_size[1]);
if (bytes_read != msg.in_size[1]) {
SPM_PANIC("SPM read length mismatch");
}
if (msg.in_size[1] != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES) {
SPM_PANIC("Unexpected psa_key_id_t size received from client");
}
status = psa_open_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_register_handle(psa_key_mng.handle, partition_id);
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
}
break;
}
case PSA_CREATE_KEY: {
psa_key_id_t id;
id.owner = msg.client_id;
bytes_read = psa_read(msg.handle, 1, &(id.key_id), msg.in_size[1]);
if (bytes_read != msg.in_size[1]) {
SPM_PANIC("SPM read length mismatch");
}
if (msg.in_size[1] != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES) {
SPM_PANIC("Unexpected psa_key_id_t size received from client");
}
status = psa_create_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_register_handle(psa_key_mng.handle, partition_id);
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
}
break;
}
case PSA_CLOSE_KEY: {
if (!psa_crypto_access_control_is_handle_permitted(psa_key_mng.handle,
partition_id)) {
status = PSA_ERROR_INVALID_HANDLE;
break;
}
status = psa_close_key(psa_key_mng.handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_unregister_handle(psa_key_mng.handle);
}
break;
}
case PSA_IMPORT_KEY: { case PSA_IMPORT_KEY: {
size_t key_length = msg.in_size[1]; size_t key_length = msg.in_size[1];
uint8_t *key = NULL; uint8_t *key = NULL;
@ -1353,72 +1419,6 @@ static void psa_key_management_operation(void)
break; break;
} }
case PSA_ALLOCATE_KEY: {
status = psa_allocate_key(&psa_key_mng.handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_register_handle(psa_key_mng.handle, partition_id);
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
}
break;
}
case PSA_CREATE_KEY: {
psa_key_id_t id;
id.owner = msg.client_id;
bytes_read = psa_read(msg.handle, 1, &(id.key_id), msg.in_size[1]);
if (bytes_read != msg.in_size[1]) {
SPM_PANIC("SPM read length mismatch");
}
if (msg.in_size[1] != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES) {
SPM_PANIC("Unexpected psa_key_id_t size received from client");
}
status = psa_create_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_register_handle(psa_key_mng.handle, partition_id);
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
}
break;
}
case PSA_OPEN_KEY: {
psa_key_id_t id;
id.owner = msg.client_id;
bytes_read = psa_read(msg.handle, 1, &(id.key_id), msg.in_size[1]);
if (bytes_read != msg.in_size[1]) {
SPM_PANIC("SPM read length mismatch");
}
if (msg.in_size[1] != CLIENT_PSA_KEY_ID_SIZE_IN_BYTES) {
SPM_PANIC("Unexpected psa_key_id_t size received from client");
}
status = psa_open_key(psa_key_mng.lifetime, id, &psa_key_mng.handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_register_handle(psa_key_mng.handle, partition_id);
psa_write(msg.handle, 0, &psa_key_mng.handle, sizeof(psa_key_mng.handle));
}
break;
}
case PSA_CLOSE_KEY: {
if (!psa_crypto_access_control_is_handle_permitted(psa_key_mng.handle,
partition_id)) {
status = PSA_ERROR_INVALID_HANDLE;
break;
}
status = psa_close_key(psa_key_mng.handle);
if (status == PSA_SUCCESS) {
psa_crypto_access_control_unregister_handle(psa_key_mng.handle);
}
break;
}
default: { default: {
status = PSA_ERROR_NOT_SUPPORTED; status = PSA_ERROR_NOT_SUPPORTED;
break; break;