55 #ifndef PSA_CRYPTO_STRUCT_H 56 #define PSA_CRYPTO_STRUCT_H 64 #if !defined(MBEDTLS_CONFIG_FILE) 65 #include "mbedtls/config.h" 67 #include MBEDTLS_CONFIG_FILE 70 #include "mbedtls/cipher.h" 71 #include "mbedtls/cmac.h" 72 #include "mbedtls/gcm.h" 73 #include "mbedtls/md.h" 74 #include "mbedtls/md2.h" 75 #include "mbedtls/md4.h" 76 #include "mbedtls/md5.h" 77 #include "mbedtls/ripemd160.h" 78 #include "mbedtls/sha1.h" 79 #include "mbedtls/sha256.h" 80 #include "mbedtls/sha512.h" 88 #if defined(MBEDTLS_MD2_C) 89 mbedtls_md2_context md2;
91 #if defined(MBEDTLS_MD4_C) 92 mbedtls_md4_context md4;
94 #if defined(MBEDTLS_MD5_C) 95 mbedtls_md5_context
md5;
97 #if defined(MBEDTLS_RIPEMD160_C) 98 mbedtls_ripemd160_context ripemd160;
100 #if defined(MBEDTLS_SHA1_C) 101 mbedtls_sha1_context sha1;
103 #if defined(MBEDTLS_SHA256_C) 104 mbedtls_sha256_context sha256;
106 #if defined(MBEDTLS_SHA512_C) 107 mbedtls_sha512_context sha512;
112 #define PSA_HASH_OPERATION_INIT {0, {0}} 119 #if defined(MBEDTLS_MD_C) 125 uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
126 } psa_hmac_internal_data;
132 unsigned int key_set : 1;
133 unsigned int iv_required : 1;
134 unsigned int iv_set : 1;
135 unsigned int has_input : 1;
136 unsigned int is_sign : 1;
141 #if defined(MBEDTLS_MD_C) 142 psa_hmac_internal_data hmac;
144 #if defined(MBEDTLS_CMAC_C) 145 mbedtls_cipher_context_t cmac;
150 #define PSA_MAC_OPERATION_INIT {0, 0, 0, 0, 0, 0, 0, {0}} 160 unsigned int key_set : 1;
161 unsigned int iv_required : 1;
162 unsigned int iv_set : 1;
168 mbedtls_cipher_context_t cipher;
172 #define PSA_CIPHER_OPERATION_INIT {0, 0, 0, 0, 0, 0, {0}} 182 unsigned int key_set : 1;
183 unsigned int iv_set : 1;
189 mbedtls_cipher_context_t cipher;
193 #define PSA_AEAD_OPERATION_INIT {0, 0, 0, 0, 0, {0}} 200 #if defined(MBEDTLS_MD_C) 205 psa_hmac_internal_data hmac;
206 uint8_t prk[PSA_HASH_MAX_SIZE];
207 uint8_t output_block[PSA_HASH_MAX_SIZE];
208 #if PSA_HASH_MAX_SIZE > 0xff 209 #error "PSA_HASH_MAX_SIZE does not fit in uint8_t" 211 uint8_t offset_in_block;
212 uint8_t block_number;
213 unsigned int state : 2;
214 unsigned int info_set : 1;
215 } psa_hkdf_key_derivation_t;
218 #if defined(MBEDTLS_MD_C) 221 TLS12_PRF_STATE_INIT,
222 TLS12_PRF_STATE_SEED_SET,
223 TLS12_PRF_STATE_KEY_SET,
224 TLS12_PRF_STATE_LABEL_SET,
225 TLS12_PRF_STATE_OUTPUT
226 } psa_tls12_prf_key_derivation_state_t;
228 typedef struct psa_tls12_prf_key_derivation_s
230 #if PSA_HASH_MAX_SIZE > 0xff 231 #error "PSA_HASH_MAX_SIZE does not fit in uint8_t" 236 uint8_t left_in_block;
239 uint8_t block_number;
241 psa_tls12_prf_key_derivation_state_t state;
247 psa_hmac_internal_data hmac;
248 uint8_t Ai[PSA_HASH_MAX_SIZE];
251 uint8_t output_block[PSA_HASH_MAX_SIZE];
252 } psa_tls12_prf_key_derivation_t;
258 unsigned int can_output_key : 1;
264 #if defined(MBEDTLS_MD_C) 265 psa_hkdf_key_derivation_t hkdf;
266 psa_tls12_prf_key_derivation_t tls12_prf;
272 #define PSA_KEY_DERIVATION_OPERATION_INIT {0, 0, 0, {0}} 287 #define PSA_KEY_POLICY_INIT {0, 0, 0} 296 typedef uint16_t psa_key_bits_t;
299 #define PSA_KEY_BITS_TOO_LARGE ( (psa_key_bits_t) ( -1 ) ) 305 #define PSA_MAX_KEY_BITS 0xfff8 314 typedef uint16_t psa_key_attributes_flag_t;
316 #define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \ 317 ( (psa_key_attributes_flag_t) 0x0001 ) 321 #define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \ 322 MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \ 327 #define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \ 336 psa_key_policy_t policy;
337 psa_key_attributes_flag_t flags;
340 #define PSA_CORE_KEY_ATTRIBUTES_INIT {PSA_KEY_TYPE_NONE, 0, PSA_KEY_LIFETIME_VOLATILE, PSA_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0} 345 #if defined(MBEDTLS_PSA_CRYPTO_SE_C) 348 void *domain_parameters;
349 size_t domain_parameters_size;
352 #if defined(MBEDTLS_PSA_CRYPTO_SE_C) 353 #define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0} 355 #define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0} 367 attributes->core.id = id;
375 return( attributes->core.id );
381 attributes->core.lifetime = lifetime;
384 #ifdef MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER 385 attributes->core.id.key_id = 0;
386 attributes->core.id.owner = 0;
388 attributes->core.id = 0;
396 return( attributes->core.lifetime );
402 attributes->core.policy.usage = usage_flags;
408 return( attributes->core.policy.usage );
414 attributes->core.policy.alg = alg;
420 return( attributes->core.policy.alg );
433 if( attributes->domain_parameters == NULL )
436 attributes->core.type = type;
451 return( attributes->core.type );
457 if( bits > PSA_MAX_KEY_BITS )
458 attributes->core.bits = PSA_KEY_BITS_TOO_LARGE;
460 attributes->core.bits = (psa_key_bits_t) bits;
466 return( attributes->core.bits );
static void psa_set_key_id(psa_key_attributes_t *attributes, psa_key_id_t id)
Declare a key as persistent and set its key identifier.
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 )
#define PSA_KEY_LIFETIME_VOLATILE
A volatile key only exists as long as the handle to it is not closed.
uint32_t psa_key_id_t
Encoding of identifiers of persistent keys.
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.
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 psa_key_id_t psa_get_key_id(const psa_key_attributes_t *attributes)
Retrieve the key identifier from key attributes.
static size_t psa_get_key_bits(const psa_key_attributes_t *attributes)
Retrieve the key size from key attributes.
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 storage area 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.
uint32_t psa_key_lifetime_t
Encoding of key lifetimes.
int32_t psa_status_t
Function return status.