From: bg Date: Fri, 19 Aug 2011 00:36:30 +0000 (+0200) Subject: added basic library creation support X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=fd1c99357bf0017ed46b843ff8be8d67ad8415ee;p=arm-crypto-lib.git added basic library creation support --- diff --git a/Makefile b/Makefile index b980159..6f2efd1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Makefile for the ARM-Crypto-Lib project # -# This file is part of the AVR-Crypto-Lib. +# This file is part of the ARM-Crypto-Lib. # Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) # # This program is free software: you can redistribute it and/or modify @@ -27,7 +27,7 @@ ENCODINGS := SIGNATURE := PK_CIPHERS := AUX := - +LIB_ALGOS := # we use the gnu make standard library include gmsl @@ -40,18 +40,50 @@ GLOBAL_INCDIR := ./ $(TESTSRC_DIR) # inclusion of make stubs include mkfiles/*.mk +define Assert_Template +$(1) = $(2) +endef + +define Add_Template +$(1) += $(2) +endef + #------------------------------------------------------------------------------- ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \ $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX) ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS)) -ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS)) +ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS)) + +LIB_OBJECTS := +LIB_SRCDIRS := +LIB_DEFINES := + +$(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \ + LIB_OBJECTS, \ + $($(a)_OBJ) \ +))) +LIB_OBJECTS := $(addprefix $(BIN_DIR)$(LIB_DIR), $(sort $(LIB_OBJECTS))) + +$(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \ + LIB_SRCDIRS, \ + $($(a)_DIR) \ +))) + +$(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \ + LIB_SRCDIRS, \ + $($(a)_INCDIR) \ +))) +LIB_SRCDIRS := $(sort $(LIB_SRCDIRS)) + +$(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \ + LIB_DEFINES, \ + $($(a)_DEF) \ +))) +LIB_DEFINES := $(sort $(LIB_DEFINES)) + #------------------------------------------------------------------------------- # define binary object in $(BIN_DIR)$(ALGO)/ -define Assert_Template -$(1) = $(2) -endef - $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ $(a)_BINOBJ, \ $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \ @@ -59,7 +91,7 @@ $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ $(a)_TESTBINOBJ, \ - $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \ + $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \ ))) @@ -100,7 +132,7 @@ $(foreach a, $(ALGORITHMS), \ ) $(foreach a, $(ALGORITHMS), \ - $(foreach b, $($(a)_TEST_BIN), \ + $(foreach b, $($(a)_TESTBIN), \ $(eval $(call TargetSource_Template, \ $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \ $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\ @@ -110,15 +142,26 @@ $(foreach a, $(ALGORITHMS), \ ) \ ) +$(foreach a, $(LIB_OBJECTS), \ + $(eval $(call TargetSource_Template, \ + $(a), \ + $(call find_source_file, $(notdir $(a)), $(LIB_SRCDIRS) ),\ + $(LIB_SRCDIRS) $(GLOBAL_INCDIR), \ + $(LIB_DEFINES) \ + ) \ + ) \ +) + #------------------------------------------------------------------------------- define MainTestElf_Template $(1): $(2) $(3) @echo "[ld]: $(1)" - @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \ + @mkdir -p $(dir $(1)) + $(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \ $(1) \ $(2) $(3) \ - $(LIBS) + $(addprefix -l, $(LIBS)) endef $(foreach a, $(ALGORITHMS), \ @@ -205,7 +248,7 @@ blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE) #------------------------------------------------------------------------------- .PHONY: tests -tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN) +tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN) #------------------------------------------------------------------------------- @@ -257,6 +300,31 @@ encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ) aux: $(foreach algo, $(AUX), $(algo)_OBJ) + + +.PHONY: lib_info +lib_info: + @echo "LIB_ALGOS =" + @echo $(foreach a, $(LIB_ALGOS), '\t$(a)\n') + @echo "LIB_OBJECTS =" + @echo $(foreach a, $(LIB_OBJECTS), '\t$(a)\n') + @echo "LIB_SRCDIRS =" + @echo $(foreach a, $(LIB_SRCDIRS), '\t$(a)\n') + +$(BIN_DIR)$(LIB_DIR)$(LIB_NAME): $(LIB_OBJECTS) + @echo "[rm]: old $@" + @$(RM) -f $@ + @echo "[chmod]: " + @$(CHMOD) 644 $^ +# $(CHGRP) root $^ +# $(CHOWN) root $^ + @echo "[ar]: $@ <-- " + @$(AR) qc $@ $^ + +.PHONY: lib +lib: $(BIN_DIR)$(LIB_DIR)$(LIB_NAME) + + #------------------------------------------------------------------------------- @@ -286,6 +354,7 @@ info: @echo " targets:" @echo " all - all algorithm cores" @echo " cores - all algorithm cores" + @echo " lib - make library archive" @echo " listings - all algorithm core listings" @echo " tests - all algorithm test programs" @echo " stats - all algorithm size statistics" @@ -313,11 +382,13 @@ info: .PHONY: clean clean: - rm -rf $(BIN_DIR)* + @echo "[rm]: $(BIN_DIR)*" + @$(RM) -rf $(BIN_DIR)* .PHONY: depclean depclean: clean - rm -f $(DEP_DIR)*.d + @echo "[rm]: $(DEP_DIR)*.d" + @$(RM) -f $(DEP_DIR)*.d #------------------------------------------------------------------------------- # dependency inclusion diff --git a/arm-makefile.inc b/arm-makefile.inc index fe5f5dc..e565ddc 100644 --- a/arm-makefile.inc +++ b/arm-makefile.inc @@ -1,6 +1,7 @@ TOOLCHAIN = arm-none-eabi-# MCU_TARGET = cortex-m3 -OPTIMIZE = -O0 +MCU_OPTS = -mthumb +OPTIMIZE = -O0 -fomit-frame-pointer DEBUG = -gdwarf-2 WARNING = -pedantic -Wall -Wstrict-prototypes -Werror DEFS = -D$(call uc, $(subst -,_,$(MCU_TARGET))) @@ -10,50 +11,57 @@ FLASHCMD = $(OPENOCD) -f openocd.cfg \ -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/ +DEP_DIR = deps/# +TEST_DIR = test/# +BIN_DIR = bin/# +TESTSRC_DIR = test_src/# ERASECMD = TESTPORT = /dev/ttyUSB1 TESTPORTBAUDR = 115200 TESTLOG_DIR = testlog/# -TESTPREFIX = nessie- +TESTPREFIX = nessie-# SPEEDTOOL = host/get_performance.rb -SPEEDLOG_DIR = speed_log/ +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 -CC = $(TOOLCHAIN)gcc CSTD = gnu99 +LIBS = c gcc -override CFLAGS_A = -fomit-frame-pointer \ - -mthumb -ffunction-sections -fdata-sections -MMD \ - -MF$(DEP_DIR)$(patsubst %.o,%.d,$(notdir $(1))) \ - $(DEBUG) $(WARNING) -std=$(CSTD) $(OPTIMIZE) \ - -mcpu=$(MCU_TARGET) $(DEFS) -override CFLAGS = -fomit-frame-pointer \ - -mthumb -ffunction-sections -fdata-sections -MMD \ - -MF$(DEP_DIR)$(patsubst %.o,%.d,$(notdir $@)) \ - $(DEBUG) $(WARNING) -std=$(CSTD) $(OPTIMIZE) \ - -mcpu=$(MCU_TARGET) $(DEFS) +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 -lc -lgcc \ - -Wl,-Map,# no space at the end + -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 diff --git a/des/des.c b/des/des.c index f7b9952..0a27503 100644 --- a/des/des.c +++ b/des/des.c @@ -202,10 +202,9 @@ const uint8_t shiftkeyinv_permtab[] = { #define ROTTABLE_INV 0x3F7E /******************************************************************************/ -void permute(uint8_t *ptable, const uint8_t *in, uint8_t *out){ - uint8_t ib, ob; /* in-bytes and out-bytes */ +void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out){ + uint8_t ob; /* in-bytes and out-bytes */ uint8_t byte, bit; /* counter for bit and byte */ - ib = ptable[0]; ob = ptable[1]; ptable = &(ptable[2]); for(byte=0; byte