From bfac0f0eef1c956bf6fbc023708f17ecfda9b39d Mon Sep 17 00:00:00 2001 From: bg Date: Sat, 5 Apr 2008 17:57:46 +0000 Subject: [PATCH] make process changed and modularised --- Makefile | 115 ++++++++++++++++++++++++++++--------------- arcfour.mk | 12 +++++ avr-makefile.inc | 20 ++++++++ camellia.c | 21 ++++++-- camellia.mk | 13 +++++ cast5.mk | 11 +++++ des.mk | 11 +++++ main-camellia-test.c | 4 +- main-cast5-test.c | 4 +- main-des-test.c | 1 - main-serpent-test.c | 6 +-- main-shabea-test.c | 24 ++++++--- main.c | 10 ++-- nessie_bc_test.h | 5 ++ seed-asm.S | 2 +- seed.c | 8 +-- seed.mk | 12 +++++ serpent.mk | 13 +++++ shabea.c | 4 +- shabea.mk | 12 +++++ skipjack.mk | 12 +++++ tdes.mk | 11 +++++ xtea.mk | 12 +++++ 23 files changed, 270 insertions(+), 73 deletions(-) create mode 100644 arcfour.mk create mode 100644 avr-makefile.inc create mode 100644 camellia.mk create mode 100644 cast5.mk create mode 100644 des.mk create mode 100644 seed.mk create mode 100644 serpent.mk create mode 100644 shabea.mk create mode 100644 skipjack.mk create mode 100644 tdes.mk create mode 100644 xtea.mk diff --git a/Makefile b/Makefile index 3761ed5..fc63924 100644 --- a/Makefile +++ b/Makefile @@ -1,55 +1,82 @@ -PRG = serpent-test -#PRG = tdes-test -# camellia -# cryptotest -SERPENT_OBJ = main-serpent-test.o debug.o uart.o serial-tools.o serpent.o nessie_bc_test.o -CAMELLIA_OBJ = main-camellia-test.o debug.o uart.o serial-tools.o camellia.o camellia-asm.o -SKIPJACK_OBJ = main-skipjack-test.o debug.o uart.o serial-tools.o skipjack.o -SHA1_OBJ = main-sha1-test.o debug.o uart.o serial-tools.o sha1-asm.o -MD5_OBJ = main-md5-test.o debug.o uart.o serial-tools.o md5.o -CAST5_OBJ = main-cast5-test.o debug.o uart.o serial-tools.o cast5.o -RC6_OBJ = main-rc6-test.o debug.o uart.o serial-tools.o rc6.o -Multi_OBJ = main.o debug.o uart.o serial-tools.o sha256-asm.o xtea-asm.o arcfour-asm.o prng.o cast5.o -DES_OBJ = main-des-test.o debug.o uart.o serial-tools.o des.o -TDES_OBJ = main-tdes-test.o debug.o uart.o serial-tools.o des.o -SEED_OBJ = main-seed-test.o debug.o uart.o serial-tools.o seed.o seed-asm.o -SHABEA_OBJ = main-shabea-test.o debug.o uart.o serial-tools.o shabea.o sha256-asm.o - -OBJ = $(SERPENT_OBJ) -MCU_TARGET = atmega32 -OPTIMIZE = -Os - -FLASHCMD = avrdude -p $(MCU_TARGET) -P /dev/ttyUSB0 -c avr911 -U flash:w:$(PRG).hex -# -U eeprom:w:$(PRG)_eeprom.hex -#uisp -dprog=bsd -dlpt=/dev/parport1 --upload if=$(PRG).hex -ERASECMD = +# Makefile for the micro-crypt project +# author: Daniel Otte -DEFS = -LIBS = +BLOCK_CIPHERS = +STREAM_CIPHERS = +HASHES = -# You should not have to change anything below here. -CC = avr-gcc +include avr-makefile.inc +include *.mk -# Override is only needed by avr-lib build system. +ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) +ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS)) +ALGORITHMS_OBJ_IMM = $(foreach a, $(ALGORITHMS_OBJ), $($(a))) +ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS)) +ALGORITHMS_TEST_BIN_MAIN = $(foreach a, $(ALGORITHMS_TEST_BIN), $(firstword $($(a)))) +ALGORITHMS_TEST_BIN_MAIN_ELF = $(patsubst %.o, %.elf, $(ALGORITHMS_TEST_BIN_MAIN)) +ALGORITHMS_TEST_BIN_MAIN_HEX = $(patsubst %.o, %.hex, $(ALGORITHMS_TEST_BIN_MAIN)) -override CFLAGS = -pedantic -std=c99 -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) -$(DEFS) -override LDFLAGS = -Wl,-Map,$(PRG).map -override ASFLAGS = -mmcu=$(MCU_TARGET) +ALGORITHMS_TEST_BIN_IMM = $(foreach a, $(ALGORITHMS_TEST_BIN), $($(a))) +ALGORITHMS_NESSIE_TEST = $(patsubst %,%_NESSIE_TEST, $(ALGORITHMS)) +ALGORITHMS_PERFORMANCE_TEST = $(patsubst %,%_PERORMANCE_TEST, $(ALGORITHMS)) -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -all: $(PRG).elf lst text eeprom +PRG = serpent-test -$(PRG).elf: $(OBJ) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) +#SHA1_OBJ = main-sha1-test.o debug.o uart.o serial-tools.o sha1-asm.o +#MD5_OBJ = main-md5-test.o debug.o uart.o serial-tools.o md5.o -#rc6-test: +#Multi_OBJ = main.o debug.o uart.o serial-tools.o sha256-asm.o xtea-asm.o arcfour-asm.o prng.o cast5.o + +#OBJ = $(SERPENT_OBJ) + +DEFS = +LIBS = +define BLA_TEMPLATE2 +$(2): $(3) + echo $$@ + echo $$^ + $(CC) $(CFLAGS) $(LDFLAGS)$(patsubst %.elf,%.map,$(2)) -o \ + $(2) \ + $(3) \ + $(LIBS) +endef + +$(foreach algo, $(ALGORITHMS), $(eval $(call BLA_TEMPLATE2, $(algo), $(patsubst %.o,%.elf,$(firstword $($(algo)_TEST_BIN))), $($(algo)_TEST_BIN) ))) + +.PHONY: info +info: + echo $(ALGORITHMS_TEST_BIN_MAIN) + echo $(ALGORITHMS) + echo $(firstword $(XTEA_TEST_BIN)) + echo $(patsubst %.o,%.elf,$(firstword $(XTEA_TEST_BIN))) +# echo $(ALGORITHMS_OBJ) +# echo $(ALGORITHMS_OBJ_IMM) +# echo $(ALGORITHMS_TEST_BIN) +# echo $(ALGORITHMS_NESSIE_TEST) +# echo $(ALGORITHMS_PERFORMANCE_TEST) + +bc: $(ALGORITHMS_OBJ) + +tests: $(ALGORITHMS_TEST_BIN) \ + $(ALGORITHMS_TEST_BIN_MAIN_ELF) \ + $(ALGORITHMS_TEST_BIN_MAIN_HEX) + + +$(ALGORITHMS_OBJ): $(ALGORITHMS_OBJ_IMM) +$(ALGORITHMS_TEST_BIN): $(ALGORITHMS_TEST_BIN_IMM) + +$(ALGORITHMS): + +.PHONY: all +all: $(PRG).elf lst text eeprom + + +.PHONY: clean clean: - rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak + rm -rf *.o *.elf *.eps *.png *.pdf *.bak rm -rf *.lst *.map $(EXTRA_CLEAN_FILES) flash: @@ -95,6 +122,11 @@ esrec: $(PRG)_eeprom.srec %_eeprom.bin: %.elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ +%_size.txt: %.o + $(SIZE) $< > $@ + + + # Every thing below here is used by avr-libc's build system and can be ignored # by the casual user. @@ -107,6 +139,7 @@ eps: $(PRG).eps png: $(PRG).png pdf: $(PRG).pdf + %.eps: %.fig $(FIG2DEV) -L eps $< $@ diff --git a/arcfour.mk b/arcfour.mk new file mode 100644 index 0000000..611a649 --- /dev/null +++ b/arcfour.mk @@ -0,0 +1,12 @@ +# Makefile for ARCFOUR (RC4 compatible) +ALGO_NAME := ARCFOUR + +# comment out the following line for removement of ARCFOUR from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +$(ALGO_NAME)_OBJ := arcfour-asm.o +$(ALGO_NAME)_TEST_BIN := main.o debug.o uart.o serial-tools.o sha256-asm.o \ + xtea-asm.o arcfour-asm.o prng.o cast5.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/avr-makefile.inc b/avr-makefile.inc new file mode 100644 index 0000000..4db2606 --- /dev/null +++ b/avr-makefile.inc @@ -0,0 +1,20 @@ + +OBJ = $(SERPENT_OBJ) +MCU_TARGET = atmega32 +OPTIMIZE = -Os + +FLASHCMD = avrdude -p $(MCU_TARGET) -P /dev/ttyUSB0 -c avr911 -U flash:w:$(PRG).hex +# -U eeprom:w:$(PRG)_eeprom.hex +#uisp -dprog=bsd -dlpt=/dev/parport1 --upload if=$(PRG).hex +ERASECMD = + +CC = avr-gcc + +override CFLAGS = -pedantic -std=c99 -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) +$(DEFS) +override LDFLAGS = -Wl,-Map, +override ASFLAGS = -mmcu=$(MCU_TARGET) + +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size diff --git a/camellia.c b/camellia.c index 513c320..cfcd561 100644 --- a/camellia.c +++ b/camellia.c @@ -21,8 +21,8 @@ uint64_t camellia_fl(uint64_t x, uint64_t k); uint64_t camellia_fl_inv(uint64_t y, uint64_t k); /*****************************************************************************/ void change_endian(void* data, uint8_t length); - -uint64_t PROGMEM camellia_sigma[6]={ /* 64 byte table */ +/* +uint64_t PROGMEM camellia_sigma[6]={ / * 64 byte table * / 0xA09E667F3BCC908BLL, 0xB67AE8584CAA73B2LL, 0xC6EF372FE94F82BELL, @@ -30,10 +30,23 @@ uint64_t PROGMEM camellia_sigma[6]={ /* 64 byte table */ 0x10E527FADE682D1DLL, 0xB05688C2B3E6C1FDLL }; +*/ +uint32_t PROGMEM camellia_sigma[12]={ /* 64 byte table */ + 0x3BCC908BL, 0xA09E667FL, + 0x4CAA73B2L, 0xB67AE858L, + 0xE94F82BEL, 0xC6EF372FL, + 0xF1D36F1CL, 0x54FF53A5L, + 0xDE682D1DL, 0x10E527FAL, + 0xB3E6C1FDL, 0xB05688C2L +}; /* an ugly macro to load an entry form the table above */ -#define SIGMA(p) (( ((uint64_t)(pgm_read_dword((prog_uint32_t*)camellia_sigma+2*(p)+1)))<<32) + \ - ((uint64_t)(pgm_read_dword((prog_uint32_t*)camellia_sigma+2*(p)+0) )) ) +/* +#define SIGMA(p) (( ((uint64_t)(pgm_read_dword((prog_uint32_t*)camellia_sigma+2*(p)+1)))<<32) | \ + ((uint64_t)(pgm_read_dword((prog_uint32_t*)camellia_sigma+2*(p)+0))) ) +*/ +#define SIGMA(p) (( ((uint64_t)(pgm_read_dword(((prog_uint32_t*)camellia_sigma)[2*(p)+1])))<<32) | \ + ((uint64_t)(pgm_read_dword(((prog_uint32_t*)camellia_sigma)[2*(p)+0]))) ) diff --git a/camellia.mk b/camellia.mk new file mode 100644 index 0000000..f749184 --- /dev/null +++ b/camellia.mk @@ -0,0 +1,13 @@ +# Makefile for camellia +ALGO_NAME := CAMELLIA + +# comment out the following line for removement of serpent from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +# main-camellia-test.o debug.o uart.o serial-tools.o camellia.o camellia-asm.o +$(ALGO_NAME)_OBJ := camellia.o camellia-asm.o +$(ALGO_NAME)_TEST_BIN := main-camellia-test.o debug.o uart.o serial-tools.o \ + camellia.o camellia-asm.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/cast5.mk b/cast5.mk new file mode 100644 index 0000000..c5df6e5 --- /dev/null +++ b/cast5.mk @@ -0,0 +1,11 @@ +# Makefile for CAST5 +ALGO_NAME := CAST5 + +# comment out the following line for removement of CAST5 from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +$(ALGO_NAME)_OBJ := cast5.o +$(ALGO_NAME)_TEST_BIN := main-cast5-test.o debug.o uart.o serial-tools.o cast5.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/des.mk b/des.mk new file mode 100644 index 0000000..6e37b71 --- /dev/null +++ b/des.mk @@ -0,0 +1,11 @@ +# Makefile for DES +ALGO_NAME := DES + +# comment out the following line for removement of DES from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +$(ALGO_NAME)_OBJ := des.o +$(ALGO_NAME)_TEST_BIN := main-des-test.o debug.o uart.o serial-tools.o des.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/main-camellia-test.c b/main-camellia-test.c index f9848d7..649cf21 100644 --- a/main-camellia-test.c +++ b/main-camellia-test.c @@ -111,7 +111,7 @@ prog_uint8_t ntt_test_values_out[16] = { 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73, 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 }; - +/* memcmp_P() is now implemented in avr-libc int memcmp_P(const void *s1, PGM_P s2, size_t n){ uint8_t b; while(n--){ @@ -122,7 +122,7 @@ int memcmp_P(const void *s1, PGM_P s2, size_t n){ } return 0; } - +*/ void testrun_camellia(void){ /* we run the NESSIE test for Camellia here see * https://www.cosic.esat.kuleuven.be/nessie/testvectors/bc/camellia/Camellia-128-128.verified.test-vectors diff --git a/main-cast5-test.c b/main-cast5-test.c index 2da7c1d..9b3795a 100644 --- a/main-cast5-test.c +++ b/main-cast5-test.c @@ -77,8 +77,8 @@ void test_decrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){ void testrun_cast5(void){ uint8_t block[8]; uint8_t key[16]; - uint8_t *tda = "\x01\x23\x45\x67\x89\xAB\xCD\xEF", - *tka = "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A"; + uint8_t *tda = (uint8_t*)"\x01\x23\x45\x67\x89\xAB\xCD\xEF", + *tka = (uint8_t*)"\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A"; memcpy(block, tda, 8); memcpy(key, tka, 16); test_encrypt(block, key, 128, true); diff --git a/main-des-test.c b/main-des-test.c index 22a8942..22dee88 100644 --- a/main-des-test.c +++ b/main-des-test.c @@ -89,7 +89,6 @@ Set 8, vector# 0: encrypted=0011223344556677 */ void nessie_testdec(uint8_t* data, uint8_t* key){ - uint16_t i; uart_putstr("\r\n\t key = \t"); uart_hexdump(key, 8); uart_putstr("\r\n\t cipher = \t"); uart_hexdump(data, 8); des_decrypt(data,data,key); diff --git a/main-serpent-test.c b/main-serpent-test.c index 6e2ce8c..ed8cf70 100644 --- a/main-serpent-test.c +++ b/main-serpent-test.c @@ -28,9 +28,9 @@ void testrun_serpent(void){ nessie_ctx.keysize = 128; nessie_ctx.name = cipher_name; nessie_ctx.ctx_size_B = sizeof(serpent_ctx_t); - nessie_ctx.cipher_enc = serpent_enc; - nessie_ctx.cipher_dec = serpent_dec; - nessie_ctx.cipher_genctx = serpent_genctx_dummy; + nessie_ctx.cipher_enc = (nessie_enc_fpt)serpent_enc; + nessie_ctx.cipher_dec = (nessie_dec_fpt)serpent_dec; + nessie_ctx.cipher_genctx = (nessie_gen_fpt)serpent_genctx_dummy; nessie_run(); diff --git a/main-shabea-test.c b/main-shabea-test.c index 1fde509..fb9c87c 100644 --- a/main-shabea-test.c +++ b/main-shabea-test.c @@ -30,11 +30,11 @@ void testencrypt(uint8_t* block, uint8_t* key){ uart_putstr("\r\n==testy-encrypt==\r\n key: "); uart_hexdump(key,16); uart_putstr("\r\n plain: "); - uart_hexdump(block,16); + uart_hexdump(block,32); _delay_ms(50); - shabea128(block,key,128,1,16); + shabea256(block,key,128,1,16); uart_putstr("\r\n crypt: "); - uart_hexdump(block,16); + uart_hexdump(block,32); } void testdecrypt(uint8_t* block, uint8_t* key){ @@ -42,11 +42,11 @@ void testdecrypt(uint8_t* block, uint8_t* key){ uart_putstr("\r\n==testy-decrypt==\r\n key: "); uart_hexdump(key,16); uart_putstr("\r\n crypt: "); - uart_hexdump(block,16); + uart_hexdump(block,32); _delay_ms(50); - shabea128(block,key,128,0,16); + shabea256(block,key,128,0,16); uart_putstr("\r\n plain: "); - uart_hexdump(block,16); + uart_hexdump(block,32); } void testrun_shabea(void){ @@ -60,14 +60,22 @@ void testrun_shabea(void){ { 0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D, 0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,} }; - uint8_t datas[4][16]= + uint8_t datas[4][32]= { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, + 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D, + 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D }, { 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, + 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7, + 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 } }; uint8_t i=0; diff --git a/main.c b/main.c index ad0fda4..cc8a72f 100644 --- a/main.c +++ b/main.c @@ -148,28 +148,28 @@ void testrun_arcfour(void){ * RC4( "Secret", "Attack at dawn" ) == "45a01f64 5fc35b38 3552544b 9bf5" **/ uart_putstr("\r\narcfour(\"Plaintext\", \"Key\")="); - arcfour_init(&s, "Key", 3); + arcfour_init(&s, (uint8_t*)"Key", 3); b="Plaintext"; while (*b) *b++ ^= arcfour_gen(&s); uart_hexdump(b-9, 9); uart_putstr("\r\narcfour(\"pedia\", \"Wiki\")="); - arcfour_init(&s, "Wiki", 4); + arcfour_init(&s, (uint8_t*)"Wiki", 4); b="pedia"; while (*b) *b++ ^= arcfour_gen(&s); uart_hexdump(b-5, 5); uart_putstr("\r\narcfour(\"Attack at dawn\", \"Secret\")="); - arcfour_init(&s, "Secret", 6); + arcfour_init(&s, (uint8_t*)"Secret", 6); b="Attack at dawn"; while (*b) *b++ ^= arcfour_gen(&s); uart_hexdump(b-14, 14); uart_putstr("\r\narcfour(00.00.00.00.00.00.00.00, 01.23.45.67.89.AB.CD.EF)="); - arcfour_init(&s, "\x01\x23\x45\x67\x89\xAB\xCD\xEF", 8); + arcfour_init(&s, (uint8_t*)"\x01\x23\x45\x67\x89\xAB\xCD\xEF", 8); int i=0; uint8_t a[8]; memset(a, 0 , 8); @@ -193,7 +193,7 @@ void testrun_cast5(void){ cast5_ctx_t s; uint8_t i; uart_putstr("\r\nCAST5:\r\nkey: 01 23 45 67 34 56 78 23 45 67 89 34 56 78 9A"); - cast5_init(&s, "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A", 128); + cast5_init(&s, (uint8_t*)"\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A", 128); uint8_t block[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; uart_putstr("\r\nplaintext: "); uart_hexdump(block, 8); diff --git a/nessie_bc_test.h b/nessie_bc_test.h index b510810..ad5d44e 100644 --- a/nessie_bc_test.h +++ b/nessie_bc_test.h @@ -3,6 +3,11 @@ #include +typedef void (*nessie_gen_fpt)(uint8_t*, uint16_t, void*); +typedef void (*nessie_enc_fpt)(void*, void*); +typedef void (*nessie_dec_fpt)(void*, void*); + + typedef struct nessie_ctx_st{ uint16_t keysize; uint16_t blocksize_B; diff --git a/seed-asm.S b/seed-asm.S index 3f757d8..1c3c288 100644 --- a/seed-asm.S +++ b/seed-asm.S @@ -87,4 +87,4 @@ bigendian_sub32: - \ No newline at end of file + diff --git a/seed.c b/seed.c index 8568fdf..f0c3a85 100644 --- a/seed.c +++ b/seed.c @@ -49,9 +49,9 @@ uint32_t bigendian_sum32(uint32_t a, uint32_t b);/*{ changeendian32(&a); return a; } - +*/ /******************************************************************************/ -static +/* static */ uint32_t bigendian_sub32(uint32_t a, uint32_t b);/*{ changeendian32(&a); changeendian32(&b); @@ -59,7 +59,7 @@ uint32_t bigendian_sub32(uint32_t a, uint32_t b);/*{ changeendian32(&a); return a; } - +*/ /******************************************************************************/ static inline uint64_t bigendian_rotl8_64(uint64_t a){ @@ -144,6 +144,7 @@ keypair_t getnextkeys(uint32_t *keystate, uint8_t curround){ keypair_t ret; if (curround>15){ /* ERROR */ + ret.k0 = ret.k1 = 0; } else { /* ret.k0 = g_function(keystate[0] + keystate[2] - pgm_read_dword(&(seed_kc[curround]))); ret.k1 = g_function(keystate[1] - keystate[3] + pgm_read_dword(&(seed_kc[curround]))); */ @@ -172,6 +173,7 @@ keypair_t getprevkeys(uint32_t *keystate, uint8_t curround){ keypair_t ret; if (curround>15){ /* ERROR */ + ret.k0 = ret.k1 = 0; } else { if (curround & 1){ /* odd round (1,3,5, ..., 15) */ diff --git a/seed.mk b/seed.mk new file mode 100644 index 0000000..55ebd2f --- /dev/null +++ b/seed.mk @@ -0,0 +1,12 @@ +# Makefile for SEED +ALGO_NAME := SEED + +# comment out the following line for removement of SEED from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +$(ALGO_NAME)_OBJ := seed.o seed-asm.o +$(ALGO_NAME)_TEST_BIN := main-seed-test.o debug.o uart.o serial-tools.o \ + seed.o seed-asm.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/serpent.mk b/serpent.mk new file mode 100644 index 0000000..44d437c --- /dev/null +++ b/serpent.mk @@ -0,0 +1,13 @@ +# Makefile for serpent +ALGO_NAME := SERPENT + +# comment out the following line for removement of serpent from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + + +$(ALGO_NAME)_OBJ := serpent.o +$(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \ + serpent.o nessie_bc_test.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/shabea.c b/shabea.c index 844788a..e786139 100644 --- a/shabea.c +++ b/shabea.c @@ -39,13 +39,12 @@ void memxor(uint8_t * dest, uint8_t * src, uint8_t length){ #define R ((uint8_t*)block+16) void shabea256(void * block, void * key, uint16_t keysize, uint8_t enc, uint8_t rounds){ int8_t r; /**/ - uint8_t *tb; /**/ + uint8_t tb[HALFSIZEB+2+(keysize+7)/8]; /**/ uint16_t kbs; /* bytes used for the key / temporary block */ sha256_hash_t hash; r = (enc?0:(rounds-1)); kbs = (keysize+7)/8; - tb = malloc(HALFSIZEB+2+kbs); memcpy(tb+HALFSIZEB+2, key, kbs); /* copy key to temporary block */ tb[HALFSIZEB+0] = 0; /* set round counter high value to zero */ @@ -63,7 +62,6 @@ void shabea256(void * block, void * key, uint16_t keysize, uint8_t enc, uint8_t memxor(L, hash, HALFSIZE); } } - free(tb); } diff --git a/shabea.mk b/shabea.mk new file mode 100644 index 0000000..3f3cc40 --- /dev/null +++ b/shabea.mk @@ -0,0 +1,12 @@ +# Makefile for SHABEA +ALGO_NAME := SHABEA + +# comment out the following line for removement of SHABEA from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +$(ALGO_NAME)_OBJ := shabea.o sha256-asm.o +$(ALGO_NAME)_TEST_BIN := main-shabea-test.o debug.o uart.o serial-tools.o \ + shabea.o sha256-asm.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/skipjack.mk b/skipjack.mk new file mode 100644 index 0000000..f8475c3 --- /dev/null +++ b/skipjack.mk @@ -0,0 +1,12 @@ +# Makefile for SKIPJACK +ALGO_NAME := SKIPJACK + +# comment out the following line for removement of skipjack from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +$(ALGO_NAME)_OBJ := skipjack.o +$(ALGO_NAME)_TEST_BIN := main-skipjack-test.o debug.o uart.o serial-tools.o \ + skipjack.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/tdes.mk b/tdes.mk new file mode 100644 index 0000000..a015cce --- /dev/null +++ b/tdes.mk @@ -0,0 +1,11 @@ +# Makefile for triple-DES +ALGO_NAME := TDES + +# comment out the following line for removement of triple-DES from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +$(ALGO_NAME)_OBJ := des.o +$(ALGO_NAME)_TEST_BIN := main-tdes-test.o debug.o uart.o serial-tools.o des.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + diff --git a/xtea.mk b/xtea.mk new file mode 100644 index 0000000..8d35377 --- /dev/null +++ b/xtea.mk @@ -0,0 +1,12 @@ +# Makefile for XTEA +ALGO_NAME := XTEA + +# comment out the following line for removement of XTEA from the build process +BLOCK_CIPHERS := $(BLOCK_CIPHERS) $(ALGO_NAME) + +$(ALGO_NAME)_OBJ := xtea-asm.o +$(ALGO_NAME)_TEST_BIN := main.o debug.o uart.o serial-tools.o sha256-asm.o \ + xtea-asm.o arcfour-asm.o prng.o cast5.o +$(ALGO_NAME)_NESSIE_TEST := "nessie" +$(ALGO_NAME)_PEROFRMANCE_TEST := "performance" + -- 2.39.5