master
Stefan Krulj 14 years ago
parent 6ea60084a8
commit 36e0d976b6
  1. 29
      Makefile
  2. 4
      main.c
  3. 12
      sha1.c
  4. 1
      test.c

@ -16,7 +16,7 @@
#-------------------------------------------------------------------------
PROJNAME = main
OBJS = main.o sha1.o hmac.o trunc.o usbdrv/oddebug.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
@ -60,17 +60,26 @@ OPTLEVEL=s
# Flags
CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \
-DF_CPU=16500000 \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wstrict-prototypes \
-Wa,-ahlms=$(firstword \
-DF_CPU=16500000 \
-mcall-prologues \
-mtiny-stack \
-fno-jump-tables \
-fno-inline-functions \
-fno-inline-small-functions \
-fno-split-wide-types \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wstrict-prototypes \
-Wa,-ahlms=$(firstword \
--gc-sections \
--print-gc-sections \
$(filter %.lst, $(<:.c=.lst)))
ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \
-x assembler-with-cpp \
-DF_CPU=16500000 \
-Wa,-gstabs,-ahlms=$(firstword \
ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \
-x assembler-with-cpp \
-DF_CPU=16500000 \
-Wa,-gstabs,-ahlms=$(firstword \
$(<:.S=.lst) $(<.s=.lst))
LDFLAGS = -Wl,-Map=$*.map -mmcu=$(MCU)
OCFLAGS = -O $(BINFORMAT)
# at16prog

@ -46,7 +46,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
int main(void){
int main(void) __attribute__((noreturn));
int __attribute__((OS_main)) main(void) {
usbDeviceDisconnect();
_delay_ms(200);
usbDeviceConnect();
@ -55,6 +56,5 @@ int main(void){
for(;;){
}
return 0;
}

@ -20,17 +20,17 @@ static uint8_t chunk_cnt;
void sha1_addbyte(uint8_t c){
uint8_t* p=(uint8_t*)chunk;
uint8_t i;
uint8_t i=(chunk_cnt & 0x03);
p[(chunk_cnt&0xfc)+3-(chunk_cnt & 0x03)]=c;
p[(chunk_cnt-i)+3-i]=c;
chunk_cnt++;
if(chunk_cnt==64){
/*chunk extension*/
uint32_t a,b,c,d,e,chunk_e[64];
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 );
//chunk_e[i]= _LROT32( _W(i+16-3) ^ _W(i+16-8) ^ _W(i+16-14) ^ _W(i+16-16), 1 );
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];
c=sha1_digest[2];
@ -54,7 +54,7 @@ void sha1_addbyte(uint8_t c){
k=K4;
f=b ^ c ^ d;
}
temp = e + _LROT32(a,5) + f + k + _W(i);
temp = e + k + f + _LROT32(a,5) + _W(i);
e = d;
d = c;
c = _LROT32(b,30);
@ -87,7 +87,7 @@ void sha1_fill(int32_t len){
}
{
uint64_t l=len*8;
/*pay attention to the endiness here*/
//pay attention to the endiness here
sha1_addbyte( ((char*)(&l))[7]);
sha1_addbyte( ((char*)(&l))[6]);
sha1_addbyte( ((char*)(&l))[5]);

@ -4,6 +4,7 @@
#include <string.h>
#include "sha1.h"
#include "hmac.h"
char sha1sum[41];

Loading…
Cancel
Save