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" 86 #if defined(MBEDTLS_MD2_C) 87 mbedtls_md2_context md2;
89 #if defined(MBEDTLS_MD4_C) 90 mbedtls_md4_context md4;
92 #if defined(MBEDTLS_MD5_C) 93 mbedtls_md5_context
md5;
95 #if defined(MBEDTLS_RIPEMD160_C) 96 mbedtls_ripemd160_context ripemd160;
98 #if defined(MBEDTLS_SHA1_C) 99 mbedtls_sha1_context sha1;
101 #if defined(MBEDTLS_SHA256_C) 102 mbedtls_sha256_context sha256;
104 #if defined(MBEDTLS_SHA512_C) 105 mbedtls_sha512_context sha512;
110 #define PSA_HASH_OPERATION_INIT {0, {0}} 117 #if defined(MBEDTLS_MD_C) 123 uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
124 } psa_hmac_internal_data;
130 unsigned int key_set : 1;
131 unsigned int iv_required : 1;
132 unsigned int iv_set : 1;
133 unsigned int has_input : 1;
134 unsigned int is_sign : 1;
139 #if defined(MBEDTLS_MD_C) 140 psa_hmac_internal_data hmac;
142 #if defined(MBEDTLS_CMAC_C) 143 mbedtls_cipher_context_t cmac;
148 #define PSA_MAC_OPERATION_INIT {0, 0, 0, 0, 0, 0, 0, {0}} 158 unsigned int key_set : 1;
159 unsigned int iv_required : 1;
160 unsigned int iv_set : 1;
166 mbedtls_cipher_context_t cipher;
170 #define PSA_CIPHER_OPERATION_INIT {0, 0, 0, 0, 0, 0, {0}} 180 unsigned int key_set : 1;
181 unsigned int iv_set : 1;
187 mbedtls_cipher_context_t cipher;
191 #define PSA_AEAD_OPERATION_INIT {0, 0, 0, 0, 0, {0}} 198 #if defined(MBEDTLS_MD_C) 203 psa_hmac_internal_data hmac;
204 uint8_t prk[PSA_HASH_MAX_SIZE];
205 uint8_t output_block[PSA_HASH_MAX_SIZE];
206 #if PSA_HASH_MAX_SIZE > 0xff 207 #error "PSA_HASH_MAX_SIZE does not fit in uint8_t" 209 uint8_t offset_in_block;
210 uint8_t block_number;
211 unsigned int state : 2;
212 unsigned int info_set : 1;
213 } psa_hkdf_key_derivation_t;
216 #if defined(MBEDTLS_MD_C) 219 TLS12_PRF_STATE_INIT,
220 TLS12_PRF_STATE_SEED_SET,
221 TLS12_PRF_STATE_KEY_SET,
222 TLS12_PRF_STATE_LABEL_SET,
223 TLS12_PRF_STATE_OUTPUT
224 } psa_tls12_prf_key_derivation_state_t;
226 typedef struct psa_tls12_prf_key_derivation_s
228 #if PSA_HASH_MAX_SIZE > 0xff 229 #error "PSA_HASH_MAX_SIZE does not fit in uint8_t" 234 uint8_t left_in_block;
237 uint8_t block_number;
239 psa_tls12_prf_key_derivation_state_t state;
245 psa_hmac_internal_data hmac;
246 uint8_t Ai[PSA_HASH_MAX_SIZE];
249 uint8_t output_block[PSA_HASH_MAX_SIZE];
250 } psa_tls12_prf_key_derivation_t;
256 unsigned int can_output_key : 1;
262 #if defined(MBEDTLS_MD_C) 263 psa_hkdf_key_derivation_t hkdf;
264 psa_tls12_prf_key_derivation_t tls12_prf;
270 #define PSA_KEY_DERIVATION_OPERATION_INIT {0, 0, 0, {0}} 285 #define PSA_KEY_POLICY_INIT {0, 0, 0} 294 typedef uint16_t psa_key_bits_t;
297 #define PSA_KEY_BITS_TOO_LARGE ( (psa_key_bits_t) ( -1 ) ) 303 #define PSA_MAX_KEY_BITS 0xfff8 312 typedef uint16_t psa_key_attributes_flag_t;
314 #define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \ 315 ( (psa_key_attributes_flag_t) 0x0001 ) 319 #define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \ 320 MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \ 325 #define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \ 334 psa_key_policy_t policy;
335 psa_key_attributes_flag_t flags;
338 #define PSA_CORE_KEY_ATTRIBUTES_INIT {PSA_KEY_TYPE_NONE, 0, PSA_KEY_LIFETIME_VOLATILE, PSA_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0} 343 #if defined(MBEDTLS_PSA_CRYPTO_SE_C) 346 void *domain_parameters;
347 size_t domain_parameters_size;
350 #if defined(MBEDTLS_PSA_CRYPTO_SE_C) 351 #define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0} 353 #define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0} 365 attributes->core.id = id;
373 return( attributes->core.id );
379 attributes->core.lifetime = lifetime;
382 #ifdef MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER 383 attributes->core.id.key_id = 0;
384 attributes->core.id.owner = 0;
386 attributes->core.id = 0;
394 return( attributes->core.lifetime );
400 attributes->core.policy.usage = usage_flags;
406 return( attributes->core.policy.usage );
412 attributes->core.policy.alg = alg;
418 return( attributes->core.policy.alg );
431 if( attributes->domain_parameters == NULL )
434 attributes->core.type = type;
449 return( attributes->core.type );
455 if( bits > PSA_MAX_KEY_BITS )
456 attributes->core.bits = PSA_KEY_BITS_TOO_LARGE;
458 attributes->core.bits = (psa_key_bits_t) bits;
464 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
The default lifetime for volatile keys.
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 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.
uint32_t psa_key_lifetime_t
Encoding of key lifetimes.
int32_t psa_status_t
Function return status.