small change in sha1

master
Stefan Krulj 14 years ago
parent 10d1a7d514
commit 502924ac8a
  1. 126
      Makefile
  2. 5
      sha1.c
  3. 22
      test.c

@ -0,0 +1,126 @@
#
# Targets:
# <none> generate flash file
# install generate flash
# download download flash
# check shows md5 and sha1 sum of uploaded code
# clean remove obj- and temporary files
#
# change PROJNAME for new projects
# add your object files to OBJS
#
#-------------------------------------------------------------------------
# project specific things
# change these definitions for new projects
#-------------------------------------------------------------------------
PROJNAME = main
OBJS = main.o sha1.o hmac.o trunc.o usbdrv/oddebug.o usbdrv/usbdrvasm.o usbdrv/usbdrv.o
# target architecture
MCU = attiny45
#-------------------------------------------------------------------------
# macros for the tools
#-------------------------------------------------------------------------
BAUD = 19200
BINFORMAT = ihex
# programmer format, this depends on programmer or bootloader you're using
#PROGFORMAT = dasa2
#PROGFORMAT = dapa
#PROGFORMAT = stk200
PROGFORMAT = usbtiny
#PROGFORMAT = stk500v2
# programmer-device-file
#IFCTYPE = /dev/ttyS0
#IFCTYPE = /dev/ttyS1
#IFCTYPE = /dev/ttyACM0
#IFCTYPE = /dev/ttyACM1
IFCTYPE = /dev/ttyUSB0
#IFCTYPE = /dev/ttyUSB1
# Tools
AS = avr-as
ASLD = avr-gcc -x assembler
LD = avr-ld
CC = avr-gcc
OBJCOPY = avr-objcopy
#PROGR = uisp
#PROGR = at16prog
#PROGR = lboot
PROGR = avrdude
INC=-Iusbdrv
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 \
$(filter %.lst, $(<:.c=.lst)))
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
#PRFLAGS = $(IFCTYPE) -dprog=$(PROGFORMAT) -dpart=$(MCU)
# avrdude
PRFLAGS = -F -p $(MCU) -P $(IFCTYPE) -c $(PROGFORMAT) -b $(BAUD)
#lboot
#PRFLAGS = -d $(IFCTYPE) -b $(BAUD)
#-------------------------------------------------------------------------
# the targets
#-------------------------------------------------------------------------
all: $(PROJNAME).hex $(PROJNAME).elf $(OBJS)
%.hex: %.elf
$(OBJCOPY) $(OCFLAGS) $< $@
@chmod ugo-x $@
%.elf: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LIBS) $(LDFLAGS) -o $@
%.o: %.c
$(CC) $(CFLAGS) -Wa,-a=$*.list -c -o $@ $<
# object from asm
.S.o :
$(CC) $(ASMFLAGS) -c $< -o $@
install: $(PROJNAME).hex
$(PROGR) $(PRFLAGS) -p $(PROJNAME).hex
#$(PROGR) $(PRFLAGS) -U flash:w:$(PROJNAME).hex
download: $(PROJNAME).down.hex
echo ""
$(PROJNAME).down.hex:
$(PROGR) $(PRFLAGS) -U flash:r:$(PROJNAME).down.hex:i
check:$(PROJNAME).down.hex $(PROJNAME).hex
$(PROGR) $(PRFLAGS) -v $(PROJNAME).hex
size: $(PROJNAME).hex
avr-size $(PROJNAME).elf
clean:
rm -f *.hex *.elf *.map *.list *.o *~ *.lst
rm -f usbdrv/*.o usbdrv/*.map usbdrv/*.list usbdrv/*~ usbdrv/*.lst
test: test.c sha1.c
gcc test.c sha1.c -o test

@ -20,13 +20,14 @@ static uint8_t chunk_cnt;
void sha1_addbyte(uint8_t c){
uint8_t* p=(uint8_t*)chunk;
uint8_t i;
p[chunk_cnt]=c;
p[(chunk_cnt&0xfc)+3-(chunk_cnt & 0x03)]=c;
chunk_cnt++;
if(chunk_cnt==64){
/*chunk extension*/
uint32_t a,b,c,d,e,chunk_e[64];
#ifdef TO_LITTLE_ENDIAN32
#ifdef TO_LITTLE_ENDIAN32asdas
for(i=0; i<16; i++){
chunk[i]=TO_LITTLE_ENDIAN32(chunk[i]);
//printf("%08x",chunk[i]);

@ -0,0 +1,22 @@
#include <stdio.h>
#include <assert.h>
#include "sha1.h"
char sha1sum[41];
int main(){
int i;
char* p;
sha1_init();
sha1_fill(0);
p=sha1sum;
for(i=0; i<20; ++i){
sprintf(p,"%02x", ((char*)(sha1_digest))[i] );
p+=2;
}
sprintf(sha1sum,"%x%x%x%x%x",sha1_digest[0],sha1_digest[1],sha1_digest[2],sha1_digest[3],sha1_digest[4]);
printf("SHA1: %s\n",sha1sum);
// assert(strncmp("da39a3ee5e6b4b0d3255bfef95601890afd80709",sha1sum)==0);
}
Loading…
Cancel
Save