From 52867acc0c7f09a79efbbb738cef0c3f5a2abb04 Mon Sep 17 00:00:00 2001 From: bg Date: Sun, 23 Oct 2011 15:49:06 +0200 Subject: [PATCH] update to stream-cipher mkfiles --- arm-makefile.inc_arm7tdmi | 69 ++++++++++++++++++++++++++++++++++++ hfal/hfal-hmac.c | 1 + mkfiles/arcfour_c.mk | 2 +- mkfiles/grain.mk | 2 +- mkfiles/mickey128.mk | 2 +- mkfiles/prf_tls12.mk | 6 ++-- mkfiles/rabbit_c.mk | 2 +- mkfiles/rabbit_estream_c.mk | 2 +- mkfiles/salsa20_c.mk | 2 +- mkfiles/trivium.mk | 2 +- mkfiles/zzz_lib.mk | 12 +++++-- prf_tls12/prf_tls12.h | 6 ++-- sha2/sha2_small_common.c | 12 +++---- test_src/main-bigint-test.c | 37 +++---------------- test_src/main-groestl-test.c | 8 ++--- test_src/main-rc6-test.c | 39 +++----------------- test_src/main-skein-test.c | 39 +++----------------- 17 files changed, 115 insertions(+), 128 deletions(-) create mode 100644 arm-makefile.inc_arm7tdmi diff --git a/arm-makefile.inc_arm7tdmi b/arm-makefile.inc_arm7tdmi new file mode 100644 index 0000000..e648810 --- /dev/null +++ b/arm-makefile.inc_arm7tdmi @@ -0,0 +1,69 @@ +TOOLCHAIN = arm-none-eabi-# +MCU_TARGET = arm7tdmi +MCU_OPTS = -marm +OPTIMIZE = -O0 -fomit-frame-pointer +DEBUG = -gdwarf-2 +WARNING = -pedantic -Wall -Wstrict-prototypes -Werror +DEFS = -D$(call uc, $(subst -,_,$(MCU_TARGET))) +FLASHCMD = $(OPENOCD) -f openocd.cfg \ + -c "init" \ + -c "halt" \ + -c "flash write_image erase $(1) 0 bin" \ + -c "reset run" \ + -c "shutdown" +DEP_DIR = deps/# +TEST_DIR = test/# +BIN_DIR = bin/# +TESTSRC_DIR = test_src/# +ERASECMD = +TESTPORT = /dev/ttyUSB1 +TESTPORTBAUDR = 115200 +TESTLOG_DIR = testlog/# +TESTPREFIX = nessie-# +SPEEDTOOL = host/get_performance.rb +SPEEDLOG_DIR = speed_log/# +SPEEDPREFIX = +SPEEDCMD = performance +SIZE_DIR = size_log/# +LIST_DIR = listings/# +STAT_DIR = stats/# +AUTOASM_DIR = autoasm/# +LIB_DIR = lib/# +LIB_NAME = libcrypto.a +AUTOASM_OPT = -S +CSTD = gnu99 +LIBS = c gcc + +COMMON_FLAGS = -ffunction-sections -fdata-sections \ + $(DEBUG) $(WARNING) -std=$(CSTD) $(OPTIMIZE) \ + -mcpu=$(MCU_TARGET) $(MCU_OPTS) $(DEFS) -MMD + +override CFLAGS_A = $(COMMON_FLAGS) \ + -MF$(DEP_DIR)$(patsubst %.o,%.d,$(notdir $(1))) +override CFLAGS = $(COMMON_FLAGS) \ + -MF$(DEP_DIR)$(patsubst %.o,%.d,$(notdir $@)) + +override LDFLAGS = -g -T lm3s9b90.ld -Wl,--gc-sections \ + -Wl,--entry=reset_isr \ + -Wl,-Map,# no space at the end + +override ASFLAGS = -mcpu=$(MCU_TARGET) + +SIZESTAT_FILE = sizestats.txt + +CC = $(TOOLCHAIN)gcc +OBJCOPY = $(TOOLCHAIN)objcopy +OBJDUMP = $(TOOLCHAIN)objdump +SIZE = $(TOOLCHAIN)size +OPENOCD = openocd +READELF = readelf +AR = $(TOOLCHAIN)ar +CHMOD = chmod +CHOWN = chown +CHGRP = chgrp +RM = rm +RUBY = ruby +GET_TEST = host/get_test.rb +MAKE = make +MAKE2GRAPH = ~/bin/make2graph.rb +TWOPI = twopi diff --git a/hfal/hfal-hmac.c b/hfal/hfal-hmac.c index 6f5fbf9..f271055 100644 --- a/hfal/hfal-hmac.c +++ b/hfal/hfal-hmac.c @@ -78,6 +78,7 @@ uint8_t hfal_hmac_ctxcopy(hfhmacgen_ctx_t* dest, hfhmacgen_ctx_t* src){ memcpy(dest->ctx, src->ctx, dest->desc->ctxsize_B); dest->finctx = malloc(dest->desc->ctxsize_B); if(dest->finctx == NULL){ + free(dest->ctx); return 1; } memcpy(dest->finctx, src->finctx, dest->desc->ctxsize_B); diff --git a/mkfiles/arcfour_c.mk b/mkfiles/arcfour_c.mk index fccca07..ff85f98 100644 --- a/mkfiles/arcfour_c.mk +++ b/mkfiles/arcfour_c.mk @@ -5,7 +5,7 @@ ALGO_NAME := ARCFOUR_C STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_DIR := arcfour/ -$(ALGO_NAME)_INCDIR := memxor/ scal/ +$(ALGO_NAME)_INCDIR := memxor/ bcal/ scal/ $(ALGO_NAME)_OBJ := arcfour.o $(ALGO_NAME)_TESTBIN := main-arcfour-test.o scal_arcfour.o $(CLI_STD) $(SCAL_STD) $(ALGO_NAME)_NESSIE_TEST := "nessie" diff --git a/mkfiles/grain.mk b/mkfiles/grain.mk index f513e4e..5e013e6 100644 --- a/mkfiles/grain.mk +++ b/mkfiles/grain.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_DIR := grain/ $(ALGO_NAME)_OBJ := grain.o -$(ALGO_NAME)_INCDIR := memxor/ scal/ +$(ALGO_NAME)_INCDIR := memxor/ bcal/ scal/ $(ALGO_NAME)_TESTBIN := main-grain-test.o $(CLI_STD) $(SCAL_STD) scal_grain.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PERFORMANCE_TEST := "performance" diff --git a/mkfiles/mickey128.mk b/mkfiles/mickey128.mk index fc0b1f4..87bc476 100644 --- a/mkfiles/mickey128.mk +++ b/mkfiles/mickey128.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_DIR := mickey128/ $(ALGO_NAME)_OBJ := mickey128.o -$(ALGO_NAME)_INCDIR := memxor/ scal/ +$(ALGO_NAME)_INCDIR := memxor/ bcal/ scal/ $(ALGO_NAME)_TESTBIN := main-mickey128-test.o $(CLI_STD) $(SCAL_STD) scal_mickey128.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PERFORMANCE_TEST := "performance" diff --git a/mkfiles/prf_tls12.mk b/mkfiles/prf_tls12.mk index d80c61e..f52b651 100644 --- a/mkfiles/prf_tls12.mk +++ b/mkfiles/prf_tls12.mk @@ -5,10 +5,10 @@ ALGO_NAME := PRF_TLS12 AUX += $(ALGO_NAME) $(ALGO_NAME)_DIR := prf_tls12/ -$(ALGO_NAME)_INCDIR := hmac/ sha512/ sha256/ hfal/ +$(ALGO_NAME)_INCDIR := hmac/ sha2/ hfal/ $(ALGO_NAME)_OBJ := prf_tls12.o -$(ALGO_NAME)_TESTBIN := main-prf_tls12-test.o $(CLI_STD) hfal_sha512.o hfal_sha256.o $(HFAL_STD) \ - sha256.o sha512.o hfal-hmac.o +$(ALGO_NAME)_TESTBIN := main-prf_tls12-test.o $(CLI_STD) $(HFAL_STD) sha224.o sha256.o sha384.o sha512.o \ + sha2_small_common.o sha2_large_common.o hfal_sha224.o hfal_sha256.o hfal_sha384.o hfal_sha512.o hfal-hmac.o $(ALGO_NAME)_PERFORMANCE_TEST := performance diff --git a/mkfiles/rabbit_c.mk b/mkfiles/rabbit_c.mk index bc19ac1..149a6ab 100644 --- a/mkfiles/rabbit_c.mk +++ b/mkfiles/rabbit_c.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_DIR := rabbit/ $(ALGO_NAME)_OBJ := rabbit_c.o -$(ALGO_NAME)_INCDIR := memxor/ scal/ +$(ALGO_NAME)_INCDIR := memxor/ bcal/ scal/ $(ALGO_NAME)_TESTBIN := main-rabbit-test.o $(CLI_STD) $(SCAL_STD) scal_rabbit.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PERFORMANCE_TEST := "performance" diff --git a/mkfiles/rabbit_estream_c.mk b/mkfiles/rabbit_estream_c.mk index 9277f67..51bc9c8 100644 --- a/mkfiles/rabbit_estream_c.mk +++ b/mkfiles/rabbit_estream_c.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_DIR := rabbit/ $(ALGO_NAME)_OBJ := rabbit_c.o -$(ALGO_NAME)_INCDIR := memxor/ scal/ +$(ALGO_NAME)_INCDIR := memxor/ bcal/ scal/ $(ALGO_NAME)_TESTBIN := main-rabbit-test.o $(CLI_STD) $(SCAL_STD) scal_rabbit.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PERFORMANCE_TEST := "performance" diff --git a/mkfiles/salsa20_c.mk b/mkfiles/salsa20_c.mk index 79169db..96a76bb 100644 --- a/mkfiles/salsa20_c.mk +++ b/mkfiles/salsa20_c.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_DIR := salsa20/ $(ALGO_NAME)_OBJ := salsa20.o -$(ALGO_NAME)_INCDIR := memxor/ scal/ +$(ALGO_NAME)_INCDIR := memxor/ bcal/ scal/ $(ALGO_NAME)_TESTBIN := main-salsa20-test.o $(CLI_STD) $(SCAL_STD) scal_salsa20.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PERFORMANCE_TEST := "performance" diff --git a/mkfiles/trivium.mk b/mkfiles/trivium.mk index 52c5317..64e3c7e 100644 --- a/mkfiles/trivium.mk +++ b/mkfiles/trivium.mk @@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_DIR := trivium/ $(ALGO_NAME)_OBJ := trivium.o -$(ALGO_NAME)_INCDIR := memxor/ scal/ +$(ALGO_NAME)_INCDIR := memxor/ bcal/ scal/ $(ALGO_NAME)_TESTBIN := main-trivium-test.o $(CLI_STD) $(SCAL_STD) scal_trivium.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PERFORMANCE_TEST := "performance" diff --git a/mkfiles/zzz_lib.mk b/mkfiles/zzz_lib.mk index 856a378..0fce0eb 100644 --- a/mkfiles/zzz_lib.mk +++ b/mkfiles/zzz_lib.mk @@ -4,7 +4,7 @@ LIB_ALGOS:= \ BASE64 \ BIGINT_C \ BLAKE_C \ - BMW \ + BMW_C \ CAST5 \ CAST6 \ CSCIPHER_SMALL_C \ @@ -20,6 +20,7 @@ LIB_ALGOS:= \ MICKEY128 \ NOEKEON_C \ PRESENT \ + PRF_TLS12 \ RABBIT_C \ RC5 \ RC6 \ @@ -27,7 +28,7 @@ LIB_ALGOS:= \ SEED_C \ SERPENT_BITSLICE \ SHA1_C \ - SHA256_C \ + SHA2_C \ SHABAL_C \ SKEIN_C \ TDES \ @@ -35,4 +36,9 @@ LIB_ALGOS:= \ XTEA_C \ HFAL_HMAC \ BCAL_BASIC \ - SCAL_BASIC + SCAL_BASIC \ + HFAL_ALGOS \ + BCAL_ALGOS \ + SCAL_ALGOS + + diff --git a/prf_tls12/prf_tls12.h b/prf_tls12/prf_tls12.h index dbd6938..e312f7e 100644 --- a/prf_tls12/prf_tls12.h +++ b/prf_tls12/prf_tls12.h @@ -21,9 +21,9 @@ #define PRF_TLS12_H_ #include -#include -#include -#include +#include "hashfunction_descriptor.h" +#include "hfal-basic.h" +#include "hfal-hmac.h" typedef struct{ hfhmacgen_ctx_t mainctx; diff --git a/sha2/sha2_small_common.c b/sha2/sha2_small_common.c index 7dad795..d650b28 100644 --- a/sha2/sha2_small_common.c +++ b/sha2/sha2_small_common.c @@ -51,9 +51,9 @@ uint32_t change_endian32(uint32_t x){ #define CH(x,y,z) (((x)&(y)) ^ ((~(x))&(z))) #define MAJ(x,y,z) (((x)&(y)) ^ ((x)&(z)) ^ ((y)&(z))) -#define SIGMA0(x) (rotr32((x),2) ^ rotr32((x),13) ^ rotl32((x),10)) -#define SIGMA1(x) (rotr32((x),6) ^ rotr32((x),11) ^ rotl32((x),7)) -#define SIGMA_a(x) (rotr32((x),7) ^ rotl32((x),14) ^ ((x)>>3)) +#define SIGMA_0(x) (rotr32((x), 2) ^ rotr32((x),13) ^ rotl32((x),10)) +#define SIGMA_1(x) (rotr32((x), 6) ^ rotr32((x),11) ^ rotl32((x),7)) +#define SIGMA_a(x) (rotr32((x), 7) ^ rotl32((x),14) ^ ((x)>>3)) #define SIGMA_b(x) (rotl32((x),15) ^ rotl32((x),13) ^ ((x)>>10)) const @@ -74,7 +74,7 @@ uint32_t k[]={ * block must be, 512, Bit = 64, Byte, long !!! */ void sha2_small_common_nextBlock (sha2_small_common_ctx_t *state, const void* block){ - uint32_t w[16], wx; /* this is 256, byte, large, */ + uint32_t w[16], wx; uint8_t i; uint32_t a[8],t1,t2; @@ -103,8 +103,8 @@ void sha2_small_common_nextBlock (sha2_small_common_ctx_t *state, const void* bl memmove(&(w[0]), &(w[1]), 15*4); w[15] = wx; } - t1 = a[7] + SIGMA1(a[4]) + CH(a[4],a[5],a[6]) + k[i] + wx; - t2 = SIGMA0(a[0]) + MAJ(a[0],a[1],a[2]); + t1 = a[7] + SIGMA_1(a[4]) + CH(a[4],a[5],a[6]) + k[i] + wx; + t2 = SIGMA_0(a[0]) + MAJ(a[0],a[1],a[2]); memmove(&(a[1]), &(a[0]), 7*4); /* a[7]=a[6]; a[6]=a[5]; a[5]=a[4]; a[4]=a[3]; a[3]=a[2]; a[2]=a[1]; a[1]=a[0]; */ a[4] += t1; a[0] = t1 + t2; diff --git a/test_src/main-bigint-test.c b/test_src/main-bigint-test.c index 4f4dfdc..ad14ab4 100644 --- a/test_src/main-bigint-test.c +++ b/test_src/main-bigint-test.c @@ -20,15 +20,7 @@ * bigint test-suit * */ -#include -#include -#include -#include "config.h" -#include "cli.h" -#include "dump.h" -#include "uart_lowlevel.h" -#include "sysclock.h" -#include "hw_gptm.h" +#include "main-test-common.h" #include "noekeon.h" #include "noekeon_prng.h" @@ -39,14 +31,6 @@ char* algo_name = "BigInt"; -void uart0_putc(char byte){ - uart_putc(UART_0, byte); -} - -char uart0_getc(void){ - return uart_getc(UART_0); -} - /***************************************************************************** * additional validation-functions * *****************************************************************************/ @@ -122,7 +106,7 @@ void test_add_scale_bigint(void){ cli_putstr("\r\nenter scale:"); { char str[8]; - cli_getsn_cecho(str, 7); + cli_getsn(str, 7); scale = atoi(str); } /* @@ -538,22 +522,9 @@ const cmdlist_entry_t cmdlist[] = { }; int main (void){ - sysclk_set_freq(SYS_FREQ); - sysclk_mosc_verify_enable(); - uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE); - gptm_set_timer_32periodic(TIMER0); - - cli_rx = uart0_getc; - cli_tx = uart0_putc; - + main_setup(); for(;;){ - cli_putstr("\r\n\r\nARM-Crypto-Lib VS ("); - cli_putstr(algo_name); - cli_putstr("; "); - cli_putstr(__DATE__); - cli_putc(' '); - cli_putstr(__TIME__); - cli_putstr(")\r\nloaded and running\r\n"); + welcome_msg(algo_name); cmd_interface(cmdlist); } } diff --git a/test_src/main-groestl-test.c b/test_src/main-groestl-test.c index 3ed2409..5720b52 100644 --- a/test_src/main-groestl-test.c +++ b/test_src/main-groestl-test.c @@ -69,19 +69,19 @@ const hfdesc_t* algolist[] = { void testrun_nessie_groestl(void){ hfal_nessie_multiple(algolist); } -void groestl224_test(void* msg, uint32_t length_b){ +void groestl224_test(const void* msg, uint32_t length_b){ hfal_test(&groestl224_desc, msg, length_b); } -void groestl256_test(void* msg, uint32_t length_b){ +void groestl256_test(const void* msg, uint32_t length_b){ hfal_test(&groestl256_desc, msg, length_b); } -void groestl384_test(void* msg, uint32_t length_b){ +void groestl384_test(const void* msg, uint32_t length_b){ hfal_test(&groestl384_desc, msg, length_b); } -void groestl512_test(void* msg, uint32_t length_b){ +void groestl512_test(const void* msg, uint32_t length_b){ hfal_test(&groestl512_desc, msg, length_b); } diff --git a/test_src/main-rc6-test.c b/test_src/main-rc6-test.c index 07b677c..95ae76d 100644 --- a/test_src/main-rc6-test.c +++ b/test_src/main-rc6-test.c @@ -21,15 +21,7 @@ * */ -#include -#include -#include -#include "config.h" -#include "cli.h" -#include "dump.h" -#include "uart_lowlevel.h" -#include "sysclock.h" -#include "hw_gptm.h" +#include "main-test-common.h" #include "rc6.h" #include "nessie_bc_test.h" @@ -37,21 +29,9 @@ #include "bcal-performance.h" #include "bcal_rc6.h" -#include -#include -#include - #define RC6_ROUNDS 20 char* algo_name = "RC6-32/20/16"; -void uart0_putc(char byte){ - uart_putc(UART_0, byte); -} - -char uart0_getc(void){ - return uart_getc(UART_0); -} - const bcdesc_t* algolist[] = { (bcdesc_t*)&rc6_desc, NULL @@ -103,21 +83,10 @@ const cmdlist_entry_t cmdlist[] = { }; int main (void){ - sysclk_set_freq(SYS_FREQ); - sysclk_mosc_verify_enable(); - uart_init_flow(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE, UART_FLOWCTRL_SOFT); - gptm_set_timer_32periodic(TIMER0); + main_setup(); - cli_rx = (cli_rx_fpt)uart0_getc; - cli_tx = (cli_tx_fpt)uart0_putc; for(;;){ - cli_putstr("\r\n\r\nARM-Crypto-Lib VS ("); - cli_putstr(algo_name); - cli_putstr("; "); - cli_putstr(__DATE__); - cli_putc(' '); - cli_putstr(__TIME__); - cli_putstr(")\r\nloaded and running\r\n"); - cmd_interface(cmdlist); + welcome_msg(algo_name); + cmd_interface(cmdlist); } } diff --git a/test_src/main-skein-test.c b/test_src/main-skein-test.c index b52fd43..4b9fdff 100644 --- a/test_src/main-skein-test.c +++ b/test_src/main-skein-test.c @@ -21,19 +21,12 @@ * */ -#include -#include -#include -#include "config.h" -#include "cli.h" -#include "dump.h" -#include "uart_lowlevel.h" -#include "sysclock.h" -#include "hw_gptm.h" +#include "main-test-common.h" #include "shavs.h" #include "nessie_hash_test.h" #include "performance_test.h" +#include "hfal-basic.h" #include "hfal-nessie.h" #include "hfal-performance.h" #include "hfal-test.h" @@ -43,15 +36,6 @@ #include "hfal_skein512.h" #include "hfal_skein1024.h" - -void uart0_putc(char byte){ - uart_putc(UART_0, byte); -} - -char uart0_getc(void){ - return uart_getc(UART_0); -} - const char* algo_name = "Skein"; const hfdesc_t* algolist[] = { @@ -284,26 +268,13 @@ cmdlist_entry_t cmdlist[] = { }; int main(void) { - sysclk_set_freq(SYS_FREQ); - sysclk_mosc_verify_enable(); - uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE); - gptm_set_timer_32periodic(TIMER0); - - cli_rx = uart0_getc; - cli_tx = uart0_putc; - + main_setup(); shavs_algolist=(hfdesc_t**)algolist; shavs_algo=(hfdesc_t*)&skein256_256_desc; for(;;){ - cli_putstr("\r\n\r\nARM-Crypto-Lib VS ("); - cli_putstr(algo_name); - cli_putstr("; "); - cli_putstr(__DATE__); - cli_putc(' '); - cli_putstr(__TIME__); - cli_putstr(")\r\nloaded and running\r\n"); - cmd_interface(cmdlist); + welcome_msg(algo_name); + cmd_interface(cmdlist); } }