]> git.codecow.com Git - Monocypher.git/commitdiff
Link SHA-512 code when using -DED25519_SHA512
authorLoup Vaillant <loup@loup-vaillant.fr>
Fri, 25 Jan 2019 14:43:02 +0000 (15:43 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Fri, 25 Jan 2019 14:54:53 +0000 (15:54 +0100)
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.

README.md
makefile

index 63604e51c3a249b0314a8a9bae5531ff866c474d..3cdda5c8f70d8d4b9cc33da1b5f6d1f329deb98a 100644 (file)
--- 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
index 9d165e48b9e0854f3122040a64af12418ebefe58..83a4bfafc0b16581d6f55409583e2680b45fa5b9 100644 (file)
--- 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