Skip to content

Commit 3c10e5d

Browse files
author
itayzafrir
committed
crypto service: Implement IPC according to Mbed Crypto 1.0.0d1 API
1. Removed obsolete crypto APIs from IPC implementation. 2. Updated existing crypto APIs in IPC implementation. 3. Added new crypto APIs to IPC implemntation (except for psa_hash_clone).
1 parent 563701d commit 3c10e5d

File tree

5 files changed

+285
-144
lines changed

5 files changed

+285
-144
lines changed

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/crypto_platform_spe.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ typedef enum psa_sec_function_s {
4242
PSA_CRYPTO_INVALID,
4343
PSA_CRYPTO_INIT,
4444
PSA_IMPORT_KEY,
45+
PSA_ALLOCATE_KEY,
46+
PSA_CREATE_KEY,
47+
PSA_OPEN_KEY,
48+
PSA_CLOSE_KEY,
4549
PSA_DESTROY_KEY,
4650
PSA_GET_KEY_INFORMATION,
4751
PSA_EXPORT_KEY,
4852
PSA_EXPORT_PUBLIC_KEY,
49-
PSA_KEY_POLICY_INIT,
50-
PSA_KEY_POLICY_SET_USAGE,
51-
PSA_KEY_POLICY_GET_USAGE,
52-
PSA_KEY_POLICY_GET_ALGORITHM,
5353
PSA_SET_KEY_POLICY,
5454
PSA_GET_KEY_POLICY,
55-
PSA_SET_KEY_LIFETIME,
5655
PSA_GET_KEY_LIFETIME,
5756
PSA_HASH_SETUP,
5857
PSA_HASH_UPDATE,
@@ -95,52 +94,50 @@ typedef enum psa_sec_function_s {
9594
*/
9695

9796
/** psa_crypto_ipc_s struct used for some of the
98-
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
97+
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t arguments
9998
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
10099
* pack them together.
101100
*/
102-
103101
typedef struct psa_crypto_ipc_s {
104102
psa_sec_function_t func;
105-
psa_key_slot_t key;
103+
psa_key_handle_t handle;
106104
psa_algorithm_t alg;
107105
} psa_crypto_ipc_t;
108106

109107
/** psa_crypto_derivation_ipc_s struct used for some of the
110-
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
108+
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t arguments
111109
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
112110
* pack them together.
113111
*/
114112
typedef struct psa_crypto_derivation_ipc_s {
115113
psa_sec_function_t func;
116-
psa_key_slot_t key;
114+
psa_key_handle_t handle;
117115
psa_algorithm_t alg;
118116
size_t capacity;
119117
} psa_crypto_derivation_ipc_t;
120118

121119
/** psa_key_mng_ipc_s struct used for some of the
122-
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
120+
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t arguments
123121
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
124122
* pack them together.
125123
*/
126-
127124
typedef struct psa_key_mng_ipc_s {
128-
psa_key_slot_t key;
125+
psa_key_handle_t handle;
126+
psa_key_lifetime_t lifetime;
129127
psa_key_type_t type;
130128
psa_sec_function_t func;
131129
} psa_key_mng_ipc_t;
132130

133131
/** psa_crypto_ipc_aead_s struct used for AEAD integrated
134-
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t and extra arguments
132+
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t and extra arguments
135133
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
136134
* pack them together.
137135
*/
138-
139136
// Max length supported for nonce is 16 bytes.
140137
#define PSA_AEAD_MAX_NONCE_SIZE 16
141138
typedef struct psa_crypto_ipc_aead_s {
142139
psa_sec_function_t func;
143-
psa_key_slot_t key;
140+
psa_key_handle_t handle;
144141
psa_algorithm_t alg;
145142
uint16_t nonce_size;
146143
size_t additional_data_length;
@@ -149,19 +146,18 @@ typedef struct psa_crypto_ipc_aead_s {
149146
} psa_crypto_ipc_aead_t;
150147

151148
/** psa_crypto_ipc_asymmetric_s struct used for asymmetric
152-
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
149+
* PSA Crypto APIs that need psa_key_handle_t and psa_algorithm_t arguments
153150
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
154151
* pack them together.
155152
*/
156153
typedef struct psa_crypto_ipc_asymmetric_s {
157154
psa_sec_function_t func;
158-
psa_key_slot_t key;
155+
psa_key_handle_t handle;
159156
psa_algorithm_t alg;
160157
size_t input_length;
161158
size_t salt_length;
162159
} psa_crypto_ipc_asymmetric_t;
163160

164-
165161
/**@}*/
166162

167163
#endif /* PSA_CRYPTO_SPE_PLATFORM_H */

components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/crypto_struct_ipc.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,34 @@ struct psa_hash_operation_s {
3131
psa_handle_t handle;
3232
};
3333

34+
#define PSA_HASH_OPERATION_INIT { PSA_NULL_HANDLE }
35+
static inline struct psa_hash_operation_s psa_hash_operation_init(void)
36+
{
37+
const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT;
38+
return(v);
39+
}
40+
3441
struct psa_mac_operation_s {
3542
psa_handle_t handle;
3643
};
3744

45+
#define PSA_MAC_OPERATION_INIT { PSA_NULL_HANDLE }
46+
static inline struct psa_mac_operation_s psa_mac_operation_init(void)
47+
{
48+
const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT;
49+
return(v);
50+
}
51+
3852
struct psa_cipher_operation_s {
3953
psa_handle_t handle;
4054
};
4155

42-
struct psa_aead_operation_s {
43-
psa_handle_t handle;
44-
};
56+
#define PSA_CIPHER_OPERATION_INIT { PSA_NULL_HANDLE }
57+
static inline struct psa_cipher_operation_s psa_cipher_operation_init(void)
58+
{
59+
const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT;
60+
return(v);
61+
}
4562

4663
struct psa_crypto_generator_s {
4764
psa_handle_t handle;
@@ -59,5 +76,11 @@ struct psa_key_policy_s {
5976
psa_algorithm_t alg;
6077
};
6178

79+
#define PSA_KEY_POLICY_INIT {0, 0}
80+
static inline struct psa_key_policy_s psa_key_policy_init(void)
81+
{
82+
const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT;
83+
return(v);
84+
}
6285

6386
#endif /* PSA_CRYPTO_STRUCT_H */

0 commit comments

Comments
 (0)