55 #ifndef PSA_CRYPTO_STRUCT_H 56 #define PSA_CRYPTO_STRUCT_H 58 #include "psa/client.h" 68 #define PSA_HASH_OPERATION_INIT { PSA_NULL_HANDLE } 80 #define PSA_MAC_OPERATION_INIT { PSA_NULL_HANDLE } 92 #define PSA_CIPHER_OPERATION_INIT { PSA_NULL_HANDLE } 104 #define PSA_AEAD_OPERATION_INIT { PSA_NULL_HANDLE } 117 #define PSA_KEY_DERIVATION_OPERATION_INIT { PSA_NULL_HANDLE } 126 psa_key_usage_t usage;
128 psa_algorithm_t alg2;
132 #define PSA_KEY_POLICY_INIT {0, 0, 0} 141 typedef uint16_t psa_key_bits_t;
144 #define PSA_KEY_BITS_TOO_LARGE ( (psa_key_bits_t) ( -1 ) ) 150 #define PSA_MAX_KEY_BITS 0xfff8 159 typedef uint16_t psa_key_attributes_flag_t;
161 #define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \ 162 ( (psa_key_attributes_flag_t) 0x0001 ) 166 #define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \ 167 MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \ 172 #define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \ 178 psa_key_lifetime_t lifetime;
180 psa_key_policy_t policy;
182 psa_key_attributes_flag_t flags;
185 #define PSA_CORE_KEY_ATTRIBUTES_INIT {0, 0, PSA_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0, 0} 190 #if defined(MBEDTLS_PSA_CRYPTO_SE_C) 191 psa_key_slot_number_t slot_number;
193 void *domain_parameters;
194 size_t domain_parameters_size;
197 #if defined(MBEDTLS_PSA_CRYPTO_SE_C) 198 #define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0} 200 #define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0} 209 static inline void psa_set_key_id(psa_key_attributes_t *attributes,
212 attributes->core.id = id;
213 if( attributes->core.lifetime == PSA_KEY_LIFETIME_VOLATILE )
214 attributes->core.lifetime = PSA_KEY_LIFETIME_PERSISTENT;
217 static inline psa_key_id_t psa_get_key_id(
218 const psa_key_attributes_t *attributes)
220 return( attributes->core.id );
223 static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes,
224 psa_key_lifetime_t lifetime)
226 attributes->core.lifetime = lifetime;
227 if( lifetime == PSA_KEY_LIFETIME_VOLATILE )
229 #ifdef MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER 230 attributes->core.id.key_id = 0;
231 attributes->core.id.owner = 0;
233 attributes->core.id = 0;
238 static inline psa_key_lifetime_t psa_get_key_lifetime(
239 const psa_key_attributes_t *attributes)
241 return( attributes->core.lifetime );
244 static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
245 psa_key_usage_t usage_flags)
247 attributes->core.policy.usage = usage_flags;
250 static inline psa_key_usage_t psa_get_key_usage_flags(
251 const psa_key_attributes_t *attributes)
253 return( attributes->core.policy.usage );
256 static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes,
259 attributes->core.policy.alg = alg;
262 static inline psa_algorithm_t psa_get_key_algorithm(
263 const psa_key_attributes_t *attributes)
265 return( attributes->core.policy.alg );
270 psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes,
275 static inline void psa_set_key_type(psa_key_attributes_t *attributes,
278 if( attributes->domain_parameters == NULL )
281 attributes->core.type = type;
289 (void) psa_set_key_domain_parameters( attributes, type, NULL, 0 );
293 static inline psa_key_type_t psa_get_key_type(
294 const psa_key_attributes_t *attributes)
296 return( attributes->core.type );
299 static inline void psa_set_key_bits(psa_key_attributes_t *attributes,
302 if( bits > PSA_MAX_KEY_BITS )
303 attributes->core.bits = PSA_KEY_BITS_TOO_LARGE;
305 attributes->core.bits = (psa_key_bits_t) bits;
308 static inline size_t psa_get_key_bits(
309 const psa_key_attributes_t *attributes)
311 return( attributes->core.bits );