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
917 F(
"| * Send SPACE character now to lock the configuration... |"));
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_ESP8266)
1347 Serial.print(F(
"| ESP8266 | DETECTED | N/A | "));
1348 #elif defined(ARDUINO_ARCH_SAMD)
1349 Serial.print(F(
"| SAMD | DETECTED | N/A | "));
1350 #elif defined(ARDUINO_ARCH_STM32F1)
1351 Serial.print(F(
"| STM32F1 | DETECTED | N/A | "));
1352 #elif defined(__linux__)
1353 Serial.print(F(
"| Linux | DETECTED | N/A | "));
1355 Serial.print(F(
"| Unknown | DETECTED | N/A | "));
1358 has_device_unique_id =
true;
1359 print_hex_buffer(uniqueID, 9);
1360 Serial.println(F(
" | N/A |"));
1362 Serial.println(F(
"N/A (generation required) | N/A |"));
1365 F(
"+--------------+--------------+--------------+------------------------------+--------+"));
1366 #ifndef USE_SOFT_SIGNING
1367 Serial.print(F(
"| ATSHA204A | "));
1371 Serial.println(F(
"NOT DETECTED | N/A | N/A | N/A |"));
1374 Serial.print(F(
"DETECTED | "));
1377 Serial.print(F(
"FAILED | "));
1379 print_hex_buffer(&rx_buffer[SHA204_BUFFER_POS_DATA], 4);
1380 Serial.print(F(
" | "));
1382 if (!get_atsha204a_serial(buffer)) {
1383 memset(buffer, 0xFF, 9);
1384 Serial.print(F(
"FAILED | "));
1386 print_hex_buffer(buffer, 9);
1387 Serial.print(F(
" | "));
1391 Serial.println(
"FAILED |");
1393 if (rx_buffer[SHA204_BUFFER_POS_DATA+3] == 0x00) {
1394 Serial.println(
"YES |");
1396 Serial.println(
"NO |");
1401 F(
"+--------------+--------------+--------------+------------------------------+--------+"));
1402 #ifdef PRINT_DETAILED_ATSHA204A_CONFIG
1404 F(
"+------------------------------------------------------------------------------------+"));
1406 F(
"| Current ATSHA204A Configuration |"));
1407 dump_detailed_atsha204a_configuration();
1409 #endif // not USE_SOFT_SIGNING
1413 static void print_eeprom_data(
void)
1418 F(
"+------------------------------------------------------------------------------------+"));
1422 F(
"+--------+--------+------------------------------------------------------------------+"));
1424 F(
"| Key ID | Status | Key |"));
1426 F(
"+--------+--------+------------------------------------------------------------------+"));
1427 Serial.print(F(
"| HMAC | "));
1429 if (!memcmp(buffer, reset_buffer, 32)) {
1430 Serial.print(F(
"RESET | "));
1432 Serial.print(F(
"OK | "));
1434 print_hex_buffer(buffer, 32);
1435 Serial.println(F(
" |"));
1436 Serial.print(F(
"| AES | "));
1438 if (!memcmp(buffer, reset_buffer, 16)) {
1439 Serial.print(F(
"RESET | "));
1441 Serial.print(F(
"OK | "));
1443 print_hex_buffer(buffer, 16);
1444 Serial.println(F(
" |"));
1445 Serial.print(F(
"| SERIAL | "));
1447 if (!memcmp(buffer, reset_buffer, 9)) {
1448 if (has_device_unique_id) {
1449 Serial.println(F(
"N/A | Device unique serial, not stored in EEPROM |"));
1451 Serial.print(F(
"RESET | "));
1452 print_hex_buffer(buffer, 9);
1453 Serial.println(F(
" |"));
1456 Serial.print(F(
"OK | "));
1457 print_hex_buffer(buffer, 9);
1458 Serial.println(F(
" |"));
1461 F(
"+--------+--------+------------------------------------------------------------------+"));
1465 static void print_whitelisting_entry(
void)
1468 #ifdef USE_SOFT_SIGNING
1471 if (!memcmp(buffer, reset_buffer, 9)) {
1474 memcpy(buffer, uniqueID, 9);
1479 if (!get_atsha204a_serial(buffer)) {
1480 memset(buffer, 0xFF, 9);
1484 F(
"+------------------------------------------------------------------------------------+"));
1486 F(
"| This nodes whitelist entry on other nodes |"));
1488 F(
"+------------------------------------------------------------------------------------+"));
1489 Serial.print(F(
"{.nodeId = <ID of this node>,.serial = {"));
1490 print_c_friendly_hex_buffer(buffer, 9);
1491 Serial.println(F(
"}}"));
1493 F(
"+------------------------------------------------------------------------------------+"));
1496 #ifdef PRINT_DETAILED_ATSHA204A_CONFIG
1498 static void dump_detailed_atsha204a_configuration(
void)
1501 F(
"+---------------------------------------------------------------++-------------------+"));
1503 F(
"| Fieldname || Data |"));
1505 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1506 for (
int i=0; i < 88; i += 4) {
1510 F(
"+------------------------------------------------------------------------------------+"));
1514 Serial.print(F(
"| SN[0:1] | SN[2:3] || "));
1515 for (
int j=0; j<4; j++) {
1516 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1519 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1521 Serial.print(F(
" | "));
1523 Serial.print(F(
" "));
1526 Serial.println(F(
" |"));
1528 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1529 }
else if (i == 0x04) {
1530 Serial.print(F(
"| Revnum || "));
1531 for (
int j=0; j<4; j++) {
1532 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1535 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1537 Serial.print(F(
" "));
1540 Serial.println(F(
" |"));
1542 F(
"+---------------------------------------------------------------++-------------------+"));
1543 }
else if (i == 0x08) {
1544 Serial.print(F(
"| SN[4:7] || "));
1545 for (
int j=0; j<4; j++) {
1546 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1549 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1551 Serial.print(F(
" "));
1554 Serial.println(F(
" |"));
1556 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1557 }
else if (i == 0x0C) {
1558 Serial.print(F(
"| SN[8] | Reserved13 | I2CEnable | Reserved15 || "));
1559 for (
int j=0; j<4; j++) {
1560 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1563 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1565 Serial.print(F(
" | "));
1567 Serial.println(F(
" |"));
1571 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1572 }
else if (i == 0x10) {
1573 Serial.print(F(
"| I2CAddress | TempOffset | OTPmode | SelectorMode || "));
1574 for (
int j=0; j<4; j++) {
1575 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1578 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1580 Serial.print(F(
" | "));
1582 Serial.println(F(
" |"));
1586 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1587 }
else if (i == 0x14) {
1588 Serial.print(F(
"| SlotConfig00 | SlotConfig01 || "));
1589 for (
int j=0; j<4; j++) {
1590 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1593 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1595 Serial.print(F(
" | "));
1597 Serial.print(F(
" "));
1600 Serial.println(F(
" |"));
1602 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1603 }
else if (i == 0x18) {
1604 Serial.print(F(
"| SlotConfig02 | SlotConfig03 || "));
1605 for (
int j=0; j<4; j++) {
1606 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1609 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1611 Serial.print(F(
" | "));
1613 Serial.print(F(
" "));
1616 Serial.println(F(
" |"));
1618 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1619 }
else if (i == 0x1C) {
1620 Serial.print(F(
"| SlotConfig04 | SlotConfig05 || "));
1621 for (
int j=0; j<4; j++) {
1622 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1625 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1627 Serial.print(F(
" | "));
1629 Serial.print(F(
" "));
1632 Serial.println(F(
" |"));
1634 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1635 }
else if (i == 0x20) {
1636 Serial.print(F(
"| SlotConfig06 | SlotConfig07 || "));
1637 for (
int j=0; j<4; j++) {
1638 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1641 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1643 Serial.print(F(
" | "));
1645 Serial.print(F(
" "));
1648 Serial.println(F(
" |"));
1650 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1651 }
else if (i == 0x24) {
1652 Serial.print(F(
"| SlotConfig08 | SlotConfig09 || "));
1653 for (
int j=0; j<4; j++) {
1654 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1657 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1659 Serial.print(F(
" | "));
1661 Serial.print(F(
" "));
1664 Serial.println(F(
" |"));
1666 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1667 }
else if (i == 0x28) {
1668 Serial.print(F(
"| SlotConfig0A | SlotConfig0B || "));
1669 for (
int j=0; j<4; j++) {
1670 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1673 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1675 Serial.print(F(
" | "));
1677 Serial.print(F(
" "));
1680 Serial.println(F(
" |"));
1682 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1683 }
else if (i == 0x2C) {
1684 Serial.print(F(
"| SlotConfig0C | SlotConfig0D || "));
1685 for (
int j=0; j<4; j++) {
1686 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1689 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1691 Serial.print(F(
" | "));
1693 Serial.print(F(
" "));
1696 Serial.println(F(
" |"));
1698 F(
"+-------------------------------+-------------------------------++---------+---------+"));
1699 }
else if (i == 0x30) {
1700 Serial.print(F(
"| SlotConfig0E | SlotConfig0F || "));
1701 for (
int j=0; j<4; j++) {
1702 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1705 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1707 Serial.print(F(
" | "));
1709 Serial.print(F(
" "));
1712 Serial.println(F(
" |"));
1714 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1715 }
else if (i == 0x34) {
1716 Serial.print(F(
"| UseFlag00 | UpdateCount00 | UseFlag01 | UpdateCount01 || "));
1717 for (
int j=0; j<4; j++) {
1718 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1721 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1723 Serial.print(F(
" | "));
1725 Serial.println(F(
" |"));
1729 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1730 }
else if (i == 0x38) {
1731 Serial.print(F(
"| UseFlag02 | UpdateCount02 | UseFlag03 | UpdateCount03 || "));
1732 for (
int j=0; j<4; j++) {
1733 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1736 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1738 Serial.print(F(
" | "));
1740 Serial.println(F(
" |"));
1744 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1745 }
else if (i == 0x3C) {
1746 Serial.print(F(
"| UseFlag04 | UpdateCount04 | UseFlag05 | UpdateCount05 || "));
1747 for (
int j=0; j<4; j++) {
1748 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1751 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1753 Serial.print(F(
" | "));
1755 Serial.println(F(
" |"));
1759 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1760 }
else if (i == 0x40) {
1761 Serial.print(F(
"| UseFlag06 | UpdateCount06 | UseFlag07 | UpdateCount07 || "));
1762 for (
int j=0; j<4; j++) {
1763 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1766 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1768 Serial.print(F(
" | "));
1770 Serial.println(F(
" |"));
1774 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1775 }
else if (i == 0x44) {
1776 Serial.print(F(
"| LastKeyUse[0:3] || "));
1777 for (
int j=0; j<4; j++) {
1778 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1781 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1783 Serial.print(F(
" "));
1786 Serial.println(F(
" |"));
1788 F(
"+---------------------------------------------------------------++-------------------+"));
1789 }
else if (i == 0x48) {
1790 Serial.print(F(
"| LastKeyUse[4:7] || "));
1791 for (
int j=0; j<4; j++) {
1792 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1795 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1797 Serial.print(F(
" "));
1800 Serial.println(F(
" |"));
1802 F(
"+---------------------------------------------------------------++-------------------+"));
1803 }
else if (i == 0x4C) {
1804 Serial.print(F(
"| LastKeyUse[8:B] || "));
1805 for (
int j=0; j<4; j++) {
1806 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1809 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1811 Serial.print(F(
" "));
1814 Serial.println(F(
" |"));
1816 F(
"+---------------------------------------------------------------++-------------------+"));
1817 }
else if (i == 0x50) {
1818 Serial.print(F(
"| LastKeyUse[C:F] || "));
1819 for (
int j=0; j<4; j++) {
1820 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1823 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1825 Serial.print(F(
" "));
1828 Serial.println(F(
" |"));
1830 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1831 }
else if (i == 0x54) {
1832 Serial.print(F(
"| UserExtra | Selector | LockValue | LockConfig || "));
1833 for (
int j=0; j<4; j++) {
1834 if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
1837 Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
1839 Serial.print(F(
" | "));
1841 Serial.println(F(
" |"));
1845 F(
"+---------------+---------------+---------------+---------------++----+----+----+----+"));
1849 #endif // PRINT_DETAILED_ATSHA204A_CONFIG
1854 #define GENERATE_KEYS_ATSHA204A
1855 #define GENERATE_KEYS_SOFT
1856 #define PERSONALIZE_ATSHA204A
1857 #define PERSONALIZE_SOFT
1858 #define PERSONALIZE_SOFT_RANDOM_SERIAL
1859 #define USE_SOFT_SIGNING
1860 #define LOCK_ATSHA204A_CONFIGURATION
1861 #define SKIP_UART_CONFIRMATION
1862 #define GENERATE_HMAC_KEY
1863 #define STORE_HMAC_KEY
1864 #define GENERATE_AES_KEY
1865 #define STORE_AES_KEY
1866 #define GENERATE_SOFT_SERIAL
1867 #define STORE_SOFT_SERIAL
1868 #define PRINT_DETAILED_ATSHA204A_CONFIG
1869 #define RESET_EEPROM_PERSONALIZATION