]> git.codecow.com Git - Monocypher.git/commitdiff
Moved speed tests out of the main Makefile
authorLoup Vaillant <loup@loup-vaillant.fr>
Sun, 19 Feb 2023 17:17:53 +0000 (18:17 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Sun, 19 Feb 2023 17:17:53 +0000 (18:17 +0100)
makefile
tests/speed/makefile [new file with mode: 0644]

index 54ad35261c41ad6baf3e0238300ed979d1abfc0a..b1086301da1b35f39aa73bf3a779c2cee7a487dc 100644 (file)
--- a/makefile
+++ b/makefile
@@ -49,7 +49,7 @@
 # You should have received a copy of the CC0 Public Domain Dedication along
 # with this software.  If not, see
 # <https://creativecommons.org/publicdomain/zero/1.0/>
-CC=gcc -std=gnu99 # speed tests don't work with -std=cxx, they need the POSIX extensions
+CC=gcc -std=c99
 CFLAGS= -pedantic -Wall -Wextra -O3 -march=native
 DESTDIR=
 PREFIX=usr/local
@@ -59,17 +59,32 @@ PKGCONFIGDIR=$(LIBDIR)/pkgconfig
 MANDIR=$(PREFIX)/share/man/man3
 SONAME=libmonocypher.so.3
 
-VERSION=__git__
-
-.PHONY: all library static-library dynamic-library                     \
-        install install-doc pkg-config-libhydrogen                     \
-        check test tis-ci ctgrind                                      \
-        speed speed-sodium speed-tweetnacl speed-hydrogen speed-c25519 \
-        speed-donna                                                    \
-        clean uninstall                                                \
-        dist
+.PHONY: all library static-library dynamic-library  \
+        install install-doc                         \
+        check test tis-ci ctgrind                   \
+        clean uninstall dist
 
+##################
+## Main targets ##
+##################
 all    : library
+check  : test
+
+test   : test.out
+tis-ci : tis-ci.out
+ctgrind: ctgrind.out
+test tis-ci:
+       ./$<
+ctgrind:
+       valgrind ./$<
+
+clean:
+       rm -rf lib/
+       rm -f  *.out
+
+#############
+## Install ##
+#############
 install: library src/monocypher.h monocypher.pc install-doc
        mkdir -p $(DESTDIR)/$(INCLUDEDIR)
        mkdir -p $(DESTDIR)/$(LIBDIR)
@@ -84,19 +99,6 @@ install-doc:
        mkdir -p $(DESTDIR)/$(MANDIR)
        cp -PR doc/man3/*.3monocypher $(DESTDIR)/$(MANDIR)
 
-pkg-config-libhydrogen:
-       mkdir -p $(DESTDIR)/$(PKGCONFIGDIR)
-       sed "s|PREFIX|$(PREFIX)|" tests/speed/libhydrogen.pc \
-            > $(DESTDIR)/$(PKGCONFIGDIR)/libhydrogen.pc
-
-library: static-library dynamic-library
-static-library : lib/libmonocypher.a
-dynamic-library: lib/libmonocypher.so lib/$(SONAME)
-
-clean:
-       rm -rf lib/
-       rm -f  *.out
-
 uninstall:
        rm -f $(DESTDIR)/$(LIBDIR)/libmonocypher.a
        rm -f $(DESTDIR)/$(LIBDIR)/libmonocypher.so*
@@ -105,24 +107,13 @@ uninstall:
        rm -f $(DESTDIR)/$(PKGCONFIGDIR)/monocypher.pc
        rm -f $(DESTDIR)/$(MANDIR)/*.3monocypher
 
-check: test
-test           : test.out
-tis-ci         : tis-ci.out
-speed          : speed.out
-speed-sodium   : speed-sodium.out
-speed-tweetnacl: speed-tweetnacl.out
-speed-hydrogen : speed-hydrogen.out
-speed-c25519   : speed-c25519.out
-speed-donna    : speed-donna.out
-test tis-ci:
-       ./$<
-speed speed-sodium speed-tweetnacl speed-hydrogen speed-c25519 speed-donna:
-       ./$<
-
-ctgrind: ctgrind.out
-       valgrind ./ctgrind.out
+##################
+## Main library ##
+##################
+library: static-library dynamic-library
+static-library : lib/libmonocypher.a
+dynamic-library: lib/libmonocypher.so lib/$(SONAME)
 
-# Monocypher libraries
 lib/libmonocypher.a: lib/monocypher.o lib/monocypher-ed25519.o
        $(AR) cr $@ $^
 lib/libmonocypher.so: lib/$(SONAME)
@@ -133,118 +124,42 @@ lib/$(SONAME): lib/monocypher.o lib/monocypher-ed25519.o
        $(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(SONAME) -o $@ $^
 lib/monocypher-ed25519.o: src/optional/monocypher-ed25519.c \
                           src/optional/monocypher-ed25519.h
-lib/chacha20.o  : src/deprecated/chacha20.c  src/deprecated/chacha20.h
-lib/aead-incr.o : src/deprecated/aead-incr.c src/deprecated/aead-incr.h
 lib/monocypher.o: src/monocypher.c src/monocypher.h
-lib/monocypher.o lib/monocypher-ed25519.o lib/chacha20.o lib/aead-incr.o:
+lib/monocypher.o lib/monocypher-ed25519.o:
        @mkdir -p $(@D)
        $(CC) $(CFLAGS) -I src -I src/optional -fPIC -c -o $@ $<
 
-# Test & speed libraries
+
+####################
+## Test libraries ##
+####################
 TEST_COMMON = tests/utils.h src/monocypher.h src/optional/monocypher-ed25519.h
-SPEED       = tests/speed
-lib/utils.o          :tests/utils.c
-lib/tis-ci.o         :tests/tis-ci.c      $(TEST_COMMON) tests/tis-ci-vectors.h
-lib/test.o           :tests/test.c               $(TEST_COMMON) tests/vectors.h
-lib/ctgrind.o        :tests/ctgrind.c            $(TEST_COMMON)
-lib/speed.o          :$(SPEED)/speed.c           $(TEST_COMMON) $(SPEED)/speed.h
-lib/speed-tweetnacl.o:$(SPEED)/speed-tweetnacl.c $(TEST_COMMON) $(SPEED)/speed.h
-lib/utils.o lib/test.o lib/tis-ci.o lib/speed.o:
+lib/utils.o  : tests/utils.c
+lib/tis-ci.o : tests/tis-ci.c  $(TEST_COMMON) tests/tis-ci-vectors.h
+lib/test.o   : tests/test.c    $(TEST_COMMON) tests/vectors.h
+lib/ctgrind.o: tests/ctgrind.c $(TEST_COMMON)
+lib/utils.o lib/test.o lib/tis-ci.o:
        @mkdir -p $(@D)
        $(CC) $(CFLAGS)                     \
-            -I src -I src/optional -I tests \
-            -fPIC -c -o $@ $<
+           -I src -I src/optional -I tests \
+           -fPIC -c -o $@ $<
 lib/ctgrind.o: # suppress optimisations to maximise findings
        @mkdir -p $(@D)
        $(CC) $(CFLAGS) -O0                 \
-            -I src -I src/optional -I tests \
-            -fPIC -c -o $@ $<
-
-lib/speed-tweetnacl.o:
-       @mkdir -p $(@D)
-       $(CC) $(CFLAGS)                                                  \
-            -I src -I src/optional -I tests -I tests/externals/tweetnacl \
-            -fPIC -c -o $@ $<
-
-lib/speed-sodium.o:$(SPEED)/speed-sodium.c $(TEST_COMMON) $(SPEED)/speed.h
-       @mkdir -p $(@D)
-       $(CC) $(CFLAGS)                     \
-            -I src -I src/optional -I tests \
-            `pkg-config --cflags libsodium` \
-            -fPIC -c -o $@ $<
-
-lib/speed-hydrogen.o:$(SPEED)/speed-hydrogen.c $(TEST_COMMON) $(SPEED)/speed.h
-       @mkdir -p $(@D)
-       $(CC) $(CFLAGS)                       \
-            -I src -I src/optional -I tests   \
-            `pkg-config --cflags libhydrogen` \
-            -fPIC -c -o $@ $<
-
-lib/speed-donna.o:$(SPEED)/speed-donna.c $(TEST_COMMON) $(SPEED)/speed.h
-       @mkdir -p $(@D)
-       $(CC) $(CFLAGS)                                                      \
-            -I src -I src/optional -I tests -I tests/externals/ed25519-donna \
-            -fPIC -c -o $@ $<
-
-C25519=         c25519 edsign ed25519 morph25519 fprime f25519 sha512
-C25519_H=       $(patsubst %, tests/externals/c25519/%.h, $(C25519))
-C25519_OBJECTS= $(patsubst %, lib/c25519/%.o,             $(C25519))
-lib/c25519/c25519.o    : tests/externals/c25519/c25519.c     $(C25519_H)
-lib/c25519/ed25519.o   : tests/externals/c25519/ed25519.c    $(C25519_H)
-lib/c25519/edsign.o    : tests/externals/c25519/edsign.c     $(C25519_H)
-lib/c25519/f25519.o    : tests/externals/c25519/f25519.c     $(C25519_H)
-lib/c25519/fprime.o    : tests/externals/c25519/fprime.c     $(C25519_H)
-lib/c25519/morph25519.o: tests/externals/c25519/morph25519.c $(C25519_H)
-lib/c25519/sha512.o    : tests/externals/c25519/sha512.c     $(C25519_H)
-$(C25519_OBJECTS):
-       @mkdir -p $(@D)
-       $(CC) $(CFLAGS) -I tests/externals/c25519/ -c -o $@ $<
-
-lib/speed-c25519.o:$(SPEED)/speed-c25519.c \
-                   $(SPEED)/speed.h        \
-                   $(TEST_COMMON)          \
-                   $(C25519_HEADERS)
-       @mkdir -p $(@D)
-       $(CC) $(CFLAGS) -I tests -I tests/externals/c25519 -c -o $@ $<
-
-lib/speed-ed25519.o: tests/externals/ed25519-donna/ed25519.c \
-           $(wildcard tests/externals/ed25519-donna/*.h)
-       $(CC) $(CFLAGS) -c $< -o$@            \
-            -I src                            \
-            -DED25519_CUSTOMHASH              \
-            -DED25519_TEST                    \
-            -DED25519_NO_INLINE_ASM           \
-            -DED25519_FORCE_32BIT
+           -I src -I src/optional -I tests \
+           -fPIC -c -o $@ $<
 
-# test & speed executables
+######################
+## Test executables ##
+######################
 TEST_OBJ=  lib/utils.o lib/monocypher.o lib/monocypher-ed25519.o
-test.out       : lib/test.o     $(TEST_OBJ)
-tis-ci.out     : lib/tis-ci.o   $(TEST_OBJ)
-ctgrind.out    : lib/ctgrind.o  $(TEST_OBJ)
-speed.out      : lib/speed.o    $(TEST_OBJ)
-test.out speed.out tis-ci.out:
+test.out   : lib/test.o    $(TEST_OBJ)
+tis-ci.out : lib/tis-ci.o  $(TEST_OBJ)
+ctgrind.out: lib/ctgrind.o $(TEST_OBJ)
+test.out tis-ci.out:
        $(CC) $(CFLAGS) -I src -I src/optional -o $@ $^
 ctgrind.out:
        $(CC) $(CFLAGS) -O0 -I src -I src/optional -o $@ $^
-speed-sodium.out: lib/speed-sodium.o lib/utils.o
-       $(CC) $(CFLAGS) -o $@ $^            \
-            `pkg-config --cflags libsodium` \
-            `pkg-config --libs   libsodium`
-speed-donna.out: lib/speed-donna.o lib/speed-ed25519.o lib/utils.o
-       $(CC) $(CFLAGS) -o $@ $^ \
-            `pkg-config --cflags libsodium` \
-            `pkg-config --libs   libsodium`
-speed-hydrogen.out: lib/speed-hydrogen.o lib/utils.o
-       $(CC) $(CFLAGS) -o $@ $^              \
-            `pkg-config --cflags libhydrogen` \
-            `pkg-config --libs   libhydrogen`
-lib/tweetnacl.o: tests/externals/tweetnacl/tweetnacl.c \
-                 tests/externals/tweetnacl/tweetnacl.h
-       $(CC) $(CFLAGS) -c -o $@ $<
-speed-tweetnacl.out: lib/speed-tweetnacl.o lib/tweetnacl.o lib/utils.o
-       $(CC) $(CFLAGS) -o $@ $^
-speed-c25519.out   : lib/speed-c25519.o $(C25519_OBJECTS) lib/utils.o
-       $(CC) $(CFLAGS) -o $@ $^
 tests/vectors.h:
        @echo ""
        @echo "======================================================"
diff --git a/tests/speed/makefile b/tests/speed/makefile
new file mode 100644 (file)
index 0000000..32d6559
--- /dev/null
@@ -0,0 +1,164 @@
+# This file is dual-licensed.  Choose whichever licence you want from
+# the two licences listed below.
+#
+# The first licence is a regular 2-clause BSD licence.  The second licence
+# is the CC-0 from Creative Commons. It is intended to release Monocypher
+# to the public domain.  The BSD licence serves as a fallback option.
+#
+# SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
+#
+# ------------------------------------------------------------------------
+#
+# Copyright (c) 2023, Loup Vaillant
+# All rights reserved.
+#
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the
+#    distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# ------------------------------------------------------------------------
+#
+# Written in 2023 by Loup Vaillant
+#
+# To the extent possible under law, the author(s) have dedicated all copyright
+# and related neighboring rights to this software to the public domain
+# worldwide.  This software is distributed without any warranty.
+#
+# You should have received a copy of the CC0 Public Domain Dedication along
+# with this software.  If not, see
+# <https://creativecommons.org/publicdomain/zero/1.0/>
+
+CC=gcc -std=gnu99
+CFLAGS= -pedantic -Wall -Wextra -O3 -march=native
+
+.PHONY: speed speed-sodium speed-hydrogen speed-tweetnacl speed-c25519 \
+        speed-donna \
+        pkg-config-libhydrogen \
+        clean
+
+##################
+## Main targets ##
+##################
+all: speed
+
+speed          : speed.out
+speed-sodium   : speed-sodium.out
+speed-hydrogen : speed-hydrogen.out
+speed-tweetnacl: speed-tweetnacl.out
+speed-c25519   : speed-c25519.out
+speed-donna    : speed-donna.out
+speed speed-sodium speed-hydrogen speed-tweetnacl speed-c25519 speed-donna:
+       ./$<
+
+clean:
+       rm -f *.o *.out
+
+####################
+## Base libraries ##
+####################
+
+# Test utils
+utils.o: ../utils.c ../utils.h
+       $(CC) -c $(CFLAGS) -I .. $< -o $@
+
+# Monocypher
+monocypher.o: ../../src/monocypher.c ../../src/monocypher.h
+       $(CC) -c $(CFLAGS) -I .. -I ../../src/ $< -o $@
+monocypher-ed25519.o: ../../src/optional/monocypher-ed25519.c \
+                      ../../src/optional/monocypher-ed25519.h \
+                      ../../src/monocypher.h
+       $(CC) -c $(CFLAGS) -I .. -I ../../src/ -I ../../src/optional $< -o $@
+
+# TweetNaCl
+tweetnacl.o: ../externals/tweetnacl/tweetnacl.c \
+             ../externals/tweetnacl/tweetnacl.h
+       $(CC) -c $(CFLAGS) -I .. $< -o $@
+
+# C25519
+C25519=c25519 edsign ed25519 morph25519 fprime f25519 sha512
+C25519_HEADERS=$(patsubst %, ../externals/c25519/%.h, $(C25519))
+C25519_OBJECTS=$(patsubst %, %.o,                     $(C25519))
+c25519.o    : ../externals/c25519/c25519.c     $(C25519_HEADERS)
+ed25519.o   : ../externals/c25519/ed25519.c    $(C25519_HEADERS)
+edsign.o    : ../externals/c25519/edsign.c     $(C25519_HEADERS)
+f25519.o    : ../externals/c25519/f25519.c     $(C25519_HEADERS)
+fprime.o    : ../externals/c25519/fprime.c     $(C25519_HEADERS)
+morph25519.o: ../externals/c25519/morph25519.c $(C25519_HEADERS)
+sha512.o    : ../externals/c25519/sha512.c     $(C25519_HEADERS)
+$(C25519_OBJECTS):
+       $(CC) -c $(CFLAGS) -I ../externals/c25519/ -o $@ $<
+
+# libhydrogen (only installs pkg-config)
+DESTDIR=
+PREFIX=usr/local
+PKGCONFIGDIR=$(LIBDIR)/pkgconfig
+pkg-config-libhydrogen:
+       mkdir -p $(DESTDIR)/$(PKGCONFIGDIR)
+       sed "s|PREFIX|$(PREFIX)|" libhydrogen.pc \
+           > $(DESTDIR)/$(PKGCONFIGDIR)/libhydrogen.pc
+
+# Donna
+DONNA_HEADERS=$(wildcard ../externals/ed25519-donna/*.h)
+donna.o: ../externals/ed25519-donna/ed25519.c $(DONNA_HEADERS)
+       $(CC) $(CFLAGS) -c $< -o$@  \
+           -DED25519_CUSTOMHASH    \
+           -DED25519_TEST          \
+           -DED25519_NO_INLINE_ASM \
+           -DED25519_FORCE_32BIT
+
+
+######################
+## Speed benchmarks ##
+######################
+speed.o           : speed.c           speed.h ../utils.h
+       $(CC) -c $(CFLAGS) $< -o $@ -I ..
+speed-sodium.o    : speed-sodium.c    speed.h ../utils.h
+       $(CC) -c $(CFLAGS) $< -o $@ -I ..
+speed-hydrogen.o  : speed-hydrogen.c  speed.h ../utils.h
+       $(CC) -c $(CFLAGS) $< -o $@ -I ..
+speed-tweetnacl.o : speed-tweetnacl.c speed.h ../utils.h $(TWEET_HEADERS)
+       $(CC) -c $(CFLAGS) $< -o $@ -I .. -I ../externals/tweetnacl
+speed-c25519.o    : speed-c25519.c    speed.h ../utils.h $(C25519_HEADERS)
+       $(CC) -c $(CFLAGS) $< -o $@ -I .. -I ../externals/c25519
+speed-donna.o     : speed-donna.c     speed.h ../utils.h $(DONNA_HEADERS)
+       $(CC) -c $(CFLAGS) $< -o $@ -I .. -I ../externals/ed25519-donna
+
+speed.out: speed.o utils.o monocypher.o monocypher-ed25519.o
+       $(CC) $(CFLAGS) -o $@ $^
+speed-sodium.out: speed-sodium.o utils.o
+       $(CC) $(CFLAGS) -o $@ $^            \
+           `pkg-config --cflags libsodium` \
+           `pkg-config --libs   libsodium`
+speed-donna.out: speed-donna.o donna.o utils.o
+       $(CC) $(CFLAGS) -o $@ $^            \
+           `pkg-config --cflags libsodium` \
+           `pkg-config --libs   libsodium`
+speed-hydrogen.out: speed-hydrogen.o utils.o
+       $(CC) $(CFLAGS) -o $@ $^              \
+           `pkg-config --cflags libhydrogen` \
+           `pkg-config --libs   libhydrogen`
+speed-tweetnacl.out: speed-tweetnacl.o tweetnacl.o utils.o
+       $(CC) $(CFLAGS) -o $@ $^
+speed-c25519.out   : speed-c25519.o $(C25519_OBJECTS) utils.o
+       $(CC) $(CFLAGS) -o $@ $^