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
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
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
`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
--- /dev/null
+#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;
+}