38 #include "sha204_library.h"
47 #define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
50 #define MY_AES_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
53 #define MY_SOFT_SERIAL 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
198 #ifdef GENERATE_KEYS_ATSHA204A
199 #define LOCK_ATSHA204A_CONFIGURATION // We have to lock configuration to enable random number generation
200 #define GENERATE_HMAC_KEY // Generate random HMAC key
201 #define GENERATE_AES_KEY // Generate random AES key
202 #define SKIP_UART_CONFIRMATION // This is an automated mode
205 #ifdef GENERATE_KEYS_SOFT
206 #define USE_SOFT_SIGNING // Use software backend
207 #define GENERATE_HMAC_KEY // Generate random HMAC key
208 #define GENERATE_AES_KEY // Generate random AES key
209 #define SKIP_UART_CONFIRMATION // This is an automated mode
212 #ifdef PERSONALIZE_ATSHA204A
213 #define LOCK_ATSHA204A_CONFIGURATION // We have to lock configuration to enable random number generation
214 #define STORE_HMAC_KEY // Store the HMAC key
215 #define STORE_AES_KEY // Store the AES key
216 #define SKIP_UART_CONFIRMATION // This is an automated mode
219 #ifdef PERSONALIZE_SOFT_RANDOM_SERIAL
220 #define GENERATE_SOFT_SERIAL // Generate a soft serial number
221 #define PERSONALIZE_SOFT // Do the rest as PERSONALIZE_SOFT
224 #ifdef PERSONALIZE_SOFT
225 #define USE_SOFT_SIGNING // Use software backend
226 #define STORE_HMAC_KEY // Store the HMAC key
227 #define STORE_AES_KEY // Store the AES key
228 #define STORE_SOFT_SERIAL // Store the soft serial number
229 #define SKIP_UART_CONFIRMATION // This is an automated mode
232 #if defined(GENERATE_HMAC_KEY) || defined(GENERATE_AES_KEY) || defined(GENERATE_SOFT_SERIAL)
233 #define GENERATE_SOMETHING
236 #if defined(MY_LOCK_MCU)
237 #undefine MY_LOCK_MCU // The Sketch after SecurityPersonaliter should lock the MCU
241 #if defined(GENERATE_SOFT_SERIAL) && !defined(USE_SOFT_SIGNING)
242 #error Cannot generate soft serial using ATSHA204A, use USE_SOFT_SINGING for this
244 #if defined(STORE_SOFT_SERIAL) && !defined(USE_SOFT_SIGNING)
245 #error Cannot store soft serial to ATSHA204A, use USE_SOFT_SINGING for this
247 #if defined(PRINT_DETAILED_ATSHA204A_CONFIG) && defined(USE_SOFT_SIGNING)
248 #error Cannot print ATSHA204A config using software signing flag, disable USE_SOFT_SINGING for this
250 #if defined(LOCK_ATSHA204A_CONFIGURATION) && defined(USE_SOFT_SIGNING)
251 #error Cannot lock ATSHA204A config using software signing flag, disable USE_SOFT_SINGING for this
253 #ifdef GENERATE_KEYS_ATSHA204A
254 #ifdef USE_SOFT_SIGNING
255 #error You cannot select soft signing if you want to generate keys using ATSHA204A
257 #ifdef STORE_HMAC_KEY
258 #error Disable STORE_SOFT_KEY, you should not store keys in this mode
260 #ifdef STORE_SOFT_SERIAL
261 #error Disable STORE_SOFT_SERIAL, you should not store serial in this mode
264 #error Disable STORE_AES_KEY, you should not store keys in this mode
266 #if defined(GENERATE_KEYS_SOFT) ||\
267 defined (PERSONALIZE_ATSHA204A) ||\
268 defined (PERSONALIZE_SOFT) ||\
269 defined (PERSONALIZE_SOFT_RANDOM_SERIAL)
270 #error You can not enable GENERATE_KEYS_ATSHA204A together with other guided modes
272 #endif // GENERATE_KEYS_ATSHA204A
273 #ifdef GENERATE_KEYS_SOFT
274 #ifdef STORE_HMAC_KEY
275 #error Disable STORE_SOFT_KEY, you should not store keys in this mode
277 #ifdef STORE_SOFT_SERIAL
278 #error Disable STORE_SOFT_SERIAL, you should not store serial in this mode
281 #error Disable STORE_AES_KEY, you should not store keys in this mode
283 #ifndef MY_SIGNING_SOFT_RANDOMSEED_PIN
284 #error You have to set MY_SIGNING_SOFT_RANDOMSEED_PIN to a suitable value in this mode
286 #if defined(GENERATE_KEYS_ATSHA204A) ||\
287 defined (PERSONALIZE_ATSHA204A) ||\
288 defined (PERSONALIZE_SOFT) ||\
289 defined (PERSONALIZE_SOFT_RANDOM_SERIAL)
290 #error You can not enable GENERATE_KEYS_SOFT together with other guided modes
292 #endif // GENERATE_KEYS_SOFT
293 #ifdef PERSONALIZE_ATSHA204A
294 #ifdef USE_SOFT_SIGNING
295 #error You cannot select soft signing if you want to personalize an ATSHA204A
297 #if defined(GENERATE_KEYS_ATSHA204A) ||\
298 defined (GENERATE_KEYS_SOFT) ||\
299 defined (PERSONALIZE_SOFT) ||\
300 defined (PERSONALIZE_SOFT_RANDOM_SERIAL)
301 #error You can not enable PERSONALIZE_ATSHA204A together with other guided modes
303 #ifdef RESET_EEPROM_PERSONALIZATION
304 #error You cannot reset EEPROM personalization when personalizing a device
306 #endif // PERSONALIZE_ATSHA204A
307 #ifdef PERSONALIZE_SOFT
308 #if defined(GENERATE_KEYS_ATSHA204A) ||\
309 defined (GENERATE_KEYS_SOFT) ||\
310 defined (PERSONALIZE_ATSHA204A)
311 #error You can not enable PERSONALIZE_SOFT together with other guided modes
313 #ifdef RESET_EEPROM_PERSONALIZATION
314 #error You cannot reset EEPROM personalization when personalizing a device
316 #endif // PERSONALIZE_SOFT
317 #ifdef PERSONALIZE_SOFT_RANDOM_SERIAL
318 #if defined(GENERATE_KEYS_SOFT) ||\
319 defined (PERSONALIZE_ATSHA204A) ||\
320 defined (GENERATE_KEYS_ATSHA204A)
321 #error You can only enable one of the guided modes at a time
323 #ifdef RESET_EEPROM_PERSONALIZATION
324 #error You cannot reset EEPROM personalization when personalizing a device
326 #endif // PERSONALIZE_SOFT_RANDOM_SERIAL
328 #if !defined(GENERATE_KEYS_ATSHA204A) &&\
329 !defined(GENERATE_KEYS_SOFT) &&\
330 !defined(PERSONALIZE_ATSHA204A) &&\
331 !defined(PERSONALIZE_SOFT) &&\
332 !defined(PERSONALIZE_SOFT_RANDOM_SERIAL) &&\
333 !defined(USE_SOFT_SIGNING) &&\
334 !defined(LOCK_ATSHA204A_CONFIGURATION) &&\
335 !defined(SKIP_UART_CONFIRMATION) &&\
336 !defined(GENERATE_HMAC_KEY) &&\
337 !defined(STORE_HMAC_KEY) &&\
338 !defined(GENERATE_SOFT_SERIAL) &&\
339 !defined(STORE_SOFT_SERIAL) &&\
340 !defined(GENERATE_AES_KEY) &&\
341 !defined(STORE_AES_KEY) &&\
342 !defined(PRINT_DETAILED_ATSHA204A_CONFIG) &&\
343 !defined(RESET_EEPROM_PERSONALIZATION)
345 #define NO_SETTINGS_DEFINED
348 #if defined(GENERATE_KEYS_ATSHA204A) ||\
349 defined(GENERATE_KEYS_SOFT) ||\
350 defined(PERSONALIZE_ATSHA204A) ||\
351 defined(PERSONALIZE_SOFT) ||\
352 defined(PERSONALIZE_SOFT_RANDOM_SERIAL)
358 static void halt(
bool success);
359 #ifdef GENERATE_SOMETHING
360 static bool generate_random_data(uint8_t*
data,
size_t sz);
362 static void generate_keys(
void);
363 static void store_keys(
void);
364 static void print_hex_buffer(uint8_t*
data,
size_t sz);
365 static void print_c_friendly_hex_buffer(uint8_t*
data,
size_t sz);
366 #ifdef STORE_HMAC_KEY
367 static bool store_hmac_key_data(uint8_t*
data,
size_t sz);
370 static bool store_aes_key_data(uint8_t*
data,
size_t sz);
372 #ifdef STORE_SOFT_SERIAL
373 static bool store_soft_serial_data(uint8_t*
data,
size_t sz);
375 #ifndef USE_SOFT_SIGNING
376 static void init_atsha204a_state(
void);
377 #ifdef LOCK_ATSHA204A_CONFIGURATION
378 static void lock_atsha204a_config(
void);
379 static uint16_t write_atsha204a_config_and_get_crc(
void);
381 static bool get_atsha204a_serial(uint8_t*
data);
382 #ifdef STORE_HMAC_KEY
383 static bool write_atsha204a_key(uint8_t* key);
385 #endif // not USE_SOFT_SIGNING
386 static void print_greeting(
void);
387 static void print_ending(
void);
388 static void probe_and_print_peripherals(
void);
389 static void print_eeprom_data(
void);
390 static void print_whitelisting_entry(
void);
391 #ifdef PRINT_DETAILED_ATSHA204A_CONFIG
392 static void dump_detailed_atsha204a_configuration(
void);
394 #ifdef RESET_EEPROM_PERSONALIZATION
395 static void reset_eeprom(
void);
397 static void write_eeprom_checksum(
void);
400 #if defined(GENERATE_HMAC_KEY) || defined(STORE_HMAC_KEY)
405 #if defined(GENERATE_SOFT_SERIAL) || defined(STORE_SOFT_SERIAL)
410 #if defined(GENERATE_AES_KEY) || defined(STORE_AES_KEY)
412 static uint8_t user_aes_key[16] = {
MY_AES_KEY};
415 #ifndef USE_SOFT_SIGNING
418 static uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
419 static uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
420 static uint8_t ret_code;
421 static uint8_t lockConfig = 0;
422 static uint8_t lockValue = 0;
424 static bool has_device_unique_id =
false;
425 static const uint8_t reset_buffer[32] = {
426 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
427 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
428 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
429 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
438 uint32_t enter = hwMillis();
439 while (hwMillis() - enter < (uint32_t)500);
440 #ifdef USE_SOFT_SIGNING
442 hwRandomNumberInit();
449 #ifndef USE_SOFT_SIGNING
450 init_atsha204a_state();
452 #ifdef LOCK_ATSHA204A_CONFIGURATION
453 lock_atsha204a_config();
459 #ifdef RESET_EEPROM_PERSONALIZATION
468 write_eeprom_checksum();
472 print_whitelisting_entry();
485 static void halt(
bool success)
489 F(
"+------------------------------------------------------------------------------------+"));
491 F(
"| Execution result |"));
493 F(
"+------------------------------------------------------------------------------------+"));
500 #ifdef USE_SOFT_SIGNING
501 Serial.println(F(
" |"));
504 Serial.print(F(
"(last ATSHA204A return code: 0x"));
505 if (ret_code < 0x10) {
508 Serial.print(ret_code, HEX);
509 Serial.println(F(
") |"));
511 Serial.println(F(
" |"));
516 F(
"+------------------------------------------------------------------------------------+"));
522 #ifdef GENERATE_SOMETHING
529 static bool generate_random_data(uint8_t*
data,
size_t sz)
531 #if defined(USE_SOFT_SIGNING) && ! defined(MY_HW_HAS_GETENTROPY)
532 for (
size_t i = 0; i < sz; i++) {
533 data[i] = random(256) ^ micros();
534 uint32_t enter = hwMillis();
535 while (hwMillis() - enter < (uint32_t)2);
538 #elif defined(USE_SOFT_SIGNING) && defined(MY_HW_HAS_GETENTROPY)
539 hwGetentropy(&
data, sz);
545 memcpy(
data, rx_buffer+SHA204_BUFFER_POS_DATA, sz);
548 #endif // not USE_SOFT_SIGNING
550 #endif // GENERATE_SOMETHING
553 static void generate_keys(
void)
555 #ifdef GENERATE_SOMETHING
557 F(
"+------------------------------------------------------------------------------------+"));
559 F(
"| Key generation |"));
561 F(
"+--------+--------+------------------------------------------------------------------+"));
563 F(
"| Key ID | Status | Key |"));
565 F(
"+--------+--------+------------------------------------------------------------------+"));
567 #ifdef GENERATE_HMAC_KEY
568 Serial.print(F(
"| HMAC | "));
569 if (!generate_random_data(user_hmac_key, 32)) {
570 memset(user_hmac_key, 0xFF, 32);
571 Serial.print(F(
"FAILED | "));
573 Serial.print(F(
"OK | "));
575 print_hex_buffer(user_hmac_key, 32);
576 Serial.println(F(
" |"));
578 #ifdef GENERATE_AES_KEY
579 Serial.print(F(
"| AES | "));
580 if (!generate_random_data(user_aes_key, 16)) {
581 memset(user_aes_key, 0xFF, 16);
582 Serial.print(F(
"FAILED | "));
584 Serial.print(F(
"OK | "));
586 print_hex_buffer(user_aes_key, 16);
587 Serial.println(F(
" |"));
589 #ifdef GENERATE_SOFT_SERIAL
590 Serial.print(F(
"| SERIAL | "));
591 if (has_device_unique_id) {
592 Serial.println(F(
"N/A | MCU has a unique serial which will be used instead. |"));
594 if (!generate_random_data(user_soft_serial, 9)) {
595 memset(user_soft_serial, 0xFF, 9);
596 Serial.print(F(
"FAILED | "));
598 Serial.print(F(
"OK | "));
600 print_hex_buffer(user_soft_serial, 9);
601 Serial.println(F(
" |"));
604 #if defined(GENERATE_SOMETHING) && !defined(PERSONALIZE_SOFT_RANDOM_SERIAL)
606 F(
"+--------+--------+------------------------------------------------------------------+"));
609 F(
"+------------------------------------------------------------------------------------+"));
611 F(
"| Key copy section |"));
613 F(
"+------------------------------------------------------------------------------------+"));
614 #ifdef GENERATE_HMAC_KEY
615 Serial.print(F(
"#define MY_HMAC_KEY "));
616 print_c_friendly_hex_buffer(user_hmac_key, 32);
619 #ifdef GENERATE_AES_KEY
620 Serial.print(F(
"#define MY_AES_KEY "));
621 print_c_friendly_hex_buffer(user_aes_key, 16);
624 #ifdef GENERATE_SOFT_SERIAL
625 Serial.print(F(
"#define MY_SOFT_SERIAL "));
626 print_c_friendly_hex_buffer(user_soft_serial, 9);
630 F(
"+------------------------------------------------------------------------------------+"));
632 #elif defined(PERSONALIZE_SOFT_RANDOM_SERIAL)
634 F(
"+--------+--------+------------------------------------------------------------------+"));
639 #ifdef RESET_EEPROM_PERSONALIZATION
641 static void reset_eeprom(
void)
643 uint8_t validation_buffer[32];
645 F(
"+------------------------------------------------------------------------------------+"));
647 F(
"| EEPROM reset |"));
649 F(
"+--------+---------------------------------------------------------------------------+"));
651 F(
"| Key ID | Status |"));
653 F(
"+--------+---------------------------------------------------------------------------+"));
654 Serial.print(F(
"| HMAC | "));
658 if (memcmp(validation_buffer, reset_buffer, 32) != 0) {
659 Serial.println(F(
"FAILED |"));
661 Serial.println(F(
"OK |"));
663 Serial.print(F(
"| AES | "));
667 if (memcmp(validation_buffer, reset_buffer, 16) != 0) {
668 Serial.println(F(
"FAILED |"));
670 Serial.println(F(
"OK |"));
672 Serial.print(F(
"| SERIAL | "));
676 if (memcmp(validation_buffer, reset_buffer, 9) != 0) {
677 Serial.println(F(
"FAILED |"));
679 Serial.println(F(
"OK |"));
682 F(
"+--------+---------------------------------------------------------------------------+"));
684 #endif // RESET_EEPROM_PERSONALIZATION
686 static void write_eeprom_checksum(
void)
700 SHA256(hash, buffer,
sizeof(buffer));
706 static void store_keys(
void)
708 #if defined(STORE_HMAC_KEY) || defined(STORE_AES_KEY) || defined(STORE_SOFT_SERIAL)
710 F(
"+------------------------------------------------------------------------------------+"));
712 F(
"| Key storage |"));
714 F(
"+--------+--------+------------------------------------------------------------------+"));
716 F(
"| Key ID | Status | Key |"));
718 F(
"+--------+--------+------------------------------------------------------------------+"));
720 #ifdef STORE_HMAC_KEY
721 Serial.print(F(
"| HMAC | "));
722 if (!store_hmac_key_data(user_hmac_key)) {
723 Serial.print(F(
"FAILED | "));
725 Serial.print(F(
"OK | "));
727 print_hex_buffer(user_hmac_key, 32);
728 Serial.println(F(
" |"));
731 Serial.print(F(
"| AES | "));
732 if (!store_aes_key_data(user_aes_key)) {
733 Serial.print(F(
"FAILED | "));
735 Serial.print(F(
"OK | "));
737 print_hex_buffer(user_aes_key, 16);
738 Serial.println(F(
" |"));
740 #ifdef STORE_SOFT_SERIAL
741 Serial.print(F(
"| SERIAL | "));
742 if (has_device_unique_id) {
743 memset(user_soft_serial, 0xFF, 9);
745 if (!store_soft_serial_data(user_soft_serial)) {
746 Serial.print(F(
"FAILED | "));
748 Serial.print(F(
"OK | "));
750 if (has_device_unique_id) {
751 Serial.println(F(
"EEPROM reset. MCU has a unique serial which will be used instead.|"));
753 print_hex_buffer(user_soft_serial, 9);
754 Serial.println(F(
" |"));
757 #if defined(STORE_HMAC_KEY) || defined(STORE_AES_KEY) || defined(STORE_SOFT_SERIAL)
759 F(
"+--------+--------+------------------------------------------------------------------+"));
769 static void print_hex_buffer(uint8_t*
data,
size_t sz)
771 for (
size_t i=0; i<sz; i++) {
772 if (
data[i] < 0x10) {
775 Serial.print(
data[i], HEX);
784 static void print_c_friendly_hex_buffer(uint8_t*
data,
size_t sz)
786 for (
size_t i=0; i<sz; i++) {
788 if (
data[i] < 0x10) {
791 Serial.print(
data[i], HEX);
798 #ifdef STORE_HMAC_KEY
804 static bool store_hmac_key_data(uint8_t*
data)
806 #ifdef USE_SOFT_SIGNING
807 static uint8_t validation_buffer[32];
811 if (memcmp(validation_buffer,
data, 32) != 0) {
818 if (lockConfig == 0x00) {
820 if (!write_atsha204a_key(
data)) {
838 static bool store_aes_key_data(uint8_t*
data)
840 static uint8_t validation_buffer[16];
844 if (memcmp(validation_buffer,
data, 16) != 0) {
850 #endif // STORE_AES_KEY
852 #ifdef STORE_SOFT_SERIAL
858 static bool store_soft_serial_data(uint8_t*
data)
860 static uint8_t validation_buffer[9];
864 if (memcmp(validation_buffer,
data, 9) != 0) {
870 #endif // STORE_SOFT_SERIAL
872 #ifndef USE_SOFT_SIGNING
876 static void init_atsha204a_state(
void)
883 lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
884 lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
888 #ifdef LOCK_ATSHA204A_CONFIGURATION
889 static void lock_atsha204a_config(
void)
892 F(
"+------------------------------------------------------------------------------------+"));
894 F(
"| ATSHA204A configuration locking |"));
896 F(
"+------------------------------------------------------------------------------------+"));
897 if (lockConfig != 0x00) {
902 crc = write_atsha204a_config_and_get_crc();
905 #ifdef PRINT_DETAILED_ATSHA204A_CONFIG
907 F(
"| New ATSHA204A Configuration |"));
908 dump_detailed_atsha204a_configuration();
909 #endif // PRINT_DETAILED_ATSHA204A_CONFIG
911 #ifndef SKIP_UART_CONFIRMATION
913 while (Serial.available()) {
917 F(
"| * Send SPACE character now to lock the configuration... |"));
919 while (Serial.available() == 0);
920 if (Serial.read() ==
' ')
921 #endif //not SKIP_UART_CONFIRMATION
923 Serial.print(F(
"| * Locking configuration..."));
929 F(
"+------------------------------------------------------------------------------------+"));
935 crc, 0, NULL, 0, NULL, 0, NULL,
936 LOCK_COUNT, tx_buffer, LOCK_RSP_SIZE, rx_buffer);
938 Serial.println(F(
"Failed |"));
940 F(
"+------------------------------------------------------------------------------------+"));
943 Serial.println(F(
"Done |"));
949 F(
"+------------------------------------------------------------------------------------+"));
952 lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
953 lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
957 #ifndef SKIP_UART_CONFIRMATION
960 F(
"| * Unexpected answer. Skipping locking. |"));
962 F(
"+------------------------------------------------------------------------------------+"));
964 #endif //not SKIP_UART_CONFIRMATION
967 F(
"| * Skipping configuration write and lock (configuration already locked). |"));
969 F(
"+------------------------------------------------------------------------------------+"));
978 static uint16_t write_atsha204a_config_and_get_crc(
void)
981 uint8_t config_word[4];
988 for (
int i=0; i < 88; i += 4) {
989 bool do_write =
true;
991 config_word[0] = 0x8F;
992 config_word[1] = 0x80;
993 config_word[2] = 0x80;
994 config_word[3] = 0xA1;
995 }
else if (i == 24) {
996 config_word[0] = 0x82;
997 config_word[1] = 0xE0;
998 config_word[2] = 0xA3;
999 config_word[3] = 0x60;
1000 }
else if (i == 28) {
1001 config_word[0] = 0x94;
1002 config_word[1] = 0x40;
1003 config_word[2] = 0xA0;
1004 config_word[3] = 0x85;
1005 }
else if (i == 32) {
1006 config_word[0] = 0x86;
1007 config_word[1] = 0x40;
1008 config_word[2] = 0x87;
1009 config_word[3] = 0x07;
1010 }
else if (i == 36) {
1011 config_word[0] = 0x0F;
1012 config_word[1] = 0x00;
1013 config_word[2] = 0x89;
1014 config_word[3] = 0xF2;
1015 }
else if (i == 40) {
1016 config_word[0] = 0x8A;
1017 config_word[1] = 0x7A;
1018 config_word[2] = 0x0B;
1019 config_word[3] = 0x8B;
1020 }
else if (i == 44) {
1021 config_word[0] = 0x0C;
1022 config_word[1] = 0x4C;
1023 config_word[2] = 0xDD;
1024 config_word[3] = 0x4D;
1025 }
else if (i == 48) {
1026 config_word[0] = 0xC2;
1027 config_word[1] = 0x42;
1028 config_word[2] = 0xAF;
1029 config_word[3] = 0x8F;
1030 }
else if (i == 52 || i == 56 || i == 60 || i == 64) {
1031 config_word[0] = 0xFF;
1032 config_word[1] = 0x00;
1033 config_word[2] = 0xFF;
1034 config_word[3] = 0x00;
1035 }
else if (i == 68 || i == 72 || i == 76 || i == 80) {
1036 config_word[0] = 0xFF;
1037 config_word[1] = 0xFF;
1038 config_word[2] = 0xFF;
1039 config_word[3] = 0xFF;
1045 F(
"+------------------------------------------------------------------------------------+"));
1049 config_word[0] = rx_buffer[SHA204_BUFFER_POS_DATA+0];
1050 config_word[1] = rx_buffer[SHA204_BUFFER_POS_DATA+1];
1051 config_word[2] = rx_buffer[SHA204_BUFFER_POS_DATA+2];
1052 config_word[3] = rx_buffer[SHA204_BUFFER_POS_DATA+3];
1062 i >> 2, 4, config_word, 0, NULL, 0, NULL,
1063 WRITE_COUNT_SHORT, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
1066 F(
"+------------------------------------------------------------------------------------+"));
1075 static bool get_atsha204a_serial(uint8_t*
data)
1081 memcpy(
data, rx_buffer, 9);
1086 #ifdef STORE_HMAC_KEY
1092 static bool write_atsha204a_key(uint8_t* key)
1096 0, SHA204_ZONE_ACCESS_32, key, 0, NULL, 0, NULL,
1097 WRITE_COUNT_LONG, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
1104 #endif // STORE_HMAC_KEY
1105 #endif // not USE_SOFT_SIGNING
1108 static void print_greeting(
void)
1111 F(
"+------------------------------------------------------------------------------------+"));
1113 F(
"| MySensors security personalizer |"));
1115 F(
"+------------------------------------------------------------------------------------+"));
1117 #ifdef NO_SETTINGS_DEFINED
1119 F(
"+------------------------------------------------------------------------------------+"));
1121 F(
"| You are running without any configuration flags set. |"));
1123 F(
"| No changes will be made to ATSHA204A or EEPROM except for the EEPROM checksum |"));
1125 F(
"| which will be updated. |"));
1129 F(
"| If you want to personalize your device, you have two options. |"));
1133 F(
"| 1. a. Enable either GENERATE_KEYS_ATSHA204A or GENERATE_KEYS_SOFT |"));
1135 F(
"| This will generate keys for ATSHA204A or software signing. |"));
1137 F(
"| b. Execute the sketch. You will be guided through the steps below under |"));
1139 F(
"| WHAT TO DO NEXT? |"));
1141 F(
"| c. Copy the generated keys and replace the topmost definitions in this file. |"));
1143 F(
"| d. Save the sketch and then disable the flag you just enabled. |"));
1145 F(
"| e. Enable PERSONALIZE_ATSHA204A to personalize the ATSHA204A device. |"));
1149 F(
"| Enable PERSONALIZE_SOFT to personalize the EEPROM for software signing. |"));
1151 F(
"| If you want to use whitelisting you need to pick a unique serial number |"));
1153 F(
"| for each device you run the sketch on and fill in MY_SOFT_SERIAL. |"));
1157 F(
"| Enable PERSONALIZE_SOFT_RANDOM_SERIAL to personalzie the EEPROM and |"));
1159 F(
"| include a new random serial number every time the sketch is executed. |"));
1161 F(
"| Take note of each saved serial number if you plan to use whitelisting. |"));
1163 F(
"| f. Execute the sketch on each device you want to personalize that is supposed |"));
1165 F(
"| to communicate securely. |"));
1169 F(
"| 2. Enable any configuration flag as you see fit. |"));
1171 F(
"| It is assumed that you know what you are doing. |"));
1173 F(
"+------------------------------------------------------------------------------------+"));
1177 F(
"+------------------------------------------------------------------------------------+"));
1179 F(
"| Configuration settings |"));
1181 F(
"+------------------------------------------------------------------------------------+"));
1182 #if defined(GENERATE_KEYS_ATSHA204A)
1184 F(
"| * Guided key generation for ATSHA204A using ATSHA024A |"));
1186 #if defined(GENERATE_KEYS_SOFT)
1188 F(
"| * Guided key generation for EEPROM using software |"));
1190 #if defined(PERSONALIZE_ATSHA204A)
1192 F(
"| * Guided personalization/storage of keys in ATSHA204A |"));
1194 #if defined(PERSONALIZE_SOFT)
1196 F(
"| * Guided personalization/storage of keys in EEPROM |"));
1198 #if defined(PERSONALIZE_SOFT_RANDOM_SERIAL)
1200 F(
"| * Guided storage and generation of random serial in EEPROM |"));
1202 #if defined(USE_SOFT_SIGNING)
1204 F(
"| * Software based personalization (no ATSHA204A usage whatsoever) |"));
1207 F(
"| * ATSHA204A based personalization |"));
1209 #if defined(LOCK_ATSHA204A_CONFIGURATION)
1211 F(
"| * Will lock ATSHA204A configuration |"));
1213 #if defined(SKIP_UART_CONFIRMATION)
1215 F(
"| * Will not require any UART confirmations |"));
1217 #if defined(GENERATE_HMAC_KEY)
1219 F(
"| * Will generate HMAC key using "));
1220 #if defined(USE_SOFT_SIGNING)
1228 #if defined(STORE_HMAC_KEY)
1229 Serial.print(F(
"| * Will store HMAC key to "));
1230 #if defined(USE_SOFT_SIGNING)
1238 #if defined(GENERATE_AES_KEY)
1240 F(
"| * Will generate AES key using "));
1241 #if defined(USE_SOFT_SIGNING)
1249 #if defined(STORE_AES_KEY)
1251 F(
"| * Will store AES key to EEPROM |"));
1253 #if defined(GENERATE_SOFT_SERIAL)
1255 F(
"| * Will generate soft serial using software |"));
1257 #if defined(STORE_SOFT_SERIAL)
1259 F(
"| * Will store soft serial to EEPROM |"));
1261 #if defined(PRINT_DETAILED_ATSHA204A_CONFIG)
1263 F(
"| * Will print detailed ATSHA204A configuration |"));
1265 #if defined(RESET_EEPROM_PERSONALIZATION)
1267 F(
"| * Will reset EEPROM personalization data |"));
1270 F(
"+------------------------------------------------------------------------------------+"));
1272 #endif // not NO_SETTINGS_DEFINED
1273 probe_and_print_peripherals();
1276 static void print_ending(
void)
1278 #if defined(GUIDED_MODE) || defined(NO_SETTINGS_DEFINED)
1280 F(
"+------------------------------------------------------------------------------------+"));
1282 F(
"| WHAT TO DO NEXT? |"));
1284 F(
"+------------------------------------------------------------------------------------+"));
1285 #ifdef NO_SETTINGS_DEFINED
1287 F(
"| To proceed with the personalization, enable GENERATE_KEYS_ATSHA204A or |"));
1289 F(
"| GENERATE_KEYS_SOFT depending on what type of signing backend you plan to use. |"));
1291 F(
"| Both options will generate an AES key for encryption if you plan to use that. |"));
1293 F(
"| Recompile, upload and run the sketch again for further instructions. |"));
1295 F(
"+------------------------------------------------------------------------------------+"));
1297 #ifdef GENERATE_KEYS_ATSHA204A
1299 F(
"| To proceed with the personalization, copy the keys shown in the Key copy section, |"));
1301 F(
"| and replace the corresponding definitions in the top of the sketch, then disable |"));
1303 F(
"| GENERATE_KEYS_ATSHA204A and enable PERSONALIZE_ATSHA204A. |"));
1305 F(
"+------------------------------------------------------------------------------------+"));
1307 #ifdef GENERATE_KEYS_SOFT
1309 F(
"| To proceed with the personalization, copy the keys shown in the Key copy section, |"));
1311 F(
"| and replace the corresponding definitions in the top of the sketch, then disable |"));
1313 F(
"| GENERATE_KEYS_SOFT and enable PERSONALIZE_SOFT or PERSONALIZE_SOFT_RANDOM_SERIAL. |"));
1315 F(
"+------------------------------------------------------------------------------------+"));
1317 #if defined(PERSONALIZE_ATSHA204A) ||\
1318 defined(PERSONALIZE_SOFT) ||\
1319 defined(PERSONALIZE_SOFT_RANDOM_SERIAL)
1321 F(
"| This device has now been personalized. Run this sketch with its current settings |"));
1323 F(
"| on all the devices in your network that have security enabled. |"));
1325 F(
"+------------------------------------------------------------------------------------+"));
1327 #endif // GUIDED_MODE or NO_SETTINGS_DEFINED
1330 static void probe_and_print_peripherals(
void)
1335 F(
"+------------------------------------------------------------------------------------+"));
1337 F(
"| Hardware security peripherals |"));
1339 F(
"+--------------+--------------+--------------+------------------------------+--------+"));
1341 F(
"| Device | Status | Revision | Serial number | Locked |"));
1343 F(
"+--------------+--------------+--------------+------------------------------+--------+"));
1344 #if defined(ARDUINO_ARCH_AVR)
1345 Serial.print(F(
"| AVR | DETECTED | N/A | "));
1346 #elif defined(ARDUINO_ARCH_MEGAAVR)
1347 Serial.print(F(
"| megaAVR | DETECTED | N/A | "));
1348 #elif defined(ARDUINO_ARCH_ESP8266)
1349 Serial.print(F(
"| ESP8266 | DETECTED | N/A | "));
1350 #elif defined(ARDUINO_ARCH_SAMD)
1351 Serial.print(F(
"| SAMD | DETECTED | N/A | "));
1352 #elif defined(ARDUINO_ARCH_STM32F1)
1353 Serial.print(F(
"| STM32F1 | DETECTED | N/A | "));
1354 #elif defined(__linux__)
1355 Serial.print(F(
"| Linux | DETECTED | N/A | "));
1357 Serial.print(F(
"| Unknown | DETECTED | N/A | "));
1360 has_device_unique_id =
true;
1361 print_hex_buffer(uniqueID, 9);
1362 Serial.println(F(
" | N/A |"));
1364 Serial.println(F(
"N/A (generation required) | N/A |"));
1367 F(
"+--------------+--------------+--------------+------------------------------+--------+"));
1368 #ifndef USE_SOFT_SIGNING
1369 Serial.print(F(
"| ATSHA204A | "));
1373 Serial.println(F(
"NOT DETECTED | N/A | N/A | N/A |"));
1376 Serial.print(F(
"DETECTED | "));
1379 Serial.print(F(
"FAILED | "));
1381 print_hex_buffer(&rx_buffer[SHA204_BUFFER_POS_DATA], 4);
1382 Serial.print(F(
" | "));
1384 if (!get_atsha204a_serial(buffer)) {
1385 memset(buffer, 0xFF, 9);
1386 Serial.print(F(
"FAILED | "));
1388 print_hex_buffer(buffer, 9);
1389 Serial.print(F(
" | "));
1393 Serial.println(
"FAILED |");
1395 if (rx_buffer[SHA204_BUFFER_POS_DATA+3] == 0x00) {
1396 Serial.println(
"YES |");
1398 Serial.println(
"NO |");
1403 F(
"+--------------+--------------+--------------+------------------------------+--------+"));
1404 #ifdef PRINT_DETAILED_ATSHA204A_CONFIG
1406 F(
"+------------------------------------------------------------------------------------+"));
1408 F(
"| Current ATSHA204A Configuration |"));
1409 dump_detailed_atsha204a_configuration();
1411 #endif // not USE_SOFT_SIGNING
1415 static void print_eeprom_data(
void)
1420 F(
"+------------------------------------------------------------------------------------+"));
1424 F(
"+--------+--------+------------------------------------------------------------------+"));
1426 F(
"| Key ID | Status | Key |"));
1428 F(
"+--------+--------+------------------------------------------------------------------+"));
1429 Serial.print(F(
"| HMAC | "));
1431 if (!memcmp(buffer, reset_buffer, 32)) {
1432 Serial.print(F(
"RESET | "));
1434 Serial.print(F(
"OK | "));
1436 print_hex_buffer(buffer, 32);
1437 Serial.println(F(
" |"));
1438 Serial.print(F(
"| AES | "));
1440 if (!memcmp(buffer, reset_buffer, 16)) {
1441 Serial.print(F(
"RESET | "));
1443 Serial.print(F(
"OK | "));
1445 print_hex_buffer(buffer, 16);
1446 Serial.println(F(
" |"));
1447 Serial.print(F(
"| SERIAL | "));
1449 if (!memcmp(buffer, reset_buffer, 9)) {
1450 if (has_device_unique_id) {
1451 Serial.println(F(
"N/A | Device unique serial, not stored in EEPROM |"));
1453 Serial.print(F(
"RESET | "));
1454 print_hex_buffer(buffer, 9);
1455 Serial.println(F(
" |"));
1458 Serial.print(F(
"OK | "));
1459 print_hex_buffer(buffer, 9);
1460 Serial.println(F(
" |"));
1463 F(
"+--------+--------+------------------------------------------------------------------+"));
1467 static void print_whitelisting_entry(
void)
1470 #ifdef USE_SOFT_SIGNING
1473 if (!memcmp(buffer, reset_buffer, 9)) {
1476 memcpy(buffer, uniqueID, 9);
1481 if (!get_atsha204a_serial(buffer)) {
1482 memset(buffer, 0xFF, 9);
1486 F(
"+------------------------------------------------------------------------------------+"));
1488 F(
"| This nodes whitelist entry on other nodes |"));
1490 F(
"+------------------------------------------------------------------------------------+"));
1491 Serial.print(F(
"{.nodeId = <ID of this node>,.serial = {"));
1492 print_c_friendly_hex_buffer(buffer, 9);
1493 Serial.println(F(
"}}"));
1495 F(
"+------------------------------------------------------------------------------------+"));
1498 #ifdef PRINT_DETAILED_ATSHA204A_CONFIG
1500 static void dump_detailed_atsha204a_configuration(
void)
1503 F(
"+---------------------------------------------------------------++-------------------+"));
1505 F(
"| Fieldname || Data |"));
1507 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1508 for (
int i=0; i < 88; i += 4) {
1512 F(
"+------------------------------------------------------------------------------------+"));
1516 Serial.print(F(
"| SN[0:1] | SN[2:3] || "));
1517 for (
int j=0; j<4; j++) {
1518 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1521 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1523 Serial.print(F(
" | "));
1525 Serial.print(F(
" "));
1528 Serial.println(F(
" |"));
1530 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1531 }
else if (i == 0x04) {
1532 Serial.print(F(
"| Revnum || "));
1533 for (
int j=0; j<4; j++) {
1534 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1537 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1539 Serial.print(F(
" "));
1542 Serial.println(F(
" |"));
1544 F(
"+---------------------------------------------------------------++-------------------+"));
1545 }
else if (i == 0x08) {
1546 Serial.print(F(
"| SN[4:7] || "));
1547 for (
int j=0; j<4; j++) {
1548 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1551 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1553 Serial.print(F(
" "));
1556 Serial.println(F(
" |"));
1558 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1559 }
else if (i == 0x0C) {
1560 Serial.print(F(
"| SN[8] | Reserved13 | I2CEnable | Reserved15 || "));
1561 for (
int j=0; j<4; j++) {
1562 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1565 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1567 Serial.print(F(
" | "));
1569 Serial.println(F(
" |"));
1573 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1574 }
else if (i == 0x10) {
1575 Serial.print(F(
"| I2CAddress | TempOffset | OTPmode | SelectorMode || "));
1576 for (
int j=0; j<4; j++) {
1577 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1580 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1582 Serial.print(F(
" | "));
1584 Serial.println(F(
" |"));
1588 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1589 }
else if (i == 0x14) {
1590 Serial.print(F(
"| SlotConfig00 | SlotConfig01 || "));
1591 for (
int j=0; j<4; j++) {
1592 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1595 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1597 Serial.print(F(
" | "));
1599 Serial.print(F(
" "));
1602 Serial.println(F(
" |"));
1604 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1605 }
else if (i == 0x18) {
1606 Serial.print(F(
"| SlotConfig02 | SlotConfig03 || "));
1607 for (
int j=0; j<4; j++) {
1608 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1611 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1613 Serial.print(F(
" | "));
1615 Serial.print(F(
" "));
1618 Serial.println(F(
" |"));
1620 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1621 }
else if (i == 0x1C) {
1622 Serial.print(F(
"| SlotConfig04 | SlotConfig05 || "));
1623 for (
int j=0; j<4; j++) {
1624 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1627 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1629 Serial.print(F(
" | "));
1631 Serial.print(F(
" "));
1634 Serial.println(F(
" |"));
1636 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1637 }
else if (i == 0x20) {
1638 Serial.print(F(
"| SlotConfig06 | SlotConfig07 || "));
1639 for (
int j=0; j<4; j++) {
1640 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1643 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1645 Serial.print(F(
" | "));
1647 Serial.print(F(
" "));
1650 Serial.println(F(
" |"));
1652 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1653 }
else if (i == 0x24) {
1654 Serial.print(F(
"| SlotConfig08 | SlotConfig09 || "));
1655 for (
int j=0; j<4; j++) {
1656 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1659 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1661 Serial.print(F(
" | "));
1663 Serial.print(F(
" "));
1666 Serial.println(F(
" |"));
1668 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1669 }
else if (i == 0x28) {
1670 Serial.print(F(
"| SlotConfig0A | SlotConfig0B || "));
1671 for (
int j=0; j<4; j++) {
1672 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1675 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1677 Serial.print(F(
" | "));
1679 Serial.print(F(
" "));
1682 Serial.println(F(
" |"));
1684 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1685 }
else if (i == 0x2C) {
1686 Serial.print(F(
"| SlotConfig0C | SlotConfig0D || "));
1687 for (
int j=0; j<4; j++) {
1688 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1691 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1693 Serial.print(F(
" | "));
1695 Serial.print(F(
" "));
1698 Serial.println(F(
" |"));
1700 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1701 }
else if (i == 0x30) {
1702 Serial.print(F(
"| SlotConfig0E | SlotConfig0F || "));
1703 for (
int j=0; j<4; j++) {
1704 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1707 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1709 Serial.print(F(
" | "));
1711 Serial.print(F(
" "));
1714 Serial.println(F(
" |"));
1716 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1717 }
else if (i == 0x34) {
1718 Serial.print(F(
"| UseFlag00 | UpdateCount00 | UseFlag01 | UpdateCount01 || "));
1719 for (
int j=0; j<4; j++) {
1720 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1723 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1725 Serial.print(F(
" | "));
1727 Serial.println(F(
" |"));
1731 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1732 }
else if (i == 0x38) {
1733 Serial.print(F(
"| UseFlag02 | UpdateCount02 | UseFlag03 | UpdateCount03 || "));
1734 for (
int j=0; j<4; j++) {
1735 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1738 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1740 Serial.print(F(
" | "));
1742 Serial.println(F(
" |"));
1746 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1747 }
else if (i == 0x3C) {
1748 Serial.print(F(
"| UseFlag04 | UpdateCount04 | UseFlag05 | UpdateCount05 || "));
1749 for (
int j=0; j<4; j++) {
1750 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1753 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1755 Serial.print(F(
" | "));
1757 Serial.println(F(
" |"));
1761 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1762 }
else if (i == 0x40) {
1763 Serial.print(F(
"| UseFlag06 | UpdateCount06 | UseFlag07 | UpdateCount07 || "));
1764 for (
int j=0; j<4; j++) {
1765 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1768 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1770 Serial.print(F(
" | "));
1772 Serial.println(F(
" |"));
1776 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1777 }
else if (i == 0x44) {
1778 Serial.print(F(
"| LastKeyUse[0:3] || "));
1779 for (
int j=0; j<4; j++) {
1780 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1783 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1785 Serial.print(F(
" "));
1788 Serial.println(F(
" |"));
1790 F(
"+---------------------------------------------------------------++-------------------+"));
1791 }
else if (i == 0x48) {
1792 Serial.print(F(
"| LastKeyUse[4:7] || "));
1793 for (
int j=0; j<4; j++) {
1794 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1797 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1799 Serial.print(F(
" "));
1802 Serial.println(F(
" |"));
1804 F(
"+---------------------------------------------------------------++-------------------+"));
1805 }
else if (i == 0x4C) {
1806 Serial.print(F(
"| LastKeyUse[8:B] || "));
1807 for (
int j=0; j<4; j++) {
1808 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1811 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1813 Serial.print(F(
" "));
1816 Serial.println(F(
" |"));
1818 F(
"+---------------------------------------------------------------++-------------------+"));
1819 }
else if (i == 0x50) {
1820 Serial.print(F(
"| LastKeyUse[C:F] || "));
1821 for (
int j=0; j<4; j++) {
1822 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1825 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1827 Serial.print(F(
" "));
1830 Serial.println(F(
" |"));
1832 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1833 }
else if (i == 0x54) {
1834 Serial.print(F(
"| UserExtra | Selector | LockValue | LockConfig || "));
1835 for (
int j=0; j<4; j++) {
1836 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1839 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1841 Serial.print(F(
" | "));
1843 Serial.println(F(
" |"));
1847 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1851 #endif // PRINT_DETAILED_ATSHA204A_CONFIG
1856 #define GENERATE_KEYS_ATSHA204A
1857 #define GENERATE_KEYS_SOFT
1858 #define PERSONALIZE_ATSHA204A
1859 #define PERSONALIZE_SOFT
1860 #define PERSONALIZE_SOFT_RANDOM_SERIAL
1861 #define USE_SOFT_SIGNING
1862 #define LOCK_ATSHA204A_CONFIGURATION
1863 #define SKIP_UART_CONFIRMATION
1864 #define GENERATE_HMAC_KEY
1865 #define STORE_HMAC_KEY
1866 #define GENERATE_AES_KEY
1867 #define STORE_AES_KEY
1868 #define GENERATE_SOFT_SERIAL
1869 #define STORE_SOFT_SERIAL
1870 #define PRINT_DETAILED_ATSHA204A_CONFIG
1871 #define RESET_EEPROM_PERSONALIZATION