aboutsummaryrefslogtreecommitdiff
path: root/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/src')
-rw-r--r--test/src/Makefile42
-rw-r--r--test/src/math/test_subgroups.c28
-rw-r--r--test/src/test/utils.c14
-rw-r--r--test/src/test/utils.h12
4 files changed, 96 insertions, 0 deletions
diff --git a/test/src/Makefile b/test/src/Makefile
new file mode 100644
index 0000000..27e6ea2
--- /dev/null
+++ b/test/src/Makefile
@@ -0,0 +1,42 @@
+####
+#
+# ecgen, tool for generating Elliptic curve domain parameters
+# Copyright (C) 2017 J08nY
+#
+####
+
+
+CC ?= gcc
+CFLAGS = -Wall
+TEST ?= 0
+ifeq ($(TEST), 1)
+ CFLAGS += --coverage -g -O0
+endif
+LDFLAGS = -L../../lib/parson -L../../lib/sha1 -L../../lib/pari -L../lib/criterion/build
+INCLUDES = -I. -I../../src -I../../lib -I../lib/criterion/include
+LIBS = -lrt -lpari -lpthread -lparson -lsha1 -lcriterion
+
+TEST_SRC = $(wildcard *.c) $(wildcard */*.c)
+TEST_OBJ = $(patsubst %.c,%.o, $(TEST_SRC))
+TESTS = $(patsubst %.c,%, $(TEST_SRC))
+
+ECGEN_SRC = $(wildcard ../../src/*/*.c)
+ECGEN_OBJ = $(patsubst %.c,%.o, $(ECGEN_SRC))
+
+all: test_ecgen
+ LD_LIBRARY_PATH=../lib/criterion/build ./test_ecgen
+
+test_ecgen: $(TEST_OBJ) $(ECGEN_OBJ)
+ $(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LDFLAGS) $(LIBS)
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
+
+clean-all: clean
+ rm -f ./test_ecgen
+
+clean:
+ find . -type f -name '*.o' -exec rm {} +
+ find . -type f -name '*.gcda' -exec rm {} +
+ find . -type f -name '*.gcno' -exec rm {} +
+ find . -type f -name '*.gcov' -exec rm {} +
diff --git a/test/src/math/test_subgroups.c b/test/src/math/test_subgroups.c
new file mode 100644
index 0000000..ad42282
--- /dev/null
+++ b/test/src/math/test_subgroups.c
@@ -0,0 +1,28 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#include "gen/types.h"
+#include "math/subgroups.h"
+#include <criterion/criterion.h>
+#include "test/utils.h"
+
+TestSuite(subgroups, .init=default_setup, .fini=default_teardown);
+
+Test(subgroups, test_prime_factors) {
+ curve_t curve = {.order = stoi(12)};
+ config_t cfg = {.prime = false};
+ GEN divs = subgroups_prime(&curve, &cfg);
+ GEN vec = gtocol0(gen_0, 2);
+ gel(vec, 1) = stoi(2);
+ gel(vec, 2) = stoi(3);
+ cr_assert(gequal(divs, vec), "Factors not equal!");
+}
+
+Test(subgroups, test_prime_prime) {
+ curve_t curve = {.order = stoi(5)};
+ config_t cfg = {.prime = true};
+ GEN divs = subgroups_prime(&curve, &cfg);
+ GEN vec = gtocol(stoi(5));
+ cr_assert(gequal(divs, vec), "Factors not equal!");
+} \ No newline at end of file
diff --git a/test/src/test/utils.c b/test/src/test/utils.c
new file mode 100644
index 0000000..a8a11db
--- /dev/null
+++ b/test/src/test/utils.c
@@ -0,0 +1,14 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#include "utils.h"
+#include <pari/pari.h>
+
+void default_setup(void) {
+ pari_init(1000000, 1000000);
+}
+
+void default_teardown(void) {
+ pari_close();
+} \ No newline at end of file
diff --git a/test/src/test/utils.h b/test/src/test/utils.h
new file mode 100644
index 0000000..2780bd2
--- /dev/null
+++ b/test/src/test/utils.h
@@ -0,0 +1,12 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#ifndef ECGEN_UTILS_H
+#define ECGEN_UTILS_H
+
+void default_setup(void);
+
+void default_teardown(void);
+
+#endif //ECGEN_UTILS_H