diff --git a/Makefile b/Makefile index 5f1afe8..e8d0dd6 100644 --- a/Makefile +++ b/Makefile @@ -16,11 +16,11 @@ #------------------------------------------------------------------------- PROJNAME = main -OBJS = main.o sha1.o hmac.o trunc.o usbdrv/usbdrvasm.o usbdrv/usbdrv.o +OBJS = main.o sha1.o hmac.o trunc.o #usbdrv/usbdrvasm.o usbdrv/usbdrv.o # target architecture -MCU = attiny45 - +MCU = atmega168 +#MCU = attiny45 #------------------------------------------------------------------------- # macros for the tools #------------------------------------------------------------------------- diff --git a/debug.py b/debug.py index d05e6a5..af4f5fe 100755 --- a/debug.py +++ b/debug.py @@ -71,8 +71,8 @@ class SHA1 (object): for i in range(len(hexdigest) // 2)) #H(K XOR opad, H(K XOR ipad, text)) -k = b"\x0b"*20 + b"\x00"*(64-20) -text = b"Hi There" +k = b"\x4a\x65\x66\x65" + b"\x00"*(64-4) +text = b"what do ya want for nothing?" ipad=b"" opad=b"" for i in range(64): diff --git a/main.c b/main.c index 4b90c9b..29cd6b0 100644 --- a/main.c +++ b/main.c @@ -1,58 +1,53 @@ #include "main.h" -static uint8_t reportBuffer[64]; - -const PROGMEM char usbHidReportDescriptor[35] = { /* USB report descriptor */ - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) - 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x08, // REPORT_COUNT (8) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x08, // REPORT_SIZE (8) - 0x25, 0x65, // LOGICAL_MAXIMUM (101) - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0 // END_COLLECTION -}; - -usbMsgLen_t usbFunctionSetup(uchar data[8]) { - usbRequest_t *rq = (void *)data; - usbMsgPtr = reportBuffer; - if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* HID class request */ - if(rq->bRequest == USBRQ_HID_GET_REPORT) { /* wValue: ReportType (highbyte), ReportID (lowbyte) */ - /* since we have only one report type, we can ignore the report-ID */ - //buildReport(); - return sizeof(reportBuffer); - }/*else if(rq->bRequest == USBRQ_HID_GET_IDLE){ - usbMsgPtr = &idleRate; - return 1; - }else if(rq->bRequest == USBRQ_HID_SET_IDLE){ - idleRate = rq->wValue.bytes[1]; - }*/ - } else { - /* ignore vendor type requests, we don't use any */ +#define DEBUG + +#ifdef DEBUG +void tx( char data ){ + while ( !( UCSR0A & (1< +#include #define _PORT_BTN B #define _NUM_BTN 3 diff --git a/sha1.c b/sha1.c index dd61410..dd59a0c 100644 --- a/sha1.c +++ b/sha1.c @@ -19,14 +19,15 @@ #define K4 0xCA62C1D6 #define _LROT32(x,n) (( (uint32_t)(x) << n ) | ( (uint32_t)(x) >>(32-n) )) -#define _W(n) (n>=16 ? chunk_e[n-16] : chunk[n]) +#define _W(n) (n>=16 ? _sha1_chunk_e[n-16] : _sha1_chunk[n]) -static uint32_t chunk[16]; +uint32_t _sha1_chunk[16]; static uint8_t chunk_cnt; +uint32_t _sha1_chunk_e[64]; /*putting this here saves a lot of code space*/ void sha1_addbyte(uint8_t c){ - uint8_t* p=(uint8_t*)chunk; + uint8_t* p=(uint8_t*)_sha1_chunk; uint8_t i=(chunk_cnt & 0x03); /* chunk_cnt-i)+3-i deals with the endianess */ @@ -34,9 +35,9 @@ void sha1_addbyte(uint8_t c){ chunk_cnt++; if(chunk_cnt==64){ /*chunk extension*/ - uint32_t a,b,c,d,e,chunk_e[64]; + uint32_t a,b,c,d,e; for(i=0; i<64; ++i){ - chunk_e[i]= _LROT32( _W(i+16-3) ^ _W(i+16-8) ^ _W(i+16-14) ^ _W(i+16-16), 1 ); + _sha1_chunk_e[i]= _LROT32( _W(i+16-3) ^ _W(i+16-8) ^ _W(i+16-14) ^ _W(i+16-16), 1 ); } a=sha1_digest[4]; b=sha1_digest[3]; diff --git a/test.c b/test.c index 6a4f695..9606423 100644 --- a/test.c +++ b/test.c @@ -21,7 +21,7 @@ char sha1sum[41]; #define MSG1 "Hi There" #define SECRET2 {'J', 'e', 'f', 'e'}; -#define MSG2 "" +#define MSG2 "what do ya want for nothing?" int main(){ /*SHA1STR makro needs those two*/ @@ -53,14 +53,16 @@ int main(){ assert(strcmp("4d71043a68fa28b9592d1aa5748e5cd4291c0512",sha1sum)==0); char sec1[20]=SECRET1; - hmac(MSG1,8,sec,20); + hmac(MSG1,8,sec1,20); SHA1STR(); printf("HMAC: %s\n",sha1sum); assert(strcmp("b617318655057264e28bc0b6fb378c8ef146be00",sha1sum)==0); - char sec1[20]=SECRET2; - hmac(MSG2,8,sec,20); + char sec2[4]=SECRET2; + hmac(MSG2,28,sec2,4); SHA1STR(); printf("HMAC: %s\n",sha1sum); - //assert(strcmp("b617318655057264e28bc0b6fb378c8ef146be00",sha1sum)==0); + assert(strcmp("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",sha1sum)==0); + + }