]> git.codecow.com Git - Monocypher.git/commitdiff
turned test utils into header only
authorLoup Vaillant <loup@loup-vaillant.fr>
Tue, 2 Jan 2018 23:10:04 +0000 (00:10 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Tue, 2 Jan 2018 23:10:04 +0000 (00:10 +0100)
Simplifies the makefiles a bit

makefile
tests/gen/makefile
tests/utils.c [deleted file]
tests/utils.h

index 7b4000d09e95662c3a411e9123190b4b3ec523c0..76b973dfc6f888f84280fc5bec805614455756aa 100644 (file)
--- a/makefile
+++ b/makefile
@@ -80,7 +80,6 @@ lib/monocypher.o lib/sha512.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         $(TEST_COMMON) tests/vectors.h
 lib/speed.o       : tests/speed.c        $(TEST_COMMON) tests/speed.h
 lib/speed-sodium.o: tests/speed-sodium.c $(TEST_COMMON) tests/speed.h
@@ -89,12 +88,11 @@ lib/utils.o lib/test.o lib/speed.o lib/speed-sodium.o:
        $(CC) $(CFLAGS) -I src -I src/optional -fPIC -c -o $@ $<
 
 # test & speed executables
-test.out        : lib/test.o         lib/utils.o lib/monocypher.o lib/sha512.o
-speed.out       : lib/speed.o        lib/utils.o lib/monocypher.o lib/sha512.o
-speed-sodium.out: lib/speed-sodium.o lib/utils.o
+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 lib/utils.o
+speed-sodium.out: lib/speed-sodium.o
        $(CC) $(CFLAGS) -I src -I src/optional -o $@ $^ \
             $$(pkg-config --cflags libsodium)           \
             $$(pkg-config --libs   libsodium)
index e1ad0e95be29975fc305ea99aed1d24063601310..5ea6e4800eb092bb4f4e424ced9348d07680f01d 100644 (file)
@@ -29,13 +29,10 @@ clean:
             -I ../../src/optional \
             $$(pkg-config --cflags libsodium)
 
-%.out: %.o monocypher.o utils.o ed25519.o
+%.out: %.o monocypher.o ed25519.o
        $(CC) $(CFLAGS) -o $@ $^ \
             $$(pkg-config --libs libsodium)
 
-utils.o: ../utils.c ../utils.h
-       $(CC) $(CFLAGS) -c $< -I .. -I ../../src
-
 ed25519.o: ../ed25519-donna/ed25519.c  $(wildcard ../ed25519-donna/*.h)
        $(CC) $(CFLAGS) -c $<       \
             -I ../../src            \
diff --git a/tests/utils.c b/tests/utils.c
deleted file mode 100644 (file)
index bedb2de..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "utils.h"
-#include "stdio.h"
-
-static void store64_le(u8 out[8], u64 in)
-{
-    out[0] =  in        & 0xff;
-    out[1] = (in >>  8) & 0xff;
-    out[2] = (in >> 16) & 0xff;
-    out[3] = (in >> 24) & 0xff;
-    out[4] = (in >> 32) & 0xff;
-    out[5] = (in >> 40) & 0xff;
-    out[6] = (in >> 48) & 0xff;
-    out[7] = (in >> 56) & 0xff;
-}
-
-u64 load64_le(const u8 s[8])
-{
-    return (u64)s[0]
-        | ((u64)s[1] <<  8)
-        | ((u64)s[2] << 16)
-        | ((u64)s[3] << 24)
-        | ((u64)s[4] << 32)
-        | ((u64)s[5] << 40)
-        | ((u64)s[6] << 48)
-        | ((u64)s[7] << 56);
-}
-
-
-// Pseudo-random 64 bit number, based on xorshift*
-u64 rand64()
-{
-    static u64 x = 12345; // Must be seeded with a nonzero value.
-    x ^= x >> 12;
-    x ^= x << 25;
-    x ^= x >> 27;
-    return x * 0x2545F4914F6CDD1D; // magic constant
-}
-
-void p_random(u8 *stream, size_t size)
-{
-    FOR (i, 0, size) {
-        stream[i] = (u8)rand64();
-    }
-}
-
-void print_vector(u8 *buf, size_t size)
-{
-    FOR (i, 0, size) {
-        printf("%x%x", buf[i] >> 4, buf[i] & 0x0f);
-    }
-    printf(":\n");
-}
-
-void print_number(u64 n)
-{
-    u8 buf[8];
-    store64_le(buf, n);
-    print_vector(buf, 8);
-}
index 701dbfa701c29c3022832d1c14e75b014d021364..9d20a426b19b1ecce6ab433e0c69fc955fbd42e9 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <inttypes.h>
 #include <stddef.h>
+#include <stdio.h>
 
 typedef int8_t   i8;
 typedef uint8_t  u8;
@@ -19,10 +20,60 @@ typedef uint64_t u64;
     }
 #define RANDOM_INPUT(name, size) u8 name[size]; p_random(name, size)
 
-u64  load64_le(const u8 s[8]);
-void p_random(u8 *stream, size_t size);
-u64  rand64();
-void print_vector(u8 *buf, size_t size);
-void print_number(u64 n);
+static void store64_le(u8 out[8], u64 in)
+{
+    out[0] =  in        & 0xff;
+    out[1] = (in >>  8) & 0xff;
+    out[2] = (in >> 16) & 0xff;
+    out[3] = (in >> 24) & 0xff;
+    out[4] = (in >> 32) & 0xff;
+    out[5] = (in >> 40) & 0xff;
+    out[6] = (in >> 48) & 0xff;
+    out[7] = (in >> 56) & 0xff;
+}
+
+u64 load64_le(const u8 s[8])
+{
+    return (u64)s[0]
+        | ((u64)s[1] <<  8)
+        | ((u64)s[2] << 16)
+        | ((u64)s[3] << 24)
+        | ((u64)s[4] << 32)
+        | ((u64)s[5] << 40)
+        | ((u64)s[6] << 48)
+        | ((u64)s[7] << 56);
+}
+
+// Pseudo-random 64 bit number, based on xorshift*
+u64 rand64()
+{
+    static u64 x = 12345; // Must be seeded with a nonzero value.
+    x ^= x >> 12;
+    x ^= x << 25;
+    x ^= x >> 27;
+    return x * 0x2545F4914F6CDD1D; // magic constant
+}
+
+void p_random(u8 *stream, size_t size)
+{
+    FOR (i, 0, size) {
+        stream[i] = (u8)rand64();
+    }
+}
+
+void print_vector(u8 *buf, size_t size)
+{
+    FOR (i, 0, size) {
+        printf("%x%x", buf[i] >> 4, buf[i] & 0x0f);
+    }
+    printf(":\n");
+}
+
+void print_number(u64 n)
+{
+    u8 buf[8];
+    store64_le(buf, n);
+    print_vector(buf, 8);
+}
 
 #endif // UTILS_H