35
35
// Must be 0 for the production firmware releases.
36
36
#define FACTORY_DURING_PROD 0
37
37
38
+ // When to do a sanity check of the expected metadata configuration. The check takes a while and
39
+ // causes a noticable delay at boot, so we don't enable it for production firmwares. We also enable
40
+ // it in debug builds.
41
+ #if FACTORYSETUP == 1 || FACTORY_DURING_PROD == 1 || !defined(NDEBUG )
42
+ #define VERIFY_METADATA 1
43
+ #else
44
+ #define VERIFY_METADATA 0
45
+ #endif
46
+
38
47
// Number of times the first kdf slot can be used over the lifetime of the device.
39
48
// The maxmimum does not seem to be specified, so we use something a little below the endurance
40
49
// indication of 600000 updates. See Solution Reference Manual Figure 32.
@@ -122,6 +131,7 @@ static const securechip_interface_functions_t* _ifs = NULL;
122
131
// During development, set this to `LCSO_STATE_CREATION`.
123
132
#define FINAL_LCSO_STATE LCSO_STATE_OPERATIONAL
124
133
134
+ #if FACTORYSETUP == 1 || FACTORY_DURING_PROD == 1 || VERIFY_METADATA == 1
125
135
static const uint8_t _platform_binding_metadata [] = {
126
136
// Metadata tag in the data object
127
137
0x20 ,
@@ -411,18 +421,6 @@ static const uint8_t _password_metadata[] = {
411
421
0x31 ,
412
422
};
413
423
414
- #if SMALL_MONOTONIC_COUNTER_MAX_USE > 255
415
- #error Max unlock attempts does not fit in one byte
416
- #endif
417
- // The intial/reset buffer for the small monotonic counter. Initial value: 0, threshold:
418
- // `SMALL_MONOTONIC_COUNTER_MAX_USE`. Table "Common data structures" -> "Counter":
419
- // https://github.com/Infineon/optiga-trust-m-overview/blob/98b2b9c178f0391b1ab26b52082899704dab688a/docs/OPTIGA%E2%84%A2%20Trust%20M%20Solution%20Reference%20Manual.md#link24b48059_db81_40f5_8b65_7afca4918ab1
420
- // Bytes 0-3 are the initial counter value, set to 0.
421
- // Bytes 4-7 are the threshold.
422
- // Ints are encoded as uint32 big endian.
423
- static const uint8_t _counter_password_reset_buf [8 ] =
424
- {0 , 0 , 0 , 0 , 0 , 0 , 0 , SMALL_MONOTONIC_COUNTER_MAX_USE };
425
-
426
424
static const uint8_t _counter_password_metadata [] = {
427
425
// Metadata tag in the data object
428
426
0x20 ,
@@ -455,6 +453,20 @@ static const uint8_t _counter_password_metadata[] = {
455
453
0x00 ,
456
454
};
457
455
456
+ #endif
457
+
458
+ #if SMALL_MONOTONIC_COUNTER_MAX_USE > 255
459
+ #error Max unlock attempts does not fit in one byte
460
+ #endif
461
+ // The intial/reset buffer for the small monotonic counter. Initial value: 0, threshold:
462
+ // `SMALL_MONOTONIC_COUNTER_MAX_USE`. Table "Common data structures" -> "Counter":
463
+ // https://github.com/Infineon/optiga-trust-m-overview/blob/98b2b9c178f0391b1ab26b52082899704dab688a/docs/OPTIGA%E2%84%A2%20Trust%20M%20Solution%20Reference%20Manual.md#link24b48059_db81_40f5_8b65_7afca4918ab1
464
+ // Bytes 0-3 are the initial counter value, set to 0.
465
+ // Bytes 4-7 are the threshold.
466
+ // Ints are encoded as uint32 big endian.
467
+ static const uint8_t _counter_password_reset_buf [8 ] =
468
+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , SMALL_MONOTONIC_COUNTER_MAX_USE };
469
+
458
470
//
459
471
// Sync wrappers around optiga util/crypt functions
460
472
//
@@ -517,6 +529,7 @@ static optiga_lib_status_t _optiga_util_write_data_sync(
517
529
return res ;
518
530
}
519
531
532
+ #if FACTORYSETUP == 1 || FACTORY_DURING_PROD == 1 || VERIFY_METADATA == 1
520
533
static optiga_lib_status_t _optiga_util_read_metadata_sync (
521
534
optiga_util_t * me ,
522
535
uint16_t optiga_oid ,
@@ -528,6 +541,7 @@ static optiga_lib_status_t _optiga_util_read_metadata_sync(
528
541
_WAIT (res , _optiga_lib_status );
529
542
return res ;
530
543
}
544
+ #endif
531
545
532
546
#if FACTORYSETUP == 1 || FACTORY_DURING_PROD == 1
533
547
static optiga_lib_status_t _optiga_util_write_metadata_sync (
@@ -781,6 +795,7 @@ static int _write_arbitrary_data(const arbitrary_data_t* data)
781
795
}
782
796
#endif
783
797
798
+ #if VERIFY_METADATA == 1
784
799
// In a metadata object (0x20 <len> <tag> <tag len> <tag data> ...),
785
800
// extract tag data for a specific tag.
786
801
// Returns false if the metadata is invalid or the tag is not present, or if the tag data is larger
@@ -834,6 +849,7 @@ static bool _read_metadata_tag(
834
849
// Tag not found
835
850
return false;
836
851
}
852
+ #endif
837
853
838
854
#if FACTORYSETUP == 1 || FACTORY_DURING_PROD == 1
839
855
// Read the LcsO status from a metadata object. Returns false if the metadata is invalid or LcsO is
@@ -1212,6 +1228,7 @@ static int _factory_setup(void)
1212
1228
}
1213
1229
#endif // FACTORYSETUP == 1 || FACTORY_DURING_PROD == 1
1214
1230
1231
+ #if VERIFY_METADATA == 1
1215
1232
static int _verify_metadata (
1216
1233
uint16_t oid ,
1217
1234
const uint8_t * expected_metadata ,
@@ -1257,6 +1274,7 @@ static int _verify_metadata(
1257
1274
}
1258
1275
return 0 ;
1259
1276
}
1277
+ #endif
1260
1278
1261
1279
static int _set_password (
1262
1280
const uint8_t * password_secret ,
@@ -1443,8 +1461,8 @@ static int _verify_config(void)
1443
1461
return res ;
1444
1462
}
1445
1463
1464
+ #if VERIFY_METADATA == 1
1446
1465
// Verify metadata tags are setup as expected.
1447
-
1448
1466
{
1449
1467
const uint8_t check_tags [] = {0xC0 , 0xD0 , 0xD1 , 0xD3 , 0xE8 };
1450
1468
res = _verify_metadata (
@@ -1558,7 +1576,7 @@ static int _verify_config(void)
1558
1576
return res ;
1559
1577
}
1560
1578
}
1561
-
1579
+ #endif
1562
1580
return 0 ;
1563
1581
}
1564
1582
0 commit comments