Mercurial > pihelp
comparison main.c @ 8:03da5ff767e9
Some debug ifdefs
Decrypt should use the next key for cli auth (Decrpyt is incorrect)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 06 Jun 2013 00:04:48 +0800 |
parents | 76f3ed943180 |
children | e83b35e864d7 |
comparison
equal
deleted
inserted
replaced
7:76f3ed943180 | 8:03da5ff767e9 |
---|---|
184 // COM21 COM20 Set OC2 on Compare Match (p116) | 184 // COM21 COM20 Set OC2 on Compare Match (p116) |
185 // WGM21 Clear counter on compare | 185 // WGM21 Clear counter on compare |
186 //TCCR2A = _BV(COM2A1) | _BV(COM2A0) | _BV(WGM21); | 186 //TCCR2A = _BV(COM2A1) | _BV(COM2A0) | _BV(WGM21); |
187 // toggle on match | 187 // toggle on match |
188 TCCR1A = _BV(COM1A0); | 188 TCCR1A = _BV(COM1A0); |
189 #ifdef SIM_DEBUG | |
190 // systemclock/8 | |
191 TCCR1B = _BV(CS11); | |
192 #else | |
189 // systemclock/64 | 193 // systemclock/64 |
190 TCCR1B = _BV(CS11) | _BV(CS10); | 194 TCCR1B = _BV(CS11) | _BV(CS10); |
195 #endif | |
191 TCNT1 = 0; | 196 TCNT1 = 0; |
192 OCR1A = SLEEP_COMPARE; | 197 OCR1A = SLEEP_COMPARE; |
193 // interrupt | 198 // interrupt |
194 TIMSK1 = _BV(OCIE1A); | 199 TIMSK1 = _BV(OCIE1A); |
195 } | 200 } |
406 if (parse_key(params, &key_index, new_key, sizeof(new_key)) != 0) | 411 if (parse_key(params, &key_index, new_key, sizeof(new_key)) != 0) |
407 { | 412 { |
408 return; | 413 return; |
409 } | 414 } |
410 memcpy(avr_keys[key_index], new_key, sizeof(new_key)); | 415 memcpy(avr_keys[key_index], new_key, sizeof(new_key)); |
416 #ifndef SIM_DEBUG | |
411 eeprom_write(avr_keys, avr_keys); | 417 eeprom_write(avr_keys, avr_keys); |
418 #endif | |
412 } | 419 } |
413 | 420 |
414 static void | 421 static void |
415 cmd_hmac(const char *params) | 422 cmd_hmac(const char *params) |
416 { | 423 { |
427 { | 434 { |
428 printf_P(PSTR("Only hmac with even keys\n")); | 435 printf_P(PSTR("Only hmac with even keys\n")); |
429 return; | 436 return; |
430 } | 437 } |
431 | 438 |
439 #ifndef SIM_DEBUG | |
432 long_delay(200); | 440 long_delay(200); |
441 #endif | |
433 | 442 |
434 hmac_sha1(outdata, avr_keys[key_index], KEYLEN*8, indata, HMACLEN*8); | 443 hmac_sha1(outdata, avr_keys[key_index], KEYLEN*8, indata, HMACLEN*8); |
435 | 444 |
436 printf_P(PSTR("HMAC: ")); | 445 printf_P(PSTR("HMAC: ")); |
437 printhex(outdata, HMACLEN, stdout); | 446 printhex(outdata, HMACLEN, stdout); |
454 { | 463 { |
455 printf_P(PSTR("Only decrypt with odd keys\n")); | 464 printf_P(PSTR("Only decrypt with odd keys\n")); |
456 return; | 465 return; |
457 } | 466 } |
458 | 467 |
468 #ifndef SIM_DEBUG | |
459 long_delay(200); | 469 long_delay(200); |
460 | 470 #endif |
461 | 471 |
462 // check the signature | 472 // check the signature |
463 hmac_sha1(output, avr_keys[key_index], KEYLEN*8, &data[HMACLEN], AESLEN*8); | 473 hmac_sha1(output, avr_keys[key_index+1], KEYLEN*8, &data[HMACLEN], AESLEN*8); |
464 | 474 |
465 if (memcmp(output, data, HMACLEN) != 0) { | 475 if (memcmp(output, data, HMACLEN) != 0) { |
466 printf_P(PSTR("FAIL: hmac mismatch\n")); | 476 printf_P(PSTR("FAIL: hmac mismatch\n")); |
467 } | 477 } |
468 | 478 |
790 | 800 |
791 setup_tick_counter(); | 801 setup_tick_counter(); |
792 | 802 |
793 sei(); | 803 sei(); |
794 | 804 |
805 #if 0 | |
806 // encryption test | |
807 cmd_set_avr_key("1 6161626263636464656566666767686800000000"); | |
808 cmd_set_avr_key("2 7979757569696f6f646465656666717164646969"); | |
809 cmd_decrypt("1 ecd858ee07a8e16575723513d2d072a7565865e40ba302059bfc650d4491268448102119"); | |
810 #endif | |
811 | |
795 // doesn't return | 812 // doesn't return |
796 do_comms(); | 813 do_comms(); |
797 | 814 |
798 return 0; /* never reached */ | 815 return 0; /* never reached */ |
799 } | 816 } |