53 #ifndef PSA_CRYPTO_STRUCT_H 54 #define PSA_CRYPTO_STRUCT_H 62 #if !defined(MBEDTLS_CONFIG_FILE) 63 #include "mbedtls/config.h" 65 #include MBEDTLS_CONFIG_FILE 68 #include "mbedtls/cipher.h" 69 #include "mbedtls/cmac.h" 70 #include "mbedtls/gcm.h" 71 #include "mbedtls/md.h" 72 #include "mbedtls/md2.h" 73 #include "mbedtls/md4.h" 74 #include "mbedtls/md5.h" 75 #include "mbedtls/ripemd160.h" 76 #include "mbedtls/sha1.h" 77 #include "mbedtls/sha256.h" 78 #include "mbedtls/sha512.h" 96 #if defined(MBEDTLS_MD2_C) 97 mbedtls_md2_context md2;
99 #if defined(MBEDTLS_MD4_C) 100 mbedtls_md4_context md4;
102 #if defined(MBEDTLS_MD5_C) 103 mbedtls_md5_context
md5;
105 #if defined(MBEDTLS_RIPEMD160_C) 106 mbedtls_ripemd160_context ripemd160;
108 #if defined(MBEDTLS_SHA1_C) 109 mbedtls_sha1_context sha1;
111 #if defined(MBEDTLS_SHA256_C) 112 mbedtls_sha256_context sha256;
114 #if defined(MBEDTLS_SHA512_C) 115 mbedtls_sha512_context sha512;
120 #define PSA_HASH_OPERATION_INIT {0, {0}} 127 #if defined(MBEDTLS_MD_C) 133 uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
134 } psa_hmac_internal_data;
140 unsigned int key_set : 1;
141 unsigned int iv_required : 1;
142 unsigned int iv_set : 1;
143 unsigned int has_input : 1;
144 unsigned int is_sign : 1;
149 #if defined(MBEDTLS_MD_C) 150 psa_hmac_internal_data hmac;
152 #if defined(MBEDTLS_CMAC_C) 153 mbedtls_cipher_context_t cmac;
158 #define PSA_MAC_OPERATION_INIT {0, 0, 0, 0, 0, 0, 0, {0}} 168 unsigned int key_set : 1;
169 unsigned int iv_required : 1;
170 unsigned int iv_set : 1;
171 unsigned int mbedtls_in_use : 1;
177 mbedtls_cipher_context_t cipher;
182 #define PSA_CIPHER_OPERATION_INIT {0, 0, 0, 0, 0, 0, 0, {0}} 192 unsigned int key_set : 1;
193 unsigned int iv_set : 1;
199 mbedtls_cipher_context_t cipher;
203 #define PSA_AEAD_OPERATION_INIT {0, 0, 0, 0, 0, {0}} 210 #if defined(MBEDTLS_MD_C) 215 psa_hmac_internal_data hmac;
216 uint8_t prk[PSA_HASH_MAX_SIZE];
217 uint8_t output_block[PSA_HASH_MAX_SIZE];
218 #if PSA_HASH_MAX_SIZE > 0xff 219 #error "PSA_HASH_MAX_SIZE does not fit in uint8_t" 221 uint8_t offset_in_block;
222 uint8_t block_number;
223 unsigned int state : 2;
224 unsigned int info_set : 1;
225 } psa_hkdf_key_derivation_t;
228 #if defined(MBEDTLS_MD_C) 231 TLS12_PRF_STATE_INIT,
232 TLS12_PRF_STATE_SEED_SET,
233 TLS12_PRF_STATE_KEY_SET,
234 TLS12_PRF_STATE_LABEL_SET,
235 TLS12_PRF_STATE_OUTPUT
236 } psa_tls12_prf_key_derivation_state_t;
238 typedef struct psa_tls12_prf_key_derivation_s
240 #if PSA_HASH_MAX_SIZE > 0xff 241 #error "PSA_HASH_MAX_SIZE does not fit in uint8_t" 246 uint8_t left_in_block;
249 uint8_t block_number;
251 psa_tls12_prf_key_derivation_state_t state;
257 psa_hmac_internal_data hmac;
258 uint8_t Ai[PSA_HASH_MAX_SIZE];
261 uint8_t output_block[PSA_HASH_MAX_SIZE];
262 } psa_tls12_prf_key_derivation_t;
268 unsigned int can_output_key : 1;
274 #if defined(MBEDTLS_MD_C) 275 psa_hkdf_key_derivation_t hkdf;
276 psa_tls12_prf_key_derivation_t tls12_prf;
282 #define PSA_KEY_DERIVATION_OPERATION_INIT {0, 0, 0, {0}} 297 #define PSA_KEY_POLICY_INIT {0, 0, 0} 306 typedef uint16_t psa_key_bits_t;
309 #define PSA_KEY_BITS_TOO_LARGE ( (psa_key_bits_t) ( -1 ) ) 315 #define PSA_MAX_KEY_BITS 0xfff8 324 typedef uint16_t psa_key_attributes_flag_t;
326 #define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \ 327 ( (psa_key_attributes_flag_t) 0x0001 ) 331 #define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \ 332 MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \ 337 #define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \ 345 mbedtls_svc_key_id_t id;
346 psa_key_policy_t policy;
347 psa_key_attributes_flag_t flags;
350 #define PSA_CORE_KEY_ATTRIBUTES_INIT {PSA_KEY_TYPE_NONE, 0, PSA_KEY_LIFETIME_VOLATILE, MBEDTLS_SVC_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0} 355 #if defined(MBEDTLS_PSA_CRYPTO_SE_C) 358 void *domain_parameters;
359 size_t domain_parameters_size;
362 #if defined(MBEDTLS_PSA_CRYPTO_SE_C) 363 #define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0} 365 #define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0} 375 mbedtls_svc_key_id_t key )
379 attributes->core.id = key;
383 attributes->core.lifetime =
386 PSA_KEY_LIFETIME_GET_LOCATION( lifetime ) );
393 return( attributes->core.id );
396 #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER 398 mbedtls_key_owner_id_t owner )
400 attributes->core.id.owner = owner;
407 attributes->core.lifetime = lifetime;
410 #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER 411 attributes->core.id.key_id = 0;
413 attributes->core.id = 0;
421 return( attributes->core.lifetime );
427 attributes->core.policy.usage = usage_flags;
433 return( attributes->core.policy.usage );
439 attributes->core.policy.alg = alg;
445 return( attributes->core.policy.alg );
458 if( attributes->domain_parameters == NULL )
461 attributes->core.type = type;
476 return( attributes->core.type );
482 if( bits > PSA_MAX_KEY_BITS )
483 attributes->core.bits = PSA_KEY_BITS_TOO_LARGE;
485 attributes->core.bits = (psa_key_bits_t) bits;
491 return( attributes->core.bits );
static void psa_set_key_bits(psa_key_attributes_t *attributes, size_t bits)
Declare the size of a key.
void md5(unsigned char *input, int ilen, unsigned char output[16])
Output = MD5( input buffer )
static psa_algorithm_t psa_get_key_algorithm(const psa_key_attributes_t *attributes)
Retrieve the algorithm policy from key attributes.
static void psa_set_key_usage_flags(psa_key_attributes_t *attributes, psa_key_usage_t usage_flags)
Declare usage flags for a key.
void * ctx
Context structure for the assigned driver, when id is not zero.
static void psa_set_key_lifetime(psa_key_attributes_t *attributes, psa_key_lifetime_t lifetime)
Set the location of a persistent key.
static psa_key_lifetime_t psa_get_key_lifetime(const psa_key_attributes_t *attributes)
Retrieve the lifetime from key attributes.
static void psa_set_key_type(psa_key_attributes_t *attributes, psa_key_type_t type)
Declare the type of a key.
static void psa_set_key_id(psa_key_attributes_t *attributes, mbedtls_svc_key_id_t key)
Declare a key as persistent and set its key identifier.
#define PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)
Whether a key lifetime indicates that the key is volatile.
static size_t psa_get_key_bits(const psa_key_attributes_t *attributes)
Retrieve the key size from key attributes.
#define PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(persistence, location)
Construct a lifetime from a persistence level and a location.
psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes, psa_key_type_t type, const uint8_t *data, size_t data_length)
Set domain parameters for a key.
uint64_t psa_key_slot_number_t
An internal designation of a key slot between the core part of the PSA Crypto implementation and the ...
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
#define PSA_KEY_LIFETIME_PERSISTENT
The default lifetime for persistent keys.
uint32_t psa_key_usage_t
Encoding of permitted usage on a key.
static void psa_set_key_algorithm(psa_key_attributes_t *attributes, psa_algorithm_t alg)
Declare the permitted algorithm policy for a key.
uint16_t psa_key_type_t
Encoding of a key type.
static psa_key_type_t psa_get_key_type(const psa_key_attributes_t *attributes)
Retrieve the key type from key attributes.
static psa_key_usage_t psa_get_key_usage_flags(const psa_key_attributes_t *attributes)
Retrieve the usage flags from key attributes.
static mbedtls_svc_key_id_t psa_get_key_id(const psa_key_attributes_t *attributes)
Retrieve the key identifier from key attributes.
uint32_t psa_key_lifetime_t
Encoding of key lifetimes.
unsigned int id
Unique ID indicating which driver got assigned to do the operation.
int32_t psa_status_t
Function return status.