diff --git a/.gitignore b/.gitignore index b07cb253..f9db9dc7 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ doc/crypt.pdf doc/refman.pdf # *nix/windows test executables +ltc-* aesgcm aesgcm.exe constants diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 6979dc81..7de73093 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -3,79 +3,97 @@ # ----------------------------------------------------------------------------- option(BUILD_USEFUL_DEMOS "Build useful demos (hashsum)" FALSE) option(BUILD_USABLE_DEMOS "Build usable demos (crypt sizes constants pem-info)" FALSE) +option(BUILD_BROKEN_DEMOS "Build broken demos (aesgcm openssh-privkey openssl-enc timing)" FALSE) option(BUILD_TEST_DEMOS "Build test demos (small tv_gen)" FALSE) +option(INSTALL_DEMOS "Install enabled demos (USEFUL and/or USABLE) and ltc wrapper script" FALSE) +option(INSTALL_BROKEN_DEMOS "Install broken demos and ltc wrapper script" FALSE) + # ----------------------------------------------------------------------------- # Useful demos +# +# Demos that are even somehow useful and could be installed as a system-tool +# +# * USEFUL_DEMOS = hashsum # ----------------------------------------------------------------------------- if(BUILD_USEFUL_DEMOS) - - list(APPEND ALL_DEMOS_TARGETS hashsum) - - # hashsum - add_executable(hashsum ${CMAKE_CURRENT_SOURCE_DIR}/hashsum.c) - - target_link_libraries(hashsum PRIVATE ${PROJECT_NAME}) - + list(APPEND USABLE_DEMOS_TARGETS hashsum) endif() # ----------------------------------------------------------------------------- # Usable demos +# +# Demos that are usable but only rarely make sense to be installed +# +# USEABLE_DEMOS = crypt sizes constants pem-info # ----------------------------------------------------------------------------- if(BUILD_USABLE_DEMOS) + list(APPEND USABLE_DEMOS_TARGETS crypt sizes constants pem-info) +endif() - list(APPEND ALL_DEMOS_TARGETS crypt sizes constants pem-info) - - # ltcrypt - add_executable(crypt ${CMAKE_CURRENT_SOURCE_DIR}/crypt.c) - - target_link_libraries(crypt PRIVATE ${PROJECT_NAME}) - - # sizes - add_executable(sizes ${CMAKE_CURRENT_SOURCE_DIR}/sizes.c) - - target_link_libraries(sizes PRIVATE ${PROJECT_NAME}) - - # constants - add_executable(constants ${CMAKE_CURRENT_SOURCE_DIR}/constants.c) - - target_link_libraries(constants PRIVATE ${PROJECT_NAME}) - - # pem-info - add_executable(pem-info ${CMAKE_CURRENT_SOURCE_DIR}/pem-info.c) - - target_link_libraries(pem-info PRIVATE ${PROJECT_NAME}) +# ----------------------------------------------------------------------------- +# Broken demos +# +# Demos that are kind of useful, but in some way broken +# +# * aesgcm - can't be built with LTC_EASY +# * openssl-enc - can't be built with LTC_EASY +# * openssh-privkey - can't be built with LTC_EASY +# * timing - not really broken, but older gcc builds spit warnings +# +# BROKEN_DEMOS = aesgcm openssl-enc openssh-privkey timing +# ----------------------------------------------------------------------------- +if(BUILD_BROKEN_DEMOS AND INSTALL_BROKEN_DEMOS) + list(APPEND USABLE_DEMOS_TARGETS aesgcm openssh-privkey openssl-enc timing) +elseif(BUILD_BROKEN_DEMOS) + list(APPEND ALL_DEMOS_TARGETS aesgcm openssh-privkey openssl-enc timing) endif() # ----------------------------------------------------------------------------- # Test demos +# +# Demos that are used for testing or measuring +# +# * TEST_DEMOS = small tv_gen # ----------------------------------------------------------------------------- if(BUILD_TEST_DEMOS) - - list(APPEND ALL_DEMOS_TARGETS tv_gen) - - # small - add_executable(small ${CMAKE_CURRENT_SOURCE_DIR}/small.c) - - target_link_libraries(small PRIVATE ${PROJECT_NAME}) - - # tv_gen - add_executable(tv_gen ${CMAKE_CURRENT_SOURCE_DIR}/tv_gen.c) - - target_link_libraries(tv_gen PRIVATE ${PROJECT_NAME}) - + list(APPEND ALL_DEMOS_TARGETS small tv_gen) endif() +# ----------------------------------------------------------------------------- +# Generate executables +# ----------------------------------------------------------------------------- + +# USABLE_DEMOS can get installed, so they're prefixed with `ltc-` +foreach(target ${USABLE_DEMOS_TARGETS}) + list(APPEND ALL_DEMOS_INSTALL_TARGETS ltc-${target}) + + add_executable(ltc-${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c) + + target_link_libraries(ltc-${target} PRIVATE ${PROJECT_NAME}) +endforeach() + +foreach(target ${ALL_DEMOS_TARGETS}) + add_executable(${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c) + + target_link_libraries(${target} PRIVATE ${PROJECT_NAME}) +endforeach() + # ----------------------------------------------------------------------------- # Install targets # ----------------------------------------------------------------------------- -install( - TARGETS ${ALL_DEMOS_TARGETS} - COMPONENT "runtime" - EXPORT ${TARGETS_EXPORT_NAME} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} -) +if(INSTALL_DEMOS) + install( + TARGETS ${ALL_DEMOS_INSTALL_TARGETS} + COMPONENT "runtime" + EXPORT ${TARGETS_EXPORT_NAME} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + + # Also install the `ltc` wrapper script + install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/ltc DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/demos/ltc b/demos/ltc new file mode 100755 index 00000000..1182e3ae --- /dev/null +++ b/demos/ltc @@ -0,0 +1,34 @@ +#!/bin/sh + +RELDIR="/$0" +RELDIR="${RELDIR%/*}" +RELDIR="${RELDIR:-.}" +RELDIR="${RELDIR##/}/" + +BINDIR=`cd "$RELDIR"; pwd` + +err_out() { + err=$1 + shift + echo $* >&2 + exit $err +} + +usage() { + cat >&$(($1 + 1)) << EOF +Available commands are: +`ls -1 $BINDIR/ltc-* | sed "s@$BINDIR/ltc-@ @g"` + help +EOF + exit $1 +} + +[ $# -gt 0 ] || usage 1 + +TOOL="$1" +shift +[ "$TOOL" == "help" ] || [ "$TOOL" == "--help" ] || [ "$TOOL" == "-h" ] && usage 0 + +test -x "$BINDIR/ltc-$TOOL" || err_out 1 "Unknown command: $TOOL" + +[ $# -gt 0 ] && "$BINDIR/ltc-$TOOL" "$@" || "$BINDIR/ltc-$TOOL" diff --git a/makefile b/makefile index 3d9d218b..70d40d65 100644 --- a/makefile +++ b/makefile @@ -84,7 +84,7 @@ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1). ifneq ($V,1) @echo " * $${CC} $$@" ${silent_echo} endif - $${silent} $$(CC) $$(LTC_LDFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $(1) + $${silent} $$(CC) $$(LTC_LDFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $$@ endef $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) diff --git a/makefile.mingw b/makefile.mingw index dd5fd0ba..9de4f29b 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -321,9 +321,9 @@ install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include" #Install useful tools -install_bins: hashsum +install_bins: hashsum.exe cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin" - copy /Y hashsum.exe "$(PREFIX)\bin" + copy /Y hashsum.exe "$(PREFIX)\bin\ltc-hashsum.exe" #Install documentation install_docs: doc/crypt.pdf diff --git a/makefile.msvc b/makefile.msvc index 13ba47f5..e95a26cc 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -306,9 +306,9 @@ install: $(LIBMAIN_S) copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include" #Install useful tools -install_bins: hashsum +install_bins: hashsum.exe cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin" - copy /Y hashsum.exe "$(PREFIX)\bin" + copy /Y hashsum.exe "$(PREFIX)\bin\ltc-hashsum.exe" #Install documentation install_docs: doc/crypt.pdf diff --git a/makefile.shared b/makefile.shared index ae8f2370..5506219d 100644 --- a/makefile.shared +++ b/makefile.shared @@ -94,7 +94,7 @@ test: $(call print-help,test,Builds the library and the 'test' application to ru # build the demos from a template define DEMO_template $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME) - $$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1) + $$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $$@ endef $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) diff --git a/makefile.unix b/makefile.unix index e498209a..ba0b266c 100644 --- a/makefile.unix +++ b/makefile.unix @@ -336,7 +336,8 @@ install: $(LIBMAIN_S) #Install useful tools install_bins: hashsum @mkdir -p $(DESTDIR)$(BINPATH) - @cp hashsum $(DESTDIR)$(BINPATH)/ + @cp hashsum $(DESTDIR)$(BINPATH)/ltc-hashsum + @cp demos/ltc $(DESTDIR)$(BINPATH)/ltc #Install documentation install_docs: doc/crypt.pdf diff --git a/makefile_include.mk b/makefile_include.mk index 95076a74..233133be 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -82,6 +82,9 @@ endif ifneq ($(shell echo $(CFLAGS) | grep TFM_DESC),) LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I tomsfastmath) endif +ifneq ($(shell echo $(CFLAGS) | grep GMP_DESC),) +LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I gmp) +endif LTC_CFLAGS += -I./src/headers/ -DLTC_SOURCE -Wall -Wsign-compare -Wshadow ifdef OLD_GCC @@ -485,7 +488,8 @@ $(DESTDIR)$(BINPATH): install -p -d $(DESTDIR)$(BINPATH) .common_install_bins: $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH) - $(INSTALL_CMD) -p -m 775 $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH) + for d in $(USEFUL_DEMOS); do $(INSTALL_CMD) -p -m 775 $$d $(DESTDIR)$(BINPATH)/ltc-$$d + $(INSTALL_CMD) -p -m 775 demos/ltc $(DESTDIR)$(BINPATH) install_docs: $(call print-help,install_docs,Installs the Developer Manual) doc/crypt.pdf install -p -d $(DESTDIR)$(DATAPATH)