From 590263d215add9bba312b19f3f994df7a838aaa7 Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Sun, 8 Oct 2017 22:19:45 +0200 Subject: [PATCH] moved SHA-512 source files to src/optional There are 2 reasons behind this change: - The primary way to install Monocypher is to copy the source files into one's own project. But it wasn't clear whether `sha512.c` and `sha512.h` are meant to be copied as well. - Monocypher is advertised as a single source file library (or a 2 files library if you count the header), and a casual glance may disagree. Now things should be much clearer. --- I made another slight change to the vector generation process: I removed the optimisation options, which in conjunction with `-std=c99` seem to trigger a bug in GCC 5.4.0 (it can't find a type definition). Clang works. Those optimisation options slowed down the whole process anyway, so no loss there. --- makefile | 15 +++++++++------ src/{ => optional}/sha512.c | 0 src/{ => optional}/sha512.h | 0 tests/gen/makefile | 19 ++++++++++--------- 4 files changed, 19 insertions(+), 15 deletions(-) rename src/{ => optional}/sha512.c (100%) rename src/{ => optional}/sha512.h (100%) diff --git a/makefile b/makefile index 9e2194c..8bdd273 100644 --- a/makefile +++ b/makefile @@ -69,23 +69,26 @@ lib/libmonocypher.a: lib/monocypher.o lib/libmonocypher.so: lib/monocypher.o @mkdir -p $(@D) $(CC) $(CFLAGS) -shared -o $@ $^ -lib/%.o: src/%.c src/%.h +lib/sha512.o : src/optional/sha512.c src/optional/sha512.o +lib/monocypher.o: src/monocypher.c src/monocypher.h +lib/monocypher.o lib/sha512.o: @mkdir -p $(@D) - $(CC) $(CFLAGS) -I src -fPIC -c -o $@ $< + $(CC) $(CFLAGS) -I src -I src/optional -fPIC -c -o $@ $< # Test & speed libraries +$TEST_COMMON=tests/utils.h src/monocypher.h src/optional/sha512.h lib/utils.o: tests/utils.c tests/utils.h -lib/test.o : tests/test.c tests/utils.h src/monocypher.h src/sha512.h tests/vectors.h -lib/speed.o: tests/speed.c tests/utils.h src/monocypher.h src/sha512.h +lib/test.o : tests/test.c $(TEST_COMMON) tests/vectors.h +lib/speed.o: tests/speed.c $(TEST_COMMON) lib/utils.o lib/test.o lib/speed.o: @mkdir -p $(@D) - $(CC) $(CFLAGS) -I src -fPIC -c -o $@ $< + $(CC) $(CFLAGS) -I src -I src/optional -fPIC -c -o $@ $< # test & speed executables test.out : lib/test.o lib/monocypher.o lib/sha512.o lib/utils.o speed.out: lib/speed.o lib/monocypher.o lib/sha512.o lib/utils.o test.out speed.out: - $(CC) $(CFLAGS) -I src -o $@ $^ + $(CC) $(CFLAGS) -I src -I src/optional -o $@ $^ tests/vectors.h: @echo "" diff --git a/src/sha512.c b/src/optional/sha512.c similarity index 100% rename from src/sha512.c rename to src/optional/sha512.c diff --git a/src/sha512.h b/src/optional/sha512.h similarity index 100% rename from src/sha512.h rename to src/optional/sha512.h diff --git a/tests/gen/makefile b/tests/gen/makefile index e1bb1e4..e1ad0e9 100644 --- a/tests/gen/makefile +++ b/tests/gen/makefile @@ -1,6 +1,6 @@ CC=gcc -std=c99 -CFLAGS = -pedantic -Wall -Wextra -O3 -march=native +CFLAGS = -pedantic -Wall -Wextra HASH = #HASH=-DED25519_SHA512 @@ -12,7 +12,6 @@ VEC2 = $(patsubst %.vec, %.all.vec, $(VEC)) key_exchange.all.vec HEADERS = $(patsubst %.all.vec, %.h.vec, $(VEC2)) VECTORS = ../vectors.h - all: $(VECTORS) clean: @@ -23,10 +22,11 @@ clean: ./$< > $@ %.o: %.c ../utils.h ../ed25519-donna/ed25519.h - $(CC) $(CFLAGS) -c $< \ - -I .. \ - -I ../ed25519-donna \ - -I ../../src \ + $(CC) $(CFLAGS) -c $< \ + -I .. \ + -I ../ed25519-donna \ + -I ../../src \ + -I ../../src/optional \ $$(pkg-config --cflags libsodium) %.out: %.o monocypher.o utils.o ed25519.o @@ -39,16 +39,17 @@ utils.o: ../utils.c ../utils.h ed25519.o: ../ed25519-donna/ed25519.c $(wildcard ../ed25519-donna/*.h) $(CC) $(CFLAGS) -c $< \ -I ../../src \ + -I ../../src/optional \ $(HASH) \ -DED25519_CUSTOMHASH \ -DED25519_TEST \ -DED25519_NO_INLINE_ASM \ -DED25519_FORCE_32BIT -monocypher.o: ../../src/monocypher.c ../../src/monocypher.h -m_sha512.o : ../../src/sha512.c ../../src/sha512.h +monocypher.o: ../../src/monocypher.c ../../src/monocypher.h +m_sha512.o : ../../src/optional/sha512.c ../../src/optional/sha512.h monocypher.o m_sha512.o: - $(CC) $(CFLAGS) -c $< -I ../../src + $(CC) $(CFLAGS) -c $< -I ../../src -I ../../src/optional vector_to_header.out: ../vector_to_header.c $(CC) $(CFLAGS) $< -o $@ -- 2.47.3