From: Loup Vaillant Date: Fri, 25 Jan 2019 14:43:02 +0000 (+0100) Subject: Link SHA-512 code when using -DED25519_SHA512 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=1094802ef4ed0c1a9429be5a3e8ef487aa62bee4;p=Monocypher.git Link SHA-512 code when using -DED25519_SHA512 When the $CFLAGS variable contains the -DED25519_SHA512 option (by default it doesn't), the code from src/optional/sha512.c is automatically linked to the final libraries (libmonocypher.a and libmonocypher.so). That way, users who need to install a ED25519 compliant version of Monocypher can do so simply by altering the compilation options with the $CFLAGS variable. --- diff --git a/README.md b/README.md index 63604e5..3cdda5c 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,11 @@ signatures. The default is EdDSA with Curve25519 and Blake2b. Activating the option replaces it by Ed25519 (EdDSA with Curve25519 and SHA-512). When this option is activated, you will need to link the final program with a suitable SHA-512 implementation. You can use the -`sha512.c` and `sha512.h` files provided in `src/optional`. +`sha512.c` and `sha512.h` files provided in `src/optional`. The +makefile does this linking automatically whenever the `$CFLAGS` variable +contains the `-DED25519_SHA512` option. For instance: + + $ make CFLAGS="-O2 -DED25519_SHA512" The `-DBLAKE2_NO_UNROLLING` option is a performance tweak. By default, Monocypher unrolls the Blake2b inner loop, because it is over 25% faster diff --git a/makefile b/makefile index 9d165e4..83a4bfa 100644 --- a/makefile +++ b/makefile @@ -8,6 +8,12 @@ MAN_DIR=$(DESTDIR)/$(PREFIX)/share/man/man3 TARBALL_VERSION=$$(cat VERSION.md) TARBALL_DIR=. +ifeq ($(findstring -DED25519_SHA512, $(CFLAGS)),) +LINK_SHA512= +else +LINK_SHA512=lib/sha512.o +endif + .PHONY: all library static-library dynamic-library \ install install-doc \ check test speed \ @@ -63,12 +69,12 @@ test speed speed-sodium speed-tweetnacl: ./$< # Monocypher libraries -lib/libmonocypher.a: lib/monocypher.o +lib/libmonocypher.a: lib/monocypher.o $(LINK_SHA512) ar cr $@ $^ lib/libmonocypher.so: lib/libmonocypher.so.2 @mkdir -p $(@D) ln -s $$(basename $<) $@ -lib/libmonocypher.so.2: lib/monocypher.o +lib/libmonocypher.so.2: lib/monocypher.o $(LINK_SHA512) @mkdir -p $(@D) $(CC) $(CFLAGS) -shared -o $@ $^ lib/sha512.o : src/optional/sha512.c src/optional/sha512.h