-
Notifications
You must be signed in to change notification settings - Fork 0
/
chip_info.c
128 lines (100 loc) · 3.39 KB
/
chip_info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* gcc -I../cryptoauthlib/lib -L../cryptoauthlib/lib -lcryptoauth chip_info.c
*
*/
#include <string.h> // strlen
#include <stdio.h> // printf
#include "atca_config.h"
#include "cryptoauthlib.h"
#include "common.h"
int main(void) {
ATCA_STATUS status;
puts("Library symbols:");
printf(" ATCA_CA_SUPPORT: %d\n", ATCA_CA_SUPPORT);
printf(" ATCA_CA2_SUPPORT: %d\n", ATCA_CA2_SUPPORT);
printf(" ATCA_TA_SUPPORT: %d\n", ATCA_TA_SUPPORT);
#ifdef ATCA_ATECC608_SUPPORT
puts(" ATCA_ATECC608_SUPPORT");
#endif
// initialize CryptoAuthLib for an ECC default I2C interface
if (atcab_init(&cfg_atecc608_i2c) != ATCA_SUCCESS) {
printf("Init error\n");
exit(1);
}
// Device type
ATCADeviceType dev_type = atcab_get_device_type();
printf("Device type: 0x%02x\n", dev_type);
printf(" CA: %s\n", atcab_is_ca_device(dev_type) ? "yes" : "no");
printf(" CA2: %s\n", atcab_is_ca2_device(dev_type) ? "yes" : "no");
printf(" TA: %s\n", atcab_is_ta_device(dev_type) ? "yes" : "no");
// Zone sizes
puts("Sizes:");
size_t config_size;
bool config_locked;
atcab_get_zone_size(ATCA_ZONE_CONFIG, 0, &config_size);
atcab_is_config_locked(&config_locked);
printf(" Config: %d (locked: %s)\n", config_size, config_locked ? "yes" : "no");
size_t otp_size;
atcab_get_zone_size(ATCA_ZONE_OTP, 0, &otp_size);
printf(" OTP: %d\n", otp_size);
size_t data_size;
bool data_locked;
atcab_is_data_locked(&data_locked);
atcab_get_zone_size(ATCA_ZONE_DATA, 0, &data_size);
printf(" Data: %d (locked: %s)\n", data_size, data_locked ? "yes" : "no");
// Read config data
// 88 bytes for ATSHA devices, 128 bytes for ATECC devices and 48 bytes for Trust Anchor devices.
uint8_t config_data[128];
if (atcab_read_config_zone(config_data) != ATCA_SUCCESS) {
printf("Error reading config\n");
exit(1);
}
else {
uint8_t buffer[128*4];
size_t buffer_size = sizeof(buffer);
atcab_bin2hex(config_data, config_size, buffer, &buffer_size);
puts("");
puts("Config data:");
puts(buffer);
puts("");
}
// Serial number
uint8_t sn[ATCA_SERIAL_NUM_SIZE];
if ((status = atcab_read_serial_number(sn)) != ATCA_SUCCESS) {
printf("Error reading Serial Number: %d\n", status);
}
else {
printhex("SN", sn, ATCA_SERIAL_NUM_SIZE, "");
}
puts("");
// Value of counters
uint32_t counter_value = 0;
atcab_counter(0, 0, &counter_value);
printf("Counter 0: %6zu\n", counter_value);
atcab_counter(0, 1, &counter_value);
printf("Counter 1: %6zu\n", counter_value);
puts("");
// Try to read OTP
uint8_t otp_data[64];
if (atcab_read_bytes_zone(ATCA_ZONE_OTP, 0, 0, otp_data, 64) == ATCA_SUCCESS) {
printf("OTP Contents: ");
for(int i = 0; i < 64; i++) putchar(otp_data[i]);
puts("");
}
else {
puts("Cannot read OTP");
}
puts("");
// Try to read data slot contents
for (int i = 0; i <= 15; i++) {
printf("Slot %2d: ", i);
uint8_t slot_data[32];
if (atcab_read_bytes_zone(ATCA_ZONE_DATA, i, 0, slot_data, 32) == ATCA_SUCCESS) {
for(int i = 0; i < 32; i++) printf("%02x ", slot_data[i]);
puts("");
}
else {
puts("<secret>");
}
}
}