blob: 938abd07b89caf8bfa6f6b0c1260ddf2350af0e4 [file] [log] [blame]
Gilles Peskine9ef733f2018-02-07 21:05:37 +01001/**
2 * \file psa/crypto_struct.h
3 *
4 * \brief PSA cryptography module: Mbed TLS structured type implementations
Gilles Peskine07c91f52018-06-28 18:02:53 +02005 *
6 * \note This file may not be included directly. Applications must
7 * include psa/crypto.h.
8 *
9 * This file contains the definitions of some data structures with
10 * implementation-specific definitions.
11 *
12 * In implementations with isolation between the application and the
13 * cryptography module, it is expected that the front-end and the back-end
14 * would have different versions of this file.
Gilles Peskineb4e73e92019-08-13 15:00:57 +020015 *
16 * <h3>Design notes about multipart operation structures</h3>
17 *
18 * Each multipart operation structure contains a `psa_algorithm_t alg`
19 * field which indicates which specific algorithm the structure is for.
20 * When the structure is not in use, `alg` is 0. Most of the structure
21 * consists of a union which is discriminated by `alg`.
22 *
23 * Note that when `alg` is 0, the content of other fields is undefined.
24 * In particular, it is not guaranteed that a freshly-initialized structure
25 * is all-zero: we initialize structures to something like `{0, 0}`, which
26 * is only guaranteed to initializes the first member of the union;
27 * GCC and Clang initialize the whole structure to 0 (at the time of writing),
28 * but MSVC and CompCert don't.
29 *
30 * In Mbed Crypto, multipart operation structures live independently from
31 * the key. This allows Mbed Crypto to free the key objects when destroying
32 * a key slot. If a multipart operation needs to remember the key after
33 * the setup function returns, the operation structure needs to contain a
34 * copy of the key.
Gilles Peskine9ef733f2018-02-07 21:05:37 +010035 */
36/*
37 * Copyright (C) 2018, ARM Limited, All Rights Reserved
38 * SPDX-License-Identifier: Apache-2.0
39 *
40 * Licensed under the Apache License, Version 2.0 (the "License"); you may
41 * not use this file except in compliance with the License.
42 * You may obtain a copy of the License at
43 *
44 * http://www.apache.org/licenses/LICENSE-2.0
45 *
46 * Unless required by applicable law or agreed to in writing, software
47 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
48 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49 * See the License for the specific language governing permissions and
50 * limitations under the License.
51 *
52 * This file is part of mbed TLS (https://tls.mbed.org)
53 */
54
55#ifndef PSA_CRYPTO_STRUCT_H
56#define PSA_CRYPTO_STRUCT_H
57
Jaeden Amero8013f442019-08-16 16:13:51 +010058#ifdef __cplusplus
59extern "C" {
60#endif
61
Gilles Peskine9ef733f2018-02-07 21:05:37 +010062/* Include the Mbed TLS configuration file, the way Mbed TLS does it
63 * in each of its header files. */
64#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amerod58a00d2019-06-07 11:49:59 +010065#include "mbedtls/config.h"
Gilles Peskine9ef733f2018-02-07 21:05:37 +010066#else
67#include MBEDTLS_CONFIG_FILE
68#endif
69
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"
81
82struct psa_hash_operation_s
83{
84 psa_algorithm_t alg;
85 union
86 {
Gilles Peskine058e0b92018-03-22 16:20:19 +010087 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
Gilles Peskine9ef733f2018-02-07 21:05:37 +010088#if defined(MBEDTLS_MD2_C)
89 mbedtls_md2_context md2;
90#endif
91#if defined(MBEDTLS_MD4_C)
92 mbedtls_md4_context md4;
93#endif
94#if defined(MBEDTLS_MD5_C)
95 mbedtls_md5_context md5;
96#endif
97#if defined(MBEDTLS_RIPEMD160_C)
98 mbedtls_ripemd160_context ripemd160;
99#endif
100#if defined(MBEDTLS_SHA1_C)
101 mbedtls_sha1_context sha1;
102#endif
103#if defined(MBEDTLS_SHA256_C)
104 mbedtls_sha256_context sha256;
105#endif
106#if defined(MBEDTLS_SHA512_C)
107 mbedtls_sha512_context sha512;
108#endif
109 } ctx;
110};
111
Jaeden Amero6a25b412019-01-04 11:47:44 +0000112#define PSA_HASH_OPERATION_INIT {0, {0}}
113static inline struct psa_hash_operation_s psa_hash_operation_init( void )
114{
115 const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT;
116 return( v );
117}
118
Gilles Peskinea05219c2018-11-16 16:02:56 +0100119#if defined(MBEDTLS_MD_C)
Gilles Peskine2d277862018-06-18 15:41:12 +0200120typedef struct
121{
Nir Sonnenscheindcd636a2018-06-04 16:03:32 +0300122 /** The hash context. */
123 struct psa_hash_operation_s hash_ctx;
124 /** The HMAC part of the context. */
Gilles Peskineb3e6e5d2018-06-18 22:16:43 +0200125 uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
Nir Sonnenscheindcd636a2018-06-04 16:03:32 +0300126} psa_hmac_internal_data;
Gilles Peskinea05219c2018-11-16 16:02:56 +0100127#endif /* MBEDTLS_MD_C */
Nir Sonnenscheindcd636a2018-06-04 16:03:32 +0300128
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100129struct psa_mac_operation_s
130{
131 psa_algorithm_t alg;
Darryl Green80bed232018-07-26 13:03:38 +0100132 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;
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100137 uint8_t mac_size;
138 union
139 {
Gilles Peskine058e0b92018-03-22 16:20:19 +0100140 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100141#if defined(MBEDTLS_MD_C)
Nir Sonnenscheindcd636a2018-06-04 16:03:32 +0300142 psa_hmac_internal_data hmac;
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100143#endif
144#if defined(MBEDTLS_CMAC_C)
145 mbedtls_cipher_context_t cmac;
146#endif
147 } ctx;
148};
149
Jaeden Amero769ce272019-01-04 11:48:03 +0000150#define PSA_MAC_OPERATION_INIT {0, 0, 0, 0, 0, 0, 0, {0}}
151static inline struct psa_mac_operation_s psa_mac_operation_init( void )
152{
153 const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT;
154 return( v );
155}
156
Gilles Peskine428dc5a2018-03-03 21:27:18 +0100157struct psa_cipher_operation_s
158{
159 psa_algorithm_t alg;
Darryl Green80bed232018-07-26 13:03:38 +0100160 unsigned int key_set : 1;
161 unsigned int iv_required : 1;
162 unsigned int iv_set : 1;
Gilles Peskine428dc5a2018-03-03 21:27:18 +0100163 uint8_t iv_size;
164 uint8_t block_size;
165 union
166 {
Jaeden Amero5a5dc772019-01-04 15:33:37 +0000167 unsigned dummy; /* Enable easier initializing of the union. */
mohammad1603503973b2018-03-12 15:59:30 +0200168 mbedtls_cipher_context_t cipher;
Gilles Peskine428dc5a2018-03-03 21:27:18 +0100169 } ctx;
170};
171
Jaeden Amero5bae2272019-01-04 11:48:27 +0000172#define PSA_CIPHER_OPERATION_INIT {0, 0, 0, 0, 0, 0, {0}}
173static inline struct psa_cipher_operation_s psa_cipher_operation_init( void )
174{
175 const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT;
176 return( v );
177}
178
Gilles Peskine30a9e412019-01-14 18:36:12 +0100179struct psa_aead_operation_s
180{
181 psa_algorithm_t alg;
182 unsigned int key_set : 1;
183 unsigned int iv_set : 1;
184 uint8_t iv_size;
185 uint8_t block_size;
186 union
187 {
188 unsigned dummy; /* Enable easier initializing of the union. */
189 mbedtls_cipher_context_t cipher;
190 } ctx;
191};
192
193#define PSA_AEAD_OPERATION_INIT {0, 0, 0, 0, 0, {0}}
194static inline struct psa_aead_operation_s psa_aead_operation_init( void )
195{
196 const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT;
197 return( v );
198}
199
Gilles Peskinea05219c2018-11-16 16:02:56 +0100200#if defined(MBEDTLS_MD_C)
Gilles Peskinebef7f142018-07-12 17:22:21 +0200201typedef struct
202{
203 uint8_t *info;
204 size_t info_length;
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"
210#endif
211 uint8_t offset_in_block;
212 uint8_t block_number;
Gilles Peskine22c51512019-04-12 15:07:32 +0200213 unsigned int state : 2;
214 unsigned int info_set : 1;
Gilles Peskinecbe66502019-05-16 16:59:18 +0200215} psa_hkdf_key_derivation_t;
Gilles Peskinea05219c2018-11-16 16:02:56 +0100216#endif /* MBEDTLS_MD_C */
Gilles Peskinebef7f142018-07-12 17:22:21 +0200217
Gilles Peskinea05219c2018-11-16 16:02:56 +0100218#if defined(MBEDTLS_MD_C)
Janos Follath999f6482019-06-11 12:04:10 +0100219typedef enum
220{
221 TLS12_PRF_STATE_INIT, /* no input provided */
222 TLS12_PRF_STATE_SEED_SET, /* seed has been set */
223 TLS12_PRF_STATE_KEY_SET, /* key has been set */
224 TLS12_PRF_STATE_LABEL_SET, /* label has been set */
225 TLS12_PRF_STATE_OUTPUT /* output has been started */
226} psa_tls12_prf_key_derivation_state_t;
227
228typedef struct psa_tls12_prf_key_derivation_s
229{
230#if PSA_HASH_MAX_SIZE > 0xff
231#error "PSA_HASH_MAX_SIZE does not fit in uint8_t"
232#endif
233
234 /* Indicates how many bytes in the current HMAC block have
Janos Follath844eb0e2019-06-19 12:10:49 +0100235 * not yet been read by the user. */
236 uint8_t left_in_block;
Janos Follath999f6482019-06-11 12:04:10 +0100237
238 /* The 1-based number of the block. */
239 uint8_t block_number;
240
241 psa_tls12_prf_key_derivation_state_t state;
242
243 uint8_t *seed;
244 size_t seed_length;
245 uint8_t *label;
246 size_t label_length;
247 psa_hmac_internal_data hmac;
248 uint8_t Ai[PSA_HASH_MAX_SIZE];
249
250 /* `HMAC_hash( prk, A(i) + seed )` in the notation of RFC 5246, Sect. 5. */
251 uint8_t output_block[PSA_HASH_MAX_SIZE];
252} psa_tls12_prf_key_derivation_t;
Gilles Peskinea05219c2018-11-16 16:02:56 +0100253#endif /* MBEDTLS_MD_C */
Hanno Beckerc8a41d72018-10-09 17:33:01 +0100254
Gilles Peskinecbe66502019-05-16 16:59:18 +0200255struct psa_key_derivation_s
Gilles Peskineeab56e42018-07-12 17:12:33 +0200256{
257 psa_algorithm_t alg;
Gilles Peskine178c9aa2019-09-24 18:21:06 +0200258 unsigned int can_output_key : 1;
Gilles Peskineeab56e42018-07-12 17:12:33 +0200259 size_t capacity;
260 union
261 {
Janos Follathadbec812019-06-14 11:05:39 +0100262 /* Make the union non-empty even with no supported algorithms. */
263 uint8_t dummy;
Gilles Peskinebef7f142018-07-12 17:22:21 +0200264#if defined(MBEDTLS_MD_C)
Gilles Peskinecbe66502019-05-16 16:59:18 +0200265 psa_hkdf_key_derivation_t hkdf;
266 psa_tls12_prf_key_derivation_t tls12_prf;
Gilles Peskinebef7f142018-07-12 17:22:21 +0200267#endif
Gilles Peskineeab56e42018-07-12 17:12:33 +0200268 } ctx;
269};
270
Janos Follathadbec812019-06-14 11:05:39 +0100271/* This only zeroes out the first byte in the union, the rest is unspecified. */
Gilles Peskine178c9aa2019-09-24 18:21:06 +0200272#define PSA_KEY_DERIVATION_OPERATION_INIT {0, 0, 0, {0}}
Gilles Peskinecbe66502019-05-16 16:59:18 +0200273static inline struct psa_key_derivation_s psa_key_derivation_operation_init( void )
Gilles Peskineeab56e42018-07-12 17:12:33 +0200274{
Gilles Peskinecbe66502019-05-16 16:59:18 +0200275 const struct psa_key_derivation_s v = PSA_KEY_DERIVATION_OPERATION_INIT;
Gilles Peskineeab56e42018-07-12 17:12:33 +0200276 return( v );
277}
278
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100279struct psa_key_policy_s
280{
281 psa_key_usage_t usage;
282 psa_algorithm_t alg;
Gilles Peskine96f0b3b2019-05-10 19:33:38 +0200283 psa_algorithm_t alg2;
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100284};
Gilles Peskinea3dd7372019-04-19 19:42:26 +0200285typedef struct psa_key_policy_s psa_key_policy_t;
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100286
Gilles Peskine96f0b3b2019-05-10 19:33:38 +0200287#define PSA_KEY_POLICY_INIT {0, 0, 0}
Jaeden Amero70261c52019-01-04 11:47:20 +0000288static inline struct psa_key_policy_s psa_key_policy_init( void )
289{
290 const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT;
291 return( v );
292}
293
Gilles Peskine68cc433b2019-07-30 17:42:47 +0200294/* The type used internally for key sizes.
295 * Public interfaces use size_t, but internally we use a smaller type. */
296typedef uint16_t psa_key_bits_t;
297/* The maximum value of the type used to represent bit-sizes.
298 * This is used to mark an invalid key size. */
299#define PSA_KEY_BITS_TOO_LARGE ( (psa_key_bits_t) ( -1 ) )
Gilles Peskinec744d992019-07-30 17:26:54 +0200300/* The maximum size of a key in bits.
Gilles Peskine68cc433b2019-07-30 17:42:47 +0200301 * Currently defined as the maximum that can be represented, rounded down
302 * to a whole number of bytes.
303 * This is an uncast value so that it can be used in preprocessor
304 * conditionals. */
Gilles Peskinec744d992019-07-30 17:26:54 +0200305#define PSA_MAX_KEY_BITS 0xfff8
306
Gilles Peskine91e8c332019-08-02 19:19:39 +0200307/** A mask of flags that can be stored in key attributes.
308 *
309 * This type is also used internally to store flags in slots. Internal
310 * flags are defined in library/psa_crypto_core.h. Internal flags may have
311 * the same value as external flags if they are properly handled during
312 * key creation and in psa_get_key_attributes.
313 */
314typedef uint16_t psa_key_attributes_flag_t;
315
Gilles Peskinec8000c02019-08-02 20:15:51 +0200316#define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \
317 ( (psa_key_attributes_flag_t) 0x0001 )
Gilles Peskine91e8c332019-08-02 19:19:39 +0200318
319/* A mask of key attribute flags used externally only.
320 * Only meant for internal checks inside the library. */
321#define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \
Gilles Peskinec8000c02019-08-02 20:15:51 +0200322 MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \
Gilles Peskine91e8c332019-08-02 19:19:39 +0200323 0 )
324
325/* A mask of key attribute flags used both internally and externally.
326 * Currently there aren't any. */
327#define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \
328 0 )
329
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200330typedef struct
331{
332 psa_key_type_t type;
Gilles Peskinef65ed6f2019-12-04 17:18:41 +0100333 psa_key_bits_t bits;
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200334 psa_key_lifetime_t lifetime;
335 psa_key_id_t id;
336 psa_key_policy_t policy;
Gilles Peskine91e8c332019-08-02 19:19:39 +0200337 psa_key_attributes_flag_t flags;
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200338} psa_core_key_attributes_t;
339
Gilles Peskinef65ed6f2019-12-04 17:18:41 +0100340#define PSA_CORE_KEY_ATTRIBUTES_INIT {PSA_KEY_TYPE_NONE, 0, PSA_KEY_LIFETIME_VOLATILE, PSA_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0}
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200341
Gilles Peskine4747d192019-04-17 15:05:45 +0200342struct psa_key_attributes_s
343{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200344 psa_core_key_attributes_t core;
Gilles Peskinec8000c02019-08-02 20:15:51 +0200345#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
346 psa_key_slot_number_t slot_number;
347#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
Gilles Peskineb699f072019-04-26 16:06:02 +0200348 void *domain_parameters;
349 size_t domain_parameters_size;
Gilles Peskine4747d192019-04-17 15:05:45 +0200350};
351
Gilles Peskinec8000c02019-08-02 20:15:51 +0200352#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
353#define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0}
354#else
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200355#define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0}
Gilles Peskinec8000c02019-08-02 20:15:51 +0200356#endif
357
Gilles Peskine4747d192019-04-17 15:05:45 +0200358static inline struct psa_key_attributes_s psa_key_attributes_init( void )
359{
360 const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT;
361 return( v );
362}
363
Gilles Peskinedc8219a2019-05-15 16:11:15 +0200364static inline void psa_set_key_id(psa_key_attributes_t *attributes,
365 psa_key_id_t id)
366{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200367 attributes->core.id = id;
368 if( attributes->core.lifetime == PSA_KEY_LIFETIME_VOLATILE )
369 attributes->core.lifetime = PSA_KEY_LIFETIME_PERSISTENT;
Gilles Peskinedc8219a2019-05-15 16:11:15 +0200370}
371
Gilles Peskinedb4b3ab2019-04-18 12:53:01 +0200372static inline psa_key_id_t psa_get_key_id(
373 const psa_key_attributes_t *attributes)
374{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200375 return( attributes->core.id );
Gilles Peskinedb4b3ab2019-04-18 12:53:01 +0200376}
377
Gilles Peskinedc8219a2019-05-15 16:11:15 +0200378static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes,
379 psa_key_lifetime_t lifetime)
380{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200381 attributes->core.lifetime = lifetime;
Gilles Peskinedc8219a2019-05-15 16:11:15 +0200382 if( lifetime == PSA_KEY_LIFETIME_VOLATILE )
Jaeden Ameroe3cdf282019-08-20 12:58:20 +0100383 {
384#ifdef MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER
385 attributes->core.id.key_id = 0;
386 attributes->core.id.owner = 0;
387#else
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200388 attributes->core.id = 0;
Jaeden Ameroe3cdf282019-08-20 12:58:20 +0100389#endif
390 }
Gilles Peskinedc8219a2019-05-15 16:11:15 +0200391}
392
Gilles Peskinedb4b3ab2019-04-18 12:53:01 +0200393static inline psa_key_lifetime_t psa_get_key_lifetime(
394 const psa_key_attributes_t *attributes)
395{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200396 return( attributes->core.lifetime );
Gilles Peskinedb4b3ab2019-04-18 12:53:01 +0200397}
398
Gilles Peskine4747d192019-04-17 15:05:45 +0200399static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
400 psa_key_usage_t usage_flags)
401{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200402 attributes->core.policy.usage = usage_flags;
Gilles Peskine4747d192019-04-17 15:05:45 +0200403}
404
405static inline psa_key_usage_t psa_get_key_usage_flags(
406 const psa_key_attributes_t *attributes)
407{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200408 return( attributes->core.policy.usage );
Gilles Peskine4747d192019-04-17 15:05:45 +0200409}
410
411static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes,
412 psa_algorithm_t alg)
413{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200414 attributes->core.policy.alg = alg;
Gilles Peskine4747d192019-04-17 15:05:45 +0200415}
416
417static inline psa_algorithm_t psa_get_key_algorithm(
418 const psa_key_attributes_t *attributes)
419{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200420 return( attributes->core.policy.alg );
Gilles Peskine4747d192019-04-17 15:05:45 +0200421}
422
Gilles Peskine24f10f82019-05-16 12:18:32 +0200423/* This function is declared in crypto_extra.h, which comes after this
424 * header file, but we need the function here, so repeat the declaration. */
425psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes,
426 psa_key_type_t type,
427 const uint8_t *data,
428 size_t data_length);
429
Gilles Peskine4747d192019-04-17 15:05:45 +0200430static inline void psa_set_key_type(psa_key_attributes_t *attributes,
431 psa_key_type_t type)
432{
Gilles Peskineb699f072019-04-26 16:06:02 +0200433 if( attributes->domain_parameters == NULL )
434 {
435 /* Common case: quick path */
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200436 attributes->core.type = type;
Gilles Peskineb699f072019-04-26 16:06:02 +0200437 }
438 else
439 {
440 /* Call the bigger function to free the old domain paramteres.
441 * Ignore any errors which may arise due to type requiring
442 * non-default domain parameters, since this function can't
443 * report errors. */
444 (void) psa_set_key_domain_parameters( attributes, type, NULL, 0 );
445 }
Gilles Peskine4747d192019-04-17 15:05:45 +0200446}
447
448static inline psa_key_type_t psa_get_key_type(
449 const psa_key_attributes_t *attributes)
450{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200451 return( attributes->core.type );
Gilles Peskine4747d192019-04-17 15:05:45 +0200452}
453
Gilles Peskine3a4f1f82019-04-26 13:49:28 +0200454static inline void psa_set_key_bits(psa_key_attributes_t *attributes,
455 size_t bits)
456{
Gilles Peskine68cc433b2019-07-30 17:42:47 +0200457 if( bits > PSA_MAX_KEY_BITS )
458 attributes->core.bits = PSA_KEY_BITS_TOO_LARGE;
459 else
460 attributes->core.bits = (psa_key_bits_t) bits;
Gilles Peskine3a4f1f82019-04-26 13:49:28 +0200461}
462
Gilles Peskinedb4b3ab2019-04-18 12:53:01 +0200463static inline size_t psa_get_key_bits(
464 const psa_key_attributes_t *attributes)
465{
Gilles Peskine7e0cff92019-07-30 13:48:52 +0200466 return( attributes->core.bits );
Gilles Peskinedb4b3ab2019-04-18 12:53:01 +0200467}
468
Jaeden Amero8013f442019-08-16 16:13:51 +0100469#ifdef __cplusplus
470}
471#endif
472
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100473#endif /* PSA_CRYPTO_STRUCT_H */