]> git.codecow.com Git - Monocypher.git/commitdiff
Added Libhydrogen speed tests
authorLoup Vaillant <loup@loup-vaillant.fr>
Wed, 23 Oct 2019 21:39:48 +0000 (23:39 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Wed, 23 Oct 2019 21:39:48 +0000 (23:39 +0200)
makefile
tests/externals/libhydrogen.pc [new file with mode: 0644]
tests/speed/speed-hydrogen.c [new file with mode: 0644]

index ca28aed343547cec2c8e6633ef29b9e121e7328c..684a6e2f883b9b2fe0eb02177884a76b9ce00c2c 100644 (file)
--- a/makefile
+++ b/makefile
@@ -13,10 +13,10 @@ else
 LINK_SHA512=lib/sha512.o
 endif
 
-.PHONY: all library static-library dynamic-library \
-        install install-doc                        \
-        check test speed                           \
-        clean uninstall                            \
+.PHONY: all library static-library dynamic-library    \
+        install install-doc pkg-config-libhydrogen    \
+        check test speed speed-sodium speed-tweetnacl \
+        clean uninstall                               \
         tarball
 
 all    : library
@@ -44,6 +44,10 @@ install-doc:
        mkdir -p $(MAN_DIR)
        cp -r doc/man/man3/*.3monocypher $(MAN_DIR)
 
+pkg-config-libhydrogen: tests/externals/libhydrogen.pc
+       mkdir -p $(PKGCONFIG)
+       cp $< $(PKGCONFIG)/libhydrogen.pc
+
 library: static-library dynamic-library
 static-library : lib/libmonocypher.a
 dynamic-library: lib/libmonocypher.so lib/libmonocypher.so.2
@@ -64,7 +68,8 @@ test           : test.out
 speed          : speed.out
 speed-sodium   : speed-sodium.out
 speed-tweetnacl: speed-tweetnacl.out
-test speed speed-sodium speed-tweetnacl:
+speed-hydrogen : speed-hydrogen.out
+test speed speed-sodium speed-tweetnacl speed-hydrogen:
        ./$<
 
 # Monocypher libraries
@@ -101,15 +106,26 @@ lib/speed-sodium.o:$(SPEED)/speed-sodium.c $(TEST_COMMON) $(SPEED)/speed.h
             `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 $@ $<
+
 # test & speed executables
 test.out : lib/test.o  lib/monocypher.o lib/sha512.o
 speed.out: lib/speed.o lib/monocypher.o lib/sha512.o
 test.out speed.out:
        $(CC) $(CFLAGS) -I src -I src/optional -o $@ $^
 speed-sodium.out: lib/speed-sodium.o
-       $(CC) $(CFLAGS) -o $@ $^              \
+       $(CC) $(CFLAGS) -o $@ $^            \
             `pkg-config --cflags libsodium` \
             `pkg-config --libs   libsodium`
+speed-hydrogen.out: lib/speed-hydrogen.o
+       $(CC) $(CFLAGS) -o $@ $^              \
+            `pkg-config --cflags libhydrogen` \
+            `pkg-config --libs   libhydrogen`
 lib/tweetnacl.o: tests/externals/tweetnacl.c tests/externals/tweetnacl.h
        $(CC) $(CFLAGS) -c -o $@ $<
 speed-tweetnacl.out: lib/speed-tweetnacl.o lib/tweetnacl.o
diff --git a/tests/externals/libhydrogen.pc b/tests/externals/libhydrogen.pc
new file mode 100644 (file)
index 0000000..932562a
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=/usr/local
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: libhydrogen
+Version: git-f1f061d
+Description: Small, easy-to-use, hard-to-misuse cryptographic library.
+
+Libs: -L${libdir} -lhydrogen
+Cflags: -I${includedir}
diff --git a/tests/speed/speed-hydrogen.c b/tests/speed/speed-hydrogen.c
new file mode 100644 (file)
index 0000000..a32ee7d
--- /dev/null
@@ -0,0 +1,78 @@
+#include "speed.h"
+#include "utils.h"
+#include "hydrogen.h"
+
+static u64 hydro_random(void)
+{
+    u8 out[SIZE];
+    RANDOM_INPUT(key  ,   32);
+    RANDOM_INPUT(nonce,    8);
+
+    TIMING_START {
+        hydro_random_buf_deterministic(out, SIZE, key);
+    }
+    TIMING_END;
+}
+
+static u64 authenticated(void)
+{
+    u8 out[SIZE + hydro_secretbox_HEADERBYTES];
+    RANDOM_INPUT(in , SIZE + 32);
+    RANDOM_INPUT(key,        32);
+    TIMING_START {
+        hydro_secretbox_encrypt(out, in, SIZE, 0, "Benchmark", key);
+    }
+    TIMING_END;
+}
+
+static u64 hash(void)
+{
+    u8 hash[32];
+    RANDOM_INPUT(in, SIZE);
+
+    TIMING_START {
+        hydro_hash_hash(hash, 32, in, SIZE, "Benchmark", 0);
+    }
+    TIMING_END;
+}
+
+static u64 sign(void)
+{
+    RANDOM_INPUT(message, 64);
+    hydro_sign_keypair key_pair;
+    hydro_sign_keygen(&key_pair);
+    uint8_t sig[hydro_sign_BYTES];
+
+    TIMING_START {
+        hydro_sign_create(sig, message, 64, "Benchmark", key_pair.sk);
+    }
+    TIMING_END;
+}
+
+static u64 check(void)
+{
+    RANDOM_INPUT(message, 64);
+    hydro_sign_keypair key_pair;
+    hydro_sign_keygen(&key_pair);
+    uint8_t sig[hydro_sign_BYTES];
+    hydro_sign_create(sig, message, 64, "Benchmark", key_pair.sk);
+
+    TIMING_START {
+        if (hydro_sign_verify(sig, message, 64, "Benchmark", key_pair.pk)) {
+            printf("LibHydrogen verification failed\n");
+        }
+    }
+    TIMING_END;
+}
+
+int main()
+{
+    hydro_init();
+    print("Random           ",hydro_random() *MUL,"megabytes  per second");
+    print("Auth'd encryption",authenticated()*MUL,"megabytes  per second");
+    print("Hash             ",hash()         *MUL,"megabytes  per second");
+    print("sign             ",sign()             ,"signatures per second");
+    print("check            ",check()            ,"checks     per second");
+    printf("\n");
+    return 0;
+}