Mercurial > pihelp
comparison main.c @ 12:aec45c673a60
Fix decryption
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 12 Jun 2013 23:48:49 +0800 |
parents | e83b35e864d7 |
children | 915be6f0ff13 |
comparison
equal
deleted
inserted
replaced
11:e83b35e864d7 | 12:aec45c673a60 |
---|---|
458 long_delay(200); | 458 long_delay(200); |
459 #endif | 459 #endif |
460 | 460 |
461 // check the signature | 461 // check the signature |
462 memcpy(&output[2], &indata[HMACLEN], AESLEN); | 462 memcpy(&output[2], &indata[HMACLEN], AESLEN); |
463 hmac_sha1(output, avr_keys[key_index+1], KEYLEN*8, output, (2+AESLEN)*8); | 463 hmac_sha1(output, avr_keys[key_index], KEYLEN*8, output, (2+AESLEN)*8); |
464 | 464 |
465 if (memcmp(output, indata, HMACLEN) != 0) { | 465 if (memcmp(output, indata, HMACLEN) != 0) { |
466 printf_P(PSTR("FAIL: hmac mismatch\n")); | 466 printf_P(PSTR("FAIL: hmac mismatch\n")); |
467 } | 467 } |
468 | 468 |
503 | 503 |
504 static void | 504 static void |
505 cmd_vcc() | 505 cmd_vcc() |
506 { | 506 { |
507 uint16_t vcc = adc_vcc(); | 507 uint16_t vcc = adc_vcc(); |
508 printf_P("vcc: %u mV\n", vcc); | 508 printf_P(PSTR("vcc: %u mV\n"), vcc); |
509 } | 509 } |
510 | 510 |
511 static void | 511 static void |
512 read_handler() | 512 read_handler() |
513 { | 513 { |
531 { | 531 { |
532 cmd_hmac(&readbuf[5]); | 532 cmd_hmac(&readbuf[5]); |
533 } | 533 } |
534 else if (strncmp_P(readbuf, PSTR("decrypt "), 8) == 0) | 534 else if (strncmp_P(readbuf, PSTR("decrypt "), 8) == 0) |
535 { | 535 { |
536 cmd_hmac(&readbuf[8]); | 536 cmd_decrypt(&readbuf[8]); |
537 } | 537 } |
538 else if (strcmp_P(readbuf, PSTR("vcc")) == 0) | 538 else if (strcmp_P(readbuf, PSTR("vcc")) == 0) |
539 { | 539 { |
540 cmd_vcc(); | 540 cmd_vcc(); |
541 } | 541 } |
708 { | 708 { |
709 if (watchdog_long_hit | 709 if (watchdog_long_hit |
710 || watchdog_short_hit | 710 || watchdog_short_hit |
711 || oneshot_hit) | 711 || oneshot_hit) |
712 { | 712 { |
713 printf_P(PSTR("Rebooting! long %d, short %d, oneshot %d\n"), | |
714 watchdog_long_hit, watchdog_short_hit, oneshot_hit); | |
715 long_delay(300); | |
713 reboot_pi(); | 716 reboot_pi(); |
714 } | 717 } |
715 | 718 |
716 if (newboot_hit) { | 719 if (newboot_hit) { |
717 set_pi_boot_normal(0); | 720 set_pi_boot_normal(0); |
780 blink(); | 783 blink(); |
781 | 784 |
782 stdout = &mystdout; | 785 stdout = &mystdout; |
783 uart_on(); | 786 uart_on(); |
784 | 787 |
785 printf(PSTR("Pi Watchdog\nMatt Johnston [email protected]")); | 788 printf_P(PSTR("Pi Watchdog\nMatt Johnston [email protected]")); |
786 | 789 |
787 set_pi_boot_normal(0); | 790 set_pi_boot_normal(0); |
788 | 791 |
789 load_params(); | 792 load_params(); |
790 | 793 |
794 | 797 |
795 #if 0 | 798 #if 0 |
796 // encryption test | 799 // encryption test |
797 cmd_set_avr_key("1 6161626263636464656566666767686800000000"); | 800 cmd_set_avr_key("1 6161626263636464656566666767686800000000"); |
798 cmd_set_avr_key("2 7979757569696f6f646465656666717164646969"); | 801 cmd_set_avr_key("2 7979757569696f6f646465656666717164646969"); |
799 cmd_decrypt("1 ecd858ee07a8e16575723513d2d072a7565865e40ba302059bfc650d4491268448102119"); | 802 //cmd_decrypt("1 ecd858ee07a8e16575723513d2d072a7565865e40ba302059bfc650d4491268448102119"); |
803 cmd_decrypt("1 5a587b50fd48688bbda1b510cf9a3fab6fd4737b" "0ba302059bfc650d4491268448102119"); | |
804 cmd_hmac("2 7979757569696f6f646465656666717164646969"); | |
800 #endif | 805 #endif |
801 | 806 |
802 // doesn't return | 807 // doesn't return |
803 do_comms(); | 808 do_comms(); |
804 | 809 |