# HG changeset patch # User Matt Johnston # Date 1370444888 -28800 # Node ID 76f3ed943180e8000530f25443568da66cef622e # Parent ed8d308b4993b9dac1e1c2ea6317916428d47825 a few fixes diff -r ed8d308b4993 -r 76f3ed943180 main.c --- a/main.c Wed Jun 05 21:30:22 2013 +0800 +++ b/main.c Wed Jun 05 23:08:08 2013 +0800 @@ -51,7 +51,7 @@ // #define HAVE_UART_ECHO -// stores a value of clock_epoch combined with the remainder of TCNT2, +// stores a value of clock_epoch combined with the remainder of TCNT1, // for 1/32 second accuracy struct epoch_ticks { @@ -171,7 +171,7 @@ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { t->ticks = clock_epoch; - t->rem = TCNT2; + t->rem = TCNT1; } } @@ -186,8 +186,8 @@ //TCCR2A = _BV(COM2A1) | _BV(COM2A0) | _BV(WGM21); // toggle on match TCCR1A = _BV(COM1A0); - // systemclock/1024 - TCCR1B = _BV(CS12) | _BV(CS10); + // systemclock/64 + TCCR1B = _BV(CS11) | _BV(CS10); TCNT1 = 0; OCR1A = SLEEP_COMPARE; // interrupt @@ -414,15 +414,16 @@ static void cmd_hmac(const char *params) { - uint8_t data[HMACLEN]; + uint8_t indata[HMACLEN]; + uint8_t outdata[HMACLEN]; uint8_t key_index; - if (parse_key(params, &key_index, data, sizeof(data)) != 0) + if (parse_key(params, &key_index, indata, sizeof(indata)) != 0) { printf_P(PSTR("FAIL: Bad input\n")); return; } - if (key_index % 2 == 0) + if (key_index % 2 != 0) { printf_P(PSTR("Only hmac with even keys\n")); return; @@ -430,13 +431,10 @@ long_delay(200); - hmac_sha1_ctx_t ctx; - hmac_sha1_init(&ctx, avr_keys[key_index], KEYLEN); - hmac_sha1_lastBlock(&ctx, data, HMACLEN); - hmac_sha1_final(data, &ctx); + hmac_sha1(outdata, avr_keys[key_index], KEYLEN*8, indata, HMACLEN*8); printf_P(PSTR("HMAC: ")); - printhex(data, HMACLEN, stdout); + printhex(outdata, HMACLEN, stdout); fputc('\n', stdout); } @@ -452,7 +450,7 @@ return; } - if (key_index % 2) + if (key_index % 2 == 0) { printf_P(PSTR("Only decrypt with odd keys\n")); return; @@ -460,11 +458,9 @@ long_delay(200); + // check the signature - hmac_sha1_ctx_t ctx; - hmac_sha1_init(&ctx, avr_keys[key_index], KEYLEN); - hmac_sha1_lastBlock(&ctx, &data[HMACLEN], AESLEN); - hmac_sha1_final(output, &ctx); + hmac_sha1(output, avr_keys[key_index], KEYLEN*8, &data[HMACLEN], AESLEN*8); if (memcmp(output, data, HMACLEN) != 0) { printf_P(PSTR("FAIL: hmac mismatch\n"));