@@ -29,8 +29,7 @@ psa_status_t atecc608a_get_serial_number(uint8_t *buffer,
29
29
{
30
30
psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
31
31
32
- if (buffer_size < ATCA_SERIAL_NUM_SIZE )
33
- {
32
+ if (buffer_size < ATCA_SERIAL_NUM_SIZE ) {
34
33
return PSA_ERROR_BUFFER_TOO_SMALL ;
35
34
}
36
35
@@ -44,35 +43,52 @@ psa_status_t atecc608a_get_serial_number(uint8_t *buffer,
44
43
return status ;
45
44
}
46
45
47
- psa_status_t atecc608a_check_config_locked ( )
46
+ psa_status_t atecc608a_check_zone_locked ( uint8_t zone )
48
47
{
49
- bool config_locked ;
48
+ bool zone_locked ;
50
49
psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
51
50
52
51
ASSERT_SUCCESS_PSA (atecc608a_init ());
53
52
54
- ASSERT_SUCCESS (atcab_is_locked (LOCK_ZONE_CONFIG , & config_locked ));
53
+ ASSERT_SUCCESS (atcab_is_locked (zone , & zone_locked ));
55
54
56
55
exit :
57
56
atecc608a_deinit ();
58
- if (status == PSA_SUCCESS )
59
- {
60
- status = config_locked ? PSA_SUCCESS : PSA_ERROR_HARDWARE_FAILURE ;
57
+ if (status == PSA_SUCCESS ) {
58
+ status = zone_locked ? PSA_SUCCESS : PSA_ERROR_HARDWARE_FAILURE ;
61
59
}
62
60
return status ;
63
61
}
64
62
63
+ psa_status_t atecc608a_lock_data_zone ()
64
+ {
65
+ psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
66
+ bool zone_locked ;
67
+
68
+ ASSERT_SUCCESS_PSA (atecc608a_init ());
69
+ /* atcab_is_locked used instead of atecc608a_check_zone_locked as an
70
+ * optimization - this way atecc608a_init won't be called again. */
71
+ ASSERT_SUCCESS (atcab_is_locked (LOCK_ZONE_DATA , & zone_locked ));
72
+ if (zone_locked ) {
73
+ status = PSA_ERROR_HARDWARE_FAILURE ;
74
+ goto exit ;
75
+ }
76
+ ASSERT_SUCCESS (atcab_lock_data_zone ());
77
+
78
+ exit :
79
+ atecc608a_deinit ();
80
+ return status ;
81
+ }
82
+
65
83
psa_status_t atecc608a_random_32_bytes (uint8_t * rand_out , size_t buffer_size )
66
84
{
67
85
psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
68
86
69
- if (rand_out == NULL )
70
- {
87
+ if (rand_out == NULL ) {
71
88
return PSA_ERROR_INVALID_ARGUMENT ;
72
89
}
73
90
74
- if (buffer_size < 32 )
75
- {
91
+ if (buffer_size < 32 ) {
76
92
return PSA_ERROR_BUFFER_TOO_SMALL ;
77
93
}
78
94
0 commit comments