blob: 103c9bbb8ea4a7b4f3ba088f14a8852111ba7031 [file] [log] [blame]
Darryl Greendb2b8db2018-06-15 13:06:04 +01001/*
2 * PSA persistent key storage
3 */
Bence Szépkúti86974652020-06-15 11:59:37 +02004/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02005 * Copyright The Mbed TLS Contributors
Darryl Greendb2b8db2018-06-15 13:06:04 +01006 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
Darryl Greendb2b8db2018-06-15 13:06:04 +010019 */
20
21#if defined(MBEDTLS_CONFIG_FILE)
22#include MBEDTLS_CONFIG_FILE
23#else
24#include "mbedtls/config.h"
25#endif
26
27#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
28
29#include <stdlib.h>
30#include <string.h>
31
itayzafrir7723ab12019-02-14 10:28:02 +020032#include "psa_crypto_service_integration.h"
Darryl Greendb2b8db2018-06-15 13:06:04 +010033#include "psa/crypto.h"
34#include "psa_crypto_storage.h"
Darryl Greendb2b8db2018-06-15 13:06:04 +010035#include "mbedtls/platform_util.h"
36
Gilles Peskine5e80d912019-02-24 17:10:18 +010037#if defined(MBEDTLS_PSA_ITS_FILE_C)
38#include "psa_crypto_its.h"
39#else /* Native ITS implementation */
40#include "psa/error.h"
41#include "psa/internal_trusted_storage.h"
42#endif
43
Darryl Greendb2b8db2018-06-15 13:06:04 +010044#if defined(MBEDTLS_PLATFORM_C)
45#include "mbedtls/platform.h"
46#else
Jaeden Amerodb29ab52019-02-12 16:40:27 +000047#include <stdlib.h>
Darryl Greendb2b8db2018-06-15 13:06:04 +010048#define mbedtls_calloc calloc
49#define mbedtls_free free
50#endif
51
Gilles Peskinec8336cb2019-07-22 19:26:12 +020052
53
54/****************************************************************/
55/* Key storage */
56/****************************************************************/
57
Gilles Peskine088b77f2019-02-24 17:00:27 +010058/* Determine a file name (ITS file identifier) for the given key file
59 * identifier. The file name must be distinct from any file that is used
60 * for a purpose other than storing a key. Currently, the only such file
61 * is the random seed file whose name is PSA_CRYPTO_ITS_RANDOM_SEED_UID
62 * and whose value is 0xFFFFFF52. */
63static psa_storage_uid_t psa_its_identifier_of_slot( psa_key_file_id_t file_id )
64{
65#if defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER) && \
66 defined(PSA_CRYPTO_SECURE)
67 /* Encode the owner in the upper 32 bits. This means that if
68 * owner values are nonzero (as they are on a PSA platform),
69 * no key file will ever have a value less than 0x100000000, so
70 * the whole range 0..0xffffffff is available for non-key files. */
71 uint32_t unsigned_owner = (uint32_t) file_id.owner;
72 return( (uint64_t) unsigned_owner << 32 | file_id.key_id );
73#else
74 /* Use the key id directly as a file name.
75 * psa_is_key_file_id_valid() in psa_crypto_slot_management.c
76 * is responsible for ensuring that key identifiers do not have a
77 * value that is reserved for non-key files. */
78 return( file_id );
79#endif
80}
81
Gilles Peskine5e80d912019-02-24 17:10:18 +010082/**
83 * \brief Load persistent data for the given key slot number.
84 *
85 * This function reads data from a storage backend and returns the data in a
86 * buffer.
87 *
88 * \param key Persistent identifier of the key to be loaded. This
89 * should be an occupied storage location.
90 * \param[out] data Buffer where the data is to be written.
91 * \param data_size Size of the \c data buffer in bytes.
92 *
93 * \retval PSA_SUCCESS
94 * \retval PSA_ERROR_STORAGE_FAILURE
95 * \retval PSA_ERROR_DOES_NOT_EXIST
96 */
97static psa_status_t psa_crypto_storage_load( const psa_key_file_id_t key,
98 uint8_t *data,
99 size_t data_size )
Gilles Peskine088b77f2019-02-24 17:00:27 +0100100{
101 psa_status_t status;
102 psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
103 struct psa_storage_info_t data_identifier_info;
Simon D Hughesbda5a212019-07-10 16:34:21 +0100104 size_t data_length = 0;
Gilles Peskine088b77f2019-02-24 17:00:27 +0100105
106 status = psa_its_get_info( data_identifier, &data_identifier_info );
107 if( status != PSA_SUCCESS )
108 return( status );
109
Simon D Hughesbda5a212019-07-10 16:34:21 +0100110 status = psa_its_get( data_identifier, 0, (uint32_t) data_size, data, &data_length );
111 if( data_size != data_length )
112 return( PSA_ERROR_STORAGE_FAILURE );
Gilles Peskine088b77f2019-02-24 17:00:27 +0100113
114 return( status );
115}
116
117int psa_is_key_present_in_storage( const psa_key_file_id_t key )
118{
119 psa_status_t ret;
120 psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
121 struct psa_storage_info_t data_identifier_info;
122
123 ret = psa_its_get_info( data_identifier, &data_identifier_info );
124
125 if( ret == PSA_ERROR_DOES_NOT_EXIST )
126 return( 0 );
127 return( 1 );
128}
129
Gilles Peskine5e80d912019-02-24 17:10:18 +0100130/**
131 * \brief Store persistent data for the given key slot number.
132 *
133 * This function stores the given data buffer to a persistent storage.
134 *
135 * \param key Persistent identifier of the key to be stored. This
136 * should be an unoccupied storage location.
137 * \param[in] data Buffer containing the data to be stored.
138 * \param data_length The number of bytes
139 * that make up the data.
140 *
141 * \retval PSA_SUCCESS
142 * \retval PSA_ERROR_INSUFFICIENT_STORAGE
143 * \retval PSA_ERROR_STORAGE_FAILURE
144 * \retval PSA_ERROR_ALREADY_EXISTS
145 */
146static psa_status_t psa_crypto_storage_store( const psa_key_file_id_t key,
147 const uint8_t *data,
148 size_t data_length )
Gilles Peskine088b77f2019-02-24 17:00:27 +0100149{
150 psa_status_t status;
151 psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
152 struct psa_storage_info_t data_identifier_info;
153
154 if( psa_is_key_present_in_storage( key ) == 1 )
155 return( PSA_ERROR_ALREADY_EXISTS );
156
Gilles Peskinefad3a3e2019-02-25 13:36:21 +0100157 status = psa_its_set( data_identifier, (uint32_t) data_length, data, 0 );
Gilles Peskine088b77f2019-02-24 17:00:27 +0100158 if( status != PSA_SUCCESS )
159 {
160 return( PSA_ERROR_STORAGE_FAILURE );
161 }
162
163 status = psa_its_get_info( data_identifier, &data_identifier_info );
164 if( status != PSA_SUCCESS )
165 {
166 goto exit;
167 }
168
169 if( data_identifier_info.size != data_length )
170 {
171 status = PSA_ERROR_STORAGE_FAILURE;
172 goto exit;
173 }
174
175exit:
176 if( status != PSA_SUCCESS )
Gilles Peskine169ca7f2020-08-25 22:50:06 +0200177 {
178 /* Remove the file in case we managed to create it but something
179 * went wrong. It's ok if the file doesn't exist. If the file exists
180 * but the removal fails, we're already reporting an error so there's
181 * nothing else we can do. */
182 (void) psa_its_remove( data_identifier );
183 }
Gilles Peskine088b77f2019-02-24 17:00:27 +0100184 return( status );
185}
186
187psa_status_t psa_destroy_persistent_key( const psa_key_file_id_t key )
188{
189 psa_status_t ret;
190 psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
191 struct psa_storage_info_t data_identifier_info;
192
193 ret = psa_its_get_info( data_identifier, &data_identifier_info );
194 if( ret == PSA_ERROR_DOES_NOT_EXIST )
195 return( PSA_SUCCESS );
196
197 if( psa_its_remove( data_identifier ) != PSA_SUCCESS )
198 return( PSA_ERROR_STORAGE_FAILURE );
199
200 ret = psa_its_get_info( data_identifier, &data_identifier_info );
201 if( ret != PSA_ERROR_DOES_NOT_EXIST )
202 return( PSA_ERROR_STORAGE_FAILURE );
203
204 return( PSA_SUCCESS );
205}
206
Gilles Peskine5e80d912019-02-24 17:10:18 +0100207/**
208 * \brief Get data length for given key slot number.
209 *
210 * \param key Persistent identifier whose stored data length
211 * is to be obtained.
212 * \param[out] data_length The number of bytes that make up the data.
213 *
214 * \retval PSA_SUCCESS
215 * \retval PSA_ERROR_STORAGE_FAILURE
216 */
217static psa_status_t psa_crypto_storage_get_data_length(
218 const psa_key_file_id_t key,
219 size_t *data_length )
Gilles Peskine088b77f2019-02-24 17:00:27 +0100220{
221 psa_status_t status;
222 psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
223 struct psa_storage_info_t data_identifier_info;
224
225 status = psa_its_get_info( data_identifier, &data_identifier_info );
226 if( status != PSA_SUCCESS )
227 return( status );
228
229 *data_length = (size_t) data_identifier_info.size;
230
231 return( PSA_SUCCESS );
232}
233
Darryl Greendb2b8db2018-06-15 13:06:04 +0100234/*
235 * 32-bit integer manipulation macros (little endian)
236 */
237#ifndef GET_UINT32_LE
Gilles Peskine274a2632019-07-23 11:27:38 +0200238#define GET_UINT32_LE( n, b, i ) \
Darryl Greendb2b8db2018-06-15 13:06:04 +0100239{ \
240 (n) = ( (uint32_t) (b)[(i) ] ) \
241 | ( (uint32_t) (b)[(i) + 1] << 8 ) \
242 | ( (uint32_t) (b)[(i) + 2] << 16 ) \
243 | ( (uint32_t) (b)[(i) + 3] << 24 ); \
244}
245#endif
246
247#ifndef PUT_UINT32_LE
Gilles Peskine274a2632019-07-23 11:27:38 +0200248#define PUT_UINT32_LE( n, b, i ) \
Darryl Greendb2b8db2018-06-15 13:06:04 +0100249{ \
250 (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
251 (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
252 (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \
253 (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \
254}
255#endif
256
Moran Peker96ebf9e2018-06-28 18:02:17 +0300257/**
258 * Persistent key storage magic header.
259 */
260#define PSA_KEY_STORAGE_MAGIC_HEADER "PSA\0KEY"
261#define PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH ( sizeof( PSA_KEY_STORAGE_MAGIC_HEADER ) )
262
Darryl Greendb2b8db2018-06-15 13:06:04 +0100263typedef struct {
Moran Peker96ebf9e2018-06-28 18:02:17 +0300264 uint8_t magic[PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH];
Darryl Greendb2b8db2018-06-15 13:06:04 +0100265 uint8_t version[4];
Gilles Peskine0e8d4952019-07-23 14:46:52 +0200266 uint8_t lifetime[sizeof( psa_key_lifetime_t )];
Gilles Peskinef65ed6f2019-12-04 17:18:41 +0100267 uint8_t type[4]; /* Size=4 for a 2-byte type to keep the structure more
268 * regular and aligned and to make potential future
269 * extensibility easier. */
Darryl Greendb2b8db2018-06-15 13:06:04 +0100270 uint8_t policy[sizeof( psa_key_policy_t )];
271 uint8_t data_len[4];
272 uint8_t key_data[];
273} psa_persistent_key_storage_format;
274
275void psa_format_key_data_for_storage( const uint8_t *data,
276 const size_t data_length,
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200277 const psa_core_key_attributes_t *attr,
Darryl Greendb2b8db2018-06-15 13:06:04 +0100278 uint8_t *storage_data )
279{
280 psa_persistent_key_storage_format *storage_format =
281 (psa_persistent_key_storage_format *) storage_data;
282
Moran Peker96ebf9e2018-06-28 18:02:17 +0300283 memcpy( storage_format->magic, PSA_KEY_STORAGE_MAGIC_HEADER, PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH );
Gilles Peskine274a2632019-07-23 11:27:38 +0200284 PUT_UINT32_LE( 0, storage_format->version, 0 );
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200285 PUT_UINT32_LE( attr->lifetime, storage_format->lifetime, 0 );
Gilles Peskinef65ed6f2019-12-04 17:18:41 +0100286 PUT_UINT32_LE( (uint32_t) attr->type, storage_format->type, 0 );
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200287 PUT_UINT32_LE( attr->policy.usage, storage_format->policy, 0 );
288 PUT_UINT32_LE( attr->policy.alg, storage_format->policy, sizeof( uint32_t ) );
289 PUT_UINT32_LE( attr->policy.alg2, storage_format->policy, 2 * sizeof( uint32_t ) );
Gilles Peskine274a2632019-07-23 11:27:38 +0200290 PUT_UINT32_LE( data_length, storage_format->data_len, 0 );
Darryl Greendb2b8db2018-06-15 13:06:04 +0100291 memcpy( storage_format->key_data, data, data_length );
292}
293
Moran Peker96ebf9e2018-06-28 18:02:17 +0300294static psa_status_t check_magic_header( const uint8_t *data )
295{
296 if( memcmp( data, PSA_KEY_STORAGE_MAGIC_HEADER,
297 PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH ) != 0 )
298 return( PSA_ERROR_STORAGE_FAILURE );
299 return( PSA_SUCCESS );
300}
301
Darryl Greendb2b8db2018-06-15 13:06:04 +0100302psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data,
303 size_t storage_data_length,
304 uint8_t **key_data,
305 size_t *key_data_length,
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200306 psa_core_key_attributes_t *attr )
Darryl Greendb2b8db2018-06-15 13:06:04 +0100307{
Moran Peker96ebf9e2018-06-28 18:02:17 +0300308 psa_status_t status;
Darryl Greendb2b8db2018-06-15 13:06:04 +0100309 const psa_persistent_key_storage_format *storage_format =
310 (const psa_persistent_key_storage_format *)storage_data;
311 uint32_t version;
Gilles Peskinef65ed6f2019-12-04 17:18:41 +0100312 uint32_t type;
Darryl Greendb2b8db2018-06-15 13:06:04 +0100313
Moran Peker96ebf9e2018-06-28 18:02:17 +0300314 if( storage_data_length < sizeof(*storage_format) )
315 return( PSA_ERROR_STORAGE_FAILURE );
316
317 status = check_magic_header( storage_data );
318 if( status != PSA_SUCCESS )
319 return( status );
320
Gilles Peskine274a2632019-07-23 11:27:38 +0200321 GET_UINT32_LE( version, storage_format->version, 0 );
Darryl Greendb2b8db2018-06-15 13:06:04 +0100322 if( version != 0 )
323 return( PSA_ERROR_STORAGE_FAILURE );
324
Gilles Peskine274a2632019-07-23 11:27:38 +0200325 GET_UINT32_LE( *key_data_length, storage_format->data_len, 0 );
Darryl Greendb2b8db2018-06-15 13:06:04 +0100326 if( *key_data_length > ( storage_data_length - sizeof(*storage_format) ) ||
327 *key_data_length > PSA_CRYPTO_MAX_STORAGE_SIZE )
328 return( PSA_ERROR_STORAGE_FAILURE );
329
Gilles Peskine3495b582019-04-25 13:47:06 +0200330 if( *key_data_length == 0 )
331 {
332 *key_data = NULL;
333 }
334 else
335 {
336 *key_data = mbedtls_calloc( 1, *key_data_length );
337 if( *key_data == NULL )
338 return( PSA_ERROR_INSUFFICIENT_MEMORY );
339 memcpy( *key_data, storage_format->key_data, *key_data_length );
340 }
Darryl Greendb2b8db2018-06-15 13:06:04 +0100341
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200342 GET_UINT32_LE( attr->lifetime, storage_format->lifetime, 0 );
Gilles Peskinef65ed6f2019-12-04 17:18:41 +0100343 GET_UINT32_LE( type, storage_format->type, 0 );
344 if( type <= (psa_key_type_t) -1 )
345 attr->type = (psa_key_type_t) type;
346 else
347 return( PSA_ERROR_STORAGE_FAILURE );
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200348 GET_UINT32_LE( attr->policy.usage, storage_format->policy, 0 );
349 GET_UINT32_LE( attr->policy.alg, storage_format->policy, sizeof( uint32_t ) );
350 GET_UINT32_LE( attr->policy.alg2, storage_format->policy, 2 * sizeof( uint32_t ) );
Darryl Greendb2b8db2018-06-15 13:06:04 +0100351
Darryl Greendb2b8db2018-06-15 13:06:04 +0100352 return( PSA_SUCCESS );
353}
354
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200355psa_status_t psa_save_persistent_key( const psa_core_key_attributes_t *attr,
Darryl Greendb2b8db2018-06-15 13:06:04 +0100356 const uint8_t *data,
357 const size_t data_length )
358{
359 size_t storage_data_length;
360 uint8_t *storage_data;
361 psa_status_t status;
362
363 if( data_length > PSA_CRYPTO_MAX_STORAGE_SIZE )
364 return PSA_ERROR_INSUFFICIENT_STORAGE;
365 storage_data_length = data_length + sizeof( psa_persistent_key_storage_format );
366
367 storage_data = mbedtls_calloc( 1, storage_data_length );
368 if( storage_data == NULL )
369 return( PSA_ERROR_INSUFFICIENT_MEMORY );
370
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200371 psa_format_key_data_for_storage( data, data_length, attr, storage_data );
Darryl Greendb2b8db2018-06-15 13:06:04 +0100372
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200373 status = psa_crypto_storage_store( attr->id,
Darryl Greendb2b8db2018-06-15 13:06:04 +0100374 storage_data, storage_data_length );
375
376 mbedtls_free( storage_data );
377
378 return( status );
379}
380
381void psa_free_persistent_key_data( uint8_t *key_data, size_t key_data_length )
382{
383 if( key_data != NULL )
384 {
385 mbedtls_platform_zeroize( key_data, key_data_length );
386 }
387 mbedtls_free( key_data );
388}
389
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200390psa_status_t psa_load_persistent_key( psa_core_key_attributes_t *attr,
Darryl Greendb2b8db2018-06-15 13:06:04 +0100391 uint8_t **data,
392 size_t *data_length )
393{
394 psa_status_t status = PSA_SUCCESS;
395 uint8_t *loaded_data;
396 size_t storage_data_length = 0;
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200397 psa_key_id_t key = attr->id;
Darryl Greendb2b8db2018-06-15 13:06:04 +0100398
399 status = psa_crypto_storage_get_data_length( key, &storage_data_length );
400 if( status != PSA_SUCCESS )
401 return( status );
402
403 loaded_data = mbedtls_calloc( 1, storage_data_length );
404
405 if( loaded_data == NULL )
406 return( PSA_ERROR_INSUFFICIENT_MEMORY );
407
408 status = psa_crypto_storage_load( key, loaded_data, storage_data_length );
409 if( status != PSA_SUCCESS )
410 goto exit;
411
412 status = psa_parse_key_data_from_storage( loaded_data, storage_data_length,
Gilles Peskine4ed0e6f2019-07-30 20:22:33 +0200413 data, data_length, attr );
Darryl Greendb2b8db2018-06-15 13:06:04 +0100414
415exit:
416 mbedtls_free( loaded_data );
417 return( status );
418}
419
Gilles Peskinec8336cb2019-07-22 19:26:12 +0200420
421
422/****************************************************************/
423/* Transactions */
424/****************************************************************/
425
426#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
427
428psa_crypto_transaction_t psa_crypto_transaction;
429
430psa_status_t psa_crypto_save_transaction( void )
431{
432 struct psa_storage_info_t p_info;
433 psa_status_t status;
Jaeden Amero2ce22a52019-10-28 15:25:10 +0000434 status = psa_its_get_info( PSA_CRYPTO_ITS_TRANSACTION_UID, &p_info );
Gilles Peskinec8336cb2019-07-22 19:26:12 +0200435 if( status == PSA_SUCCESS )
436 {
437 /* This shouldn't happen: we're trying to start a transaction while
438 * there is still a transaction that hasn't been replayed. */
439 return( PSA_ERROR_CORRUPTION_DETECTED );
440 }
441 else if( status != PSA_ERROR_DOES_NOT_EXIST )
442 return( status );
443 return( psa_its_set( PSA_CRYPTO_ITS_TRANSACTION_UID,
444 sizeof( psa_crypto_transaction ),
445 &psa_crypto_transaction,
446 0 ) );
447}
448
449psa_status_t psa_crypto_load_transaction( void )
450{
Gilles Peskine8b663892019-07-31 17:57:57 +0200451 psa_status_t status;
452 size_t length;
453 status = psa_its_get( PSA_CRYPTO_ITS_TRANSACTION_UID, 0,
454 sizeof( psa_crypto_transaction ),
455 &psa_crypto_transaction, &length );
456 if( status != PSA_SUCCESS )
457 return( status );
458 if( length != sizeof( psa_crypto_transaction ) )
459 return( PSA_ERROR_STORAGE_FAILURE );
460 return( PSA_SUCCESS );
Gilles Peskinec8336cb2019-07-22 19:26:12 +0200461}
462
463psa_status_t psa_crypto_stop_transaction( void )
464{
465 psa_status_t status = psa_its_remove( PSA_CRYPTO_ITS_TRANSACTION_UID );
466 /* Whether or not updating the storage succeeded, the transaction is
467 * finished now. It's too late to go back, so zero out the in-memory
468 * data. */
469 memset( &psa_crypto_transaction, 0, sizeof( psa_crypto_transaction ) );
470 return( status );
471}
472
473#endif /* PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS */
474
475
476
477/****************************************************************/
478/* Random generator state */
479/****************************************************************/
480
Gilles Peskinee3dbdd82019-02-25 11:04:06 +0100481#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
482psa_status_t mbedtls_psa_storage_inject_entropy( const unsigned char *seed,
483 size_t seed_size )
484{
485 psa_status_t status;
486 struct psa_storage_info_t p_info;
487
488 status = psa_its_get_info( PSA_CRYPTO_ITS_RANDOM_SEED_UID, &p_info );
489
490 if( PSA_ERROR_DOES_NOT_EXIST == status ) /* No seed exists */
491 {
492 status = psa_its_set( PSA_CRYPTO_ITS_RANDOM_SEED_UID, seed_size, seed, 0 );
493 }
494 else if( PSA_SUCCESS == status )
495 {
496 /* You should not be here. Seed needs to be injected only once */
497 status = PSA_ERROR_NOT_PERMITTED;
498 }
499 return( status );
500}
501#endif /* MBEDTLS_PSA_INJECT_ENTROPY */
502
Gilles Peskinec8336cb2019-07-22 19:26:12 +0200503
504
505/****************************************************************/
506/* The end */
507/****************************************************************/
508
Darryl Greendb2b8db2018-06-15 13:06:04 +0100509#endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C */