6767#include "mbedtls/entropy.h"
6868#include "mbedtls/ctr_drbg.h"
6969
70+ /* TF-M ITS include */
71+ #include "psa/internal_trusted_storage.h"
72+
7073/* Default FreeRTOS API for console logging. */
7174#define DEV_MODE_KEY_PROVISIONING_PRINT ( X ) printf
7275
@@ -91,6 +94,9 @@ extern void vLoggingPrint( const char * pcFormat );
9194
9295#define DER_FORMAT_BUFFER_LENGTH 512
9396
97+ #define FIRST_BOOT_ITS_UID ( 1U )
98+ #define BOOT_PATTERN ( 0x55 )
99+
94100/* Adding one to all of the lengths because ASN1 may pad a leading 0 byte
95101 * to numbers that could be interpreted as negative */
96102typedef struct RsaParams_t
@@ -1443,4 +1449,39 @@ int xOtaProvisionCodeSigningKey( psa_key_handle_t * pxKeyHandle,
14431449 return result ;
14441450}
14451451
1452+ UBaseType_t uxIsDeviceProvisioned ( void )
1453+ {
1454+ psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
1455+ const psa_storage_uid_t uid = FIRST_BOOT_ITS_UID ;
1456+ uint8_t boot_pattern_in_its = 0 ;
1457+ size_t read_data_length = 0 ;
1458+
1459+ status = psa_its_get ( uid , 0 , 1 , & boot_pattern_in_its ,
1460+ & read_data_length );
1461+
1462+ if ( status != PSA_SUCCESS )
1463+ {
1464+ return 0 ;
1465+ }
1466+
1467+ if ( boot_pattern_in_its == BOOT_PATTERN )
1468+ {
1469+ return 1 ;
1470+ }
1471+ else
1472+ {
1473+ return 0 ;
1474+ }
1475+ }
1476+
1477+ psa_status_t xWriteDeviceProvisioned ( void )
1478+ {
1479+ const psa_storage_uid_t uid = FIRST_BOOT_ITS_UID ;
1480+ const psa_storage_create_flags_t flags = PSA_STORAGE_FLAG_WRITE_ONCE ;
1481+ uint8_t first_boot_pattern = BOOT_PATTERN ;
1482+
1483+ /* Write the pattern to ITS */
1484+ return psa_its_set ( uid , 1 , & first_boot_pattern , flags );
1485+ }
1486+
14461487/*-----------------------------------------------------------*/
0 commit comments