]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Moved Ed25519 tests to libstrongswan
authorAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 13 Dec 2016 21:47:36 +0000 (22:47 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 14 Dec 2016 10:57:36 +0000 (11:57 +0100)
configure.ac
src/libstrongswan/Makefile.am
src/libstrongswan/plugins/curve25519/Makefile.am
src/libstrongswan/plugins/curve25519/tests/.gitignore [deleted file]
src/libstrongswan/plugins/curve25519/tests/Makefile.am [deleted file]
src/libstrongswan/plugins/curve25519/tests/curve25519_tests.c [deleted file]
src/libstrongswan/plugins/curve25519/tests/curve25519_tests.h [deleted file]
src/libstrongswan/tests/Makefile.am
src/libstrongswan/tests/suites/test_ed25519.c [moved from src/libstrongswan/plugins/curve25519/tests/suites/test_curve25519_ed25519.c with 96% similarity]
src/libstrongswan/tests/tests.h

index d5f87901b4394045367d13c92ef05b17f7b7615d..983e924d8c2c80618887f0e37496491c018dc0f5 100644 (file)
@@ -1757,7 +1757,6 @@ AC_CONFIG_FILES([
        src/libstrongswan/plugins/fips_prf/Makefile
        src/libstrongswan/plugins/gmp/Makefile
        src/libstrongswan/plugins/curve25519/Makefile
-       src/libstrongswan/plugins/curve25519/tests/Makefile
        src/libstrongswan/plugins/rdrand/Makefile
        src/libstrongswan/plugins/aesni/Makefile
        src/libstrongswan/plugins/random/Makefile
index c3b31fe1450aed71f3baa7fe469204cbc8579038..f6d6f5465fdf6fa9f33d4f2848104190bcd359bc 100644 (file)
@@ -648,7 +648,3 @@ endif
 if USE_NEWHOPE
   SUBDIRS += plugins/newhope/tests
 endif
-
-if USE_CURVE25519
-  SUBDIRS += plugins/curve25519/tests
-endif
index 7bbf2218bcc589111865ee981f3db98f802927c9..f3e1e92958948b99a4ae2bde1fb14a846fe4db3b 100644 (file)
@@ -2,19 +2,10 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/src/libstrongswan
 
 AM_CFLAGS = \
-       $(PLUGIN_CFLAGS) \
-       @COVERAGE_CFLAGS@
-
-# these files are also used by the tests, we can't directly refer to them
-# because of the subdirectory, which would cause distclean to fail
-noinst_LTLIBRARIES = libcurve25519.la
-libcurve25519_la_SOURCES = \
-       curve25519_private_key.h curve25519_private_key.c \
-       curve25519_public_key.h curve25519_public_key.c \
-       ref10/ref10.h ref10/ref10.c ref10/base.h ref10/base2.h
+       $(PLUGIN_CFLAGS)
 
 if MONOLITHIC
-noinst_LTLIBRARIES += libstrongswan-curve25519.la
+noinst_LTLIBRARIES = libstrongswan-curve25519.la
 else
 plugin_LTLIBRARIES = libstrongswan-curve25519.la
 endif
@@ -24,9 +15,9 @@ libstrongswan_curve25519_la_SOURCES = \
        curve25519_drv.h curve25519_drv.c \
        curve25519_drv_portable.h curve25519_drv_portable.c \
        curve25519_identity_hasher.h curve25519_identity_hasher.c \
-       curve25519_plugin.h curve25519_plugin.c
+       curve25519_plugin.h curve25519_plugin.c \
+       curve25519_private_key.h curve25519_private_key.c \
+       curve25519_public_key.h curve25519_public_key.c \
+       ref10/ref10.h ref10/ref10.c ref10/base.h ref10/base2.h
 
 libstrongswan_curve25519_la_LDFLAGS = -module -avoid-version
-
-libstrongswan_curve25519_la_LIBADD = libcurve25519.la
-
diff --git a/src/libstrongswan/plugins/curve25519/tests/.gitignore b/src/libstrongswan/plugins/curve25519/tests/.gitignore
deleted file mode 100644 (file)
index 9c83c3f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-curve25519_tests
diff --git a/src/libstrongswan/plugins/curve25519/tests/Makefile.am b/src/libstrongswan/plugins/curve25519/tests/Makefile.am
deleted file mode 100644 (file)
index 30e1851..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-TESTS = curve25519_tests
-
-check_PROGRAMS = $(TESTS)
-
-curve25519_tests_SOURCES = \
-       suites/test_curve25519_ed25519.c \
-       curve25519_tests.h curve25519_tests.c
-
-curve25519_tests_CFLAGS = \
-       -I$(top_srcdir)/src/libstrongswan \
-       -I$(top_srcdir)/src/libstrongswan/tests \
-       -I$(top_srcdir)/src/libstrongswan/plugins/curve25519 \
-       -DPLUGINDIR=\""$(abs_top_builddir)/src/libstrongswan/plugins\"" \
-       -DPLUGINS=\""${s_plugins}\"" \
-       @COVERAGE_CFLAGS@
-
-curve25519_tests_LDFLAGS = @COVERAGE_LDFLAGS@
-curve25519_tests_LDADD = \
-       $(top_builddir)/src/libstrongswan/libstrongswan.la \
-       $(top_builddir)/src/libstrongswan/tests/libtest.la \
-       ../libcurve25519.la
diff --git a/src/libstrongswan/plugins/curve25519/tests/curve25519_tests.c b/src/libstrongswan/plugins/curve25519/tests/curve25519_tests.c
deleted file mode 100644 (file)
index 5ecae23..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2014 Andreas Steffen
- * HSR Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-#include <test_runner.h>
-
-#include <library.h>
-
-/* declare test suite constructors */
-#define TEST_SUITE(x) test_suite_t* x();
-#include "curve25519_tests.h"
-#undef TEST_SUITE
-
-static test_configuration_t tests[] = {
-#define TEST_SUITE(x) \
-       { .suite = x, },
-#include "curve25519_tests.h"
-       { .suite = NULL, }
-};
-
-static bool test_runner_init(bool init)
-{
-       if (init)
-       {
-               char *plugins, *plugindir;
-
-               plugins = lib->settings->get_str(lib->settings,
-                                                                               "tests.load", PLUGINS);
-               plugindir = lib->settings->get_str(lib->settings,
-                                                                               "tests.plugindir", PLUGINDIR);
-               plugin_loader_add_plugindirs(plugindir, plugins);
-               if (!lib->plugins->load(lib->plugins, plugins))
-               {
-                       return FALSE;
-               }
-       }
-       else
-       {
-               lib->processor->set_threads(lib->processor, 0);
-               lib->processor->cancel(lib->processor);
-               lib->plugins->unload(lib->plugins);
-       }
-       return TRUE;
-}
-
-int main(int argc, char *argv[])
-{
-       return test_runner_run("curve25519", tests, test_runner_init);
-}
diff --git a/src/libstrongswan/plugins/curve25519/tests/curve25519_tests.h b/src/libstrongswan/plugins/curve25519/tests/curve25519_tests.h
deleted file mode 100644 (file)
index f176574..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (C) 2016 Andreas Steffen
- * HSR Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-TEST_SUITE(curve25519_ed25519_suite_create)
index caa9d3a6a306f0b91515ac0bbe722c3d2b33d93c..0231c1c142dfa830e31abbc2ed4ea46e82f21f3b 100644 (file)
@@ -55,7 +55,8 @@ tests_SOURCES = tests.h tests.c \
   suites/test_printf.c \
   suites/test_test_rng.c \
   suites/test_mgf1.c \
-  suites/test_ntru.c
+  suites/test_ntru.c \
+  suites/test_ed25519.c
 
 tests_CFLAGS = \
   -I$(top_srcdir)/src/libstrongswan \
similarity index 96%
rename from src/libstrongswan/plugins/curve25519/tests/suites/test_curve25519_ed25519.c
rename to src/libstrongswan/tests/suites/test_ed25519.c
index cdff16327803e7826324c2baa41b019279b8268f..00842628dab6360e921441351e43a60168fd949f 100644 (file)
@@ -15,9 +15,6 @@
 
 #include "test_suite.h"
 
-#include <curve25519_private_key.h>
-#include <curve25519_public_key.h>
-
 #include <time.h>
 
 typedef struct sig_test_t sig_test_t;
@@ -272,7 +269,7 @@ static sig_test_t sig_tests[] = {
        }
 };
 
-START_TEST(test_curve25519_ed25519_sign)
+START_TEST(test_ed25519_sign)
 {
        private_key_t *key;
        public_key_t *pubkey, *public;
@@ -316,7 +313,7 @@ START_TEST(test_curve25519_ed25519_sign)
 }
 END_TEST
 
-START_TEST(test_curve25519_ed25519_gen)
+START_TEST(test_ed25519_gen)
 {
        private_key_t *key, *key2;
        public_key_t *pubkey, *pubkey2;
@@ -390,19 +387,18 @@ START_TEST(test_curve25519_ed25519_gen)
 }
 END_TEST
 
-START_TEST(test_curve25519_ed25519_speed)
+START_TEST(test_ed25519_speed)
 {
        private_key_t *key;
        public_key_t *pubkey;
        chunk_t msg = chunk_from_str("Hello Ed25519"), sig;
-       struct timespec start, stop;
        int i, count = 1000;
 
-       /* use /dev/urandom for true random source */
-       lib->settings->set_str(lib->settings,
-                               "libstrongswan.plugins.random.random", "/dev/urandom");
-
+#ifdef HAVE_CLOCK_GETTIME
+       struct timespec start, stop;
        clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
+#endif
+
        for (i = 0; i < count; i++)
        {
                key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ED25519,
@@ -416,15 +412,13 @@ START_TEST(test_curve25519_ed25519_speed)
                pubkey->destroy(pubkey);
                chunk_free(&sig);
        }
-       clock_gettime(CLOCK_THREAD_CPUTIME_ID, &stop);
 
+#ifdef HAVE_CLOCK_GETTIME
+       clock_gettime(CLOCK_THREAD_CPUTIME_ID, &stop);
        DBG0(DBG_LIB, "%d Ed25519 keys and signatures in %d ms\n", count,
                                  (stop.tv_nsec - start.tv_nsec) / 1000000 +
                                  (stop.tv_sec - start.tv_sec) * 1000);
-
-       /* revert to /dev/random for true random source */
-       lib->settings->set_str(lib->settings,
-                               "libstrongswan.plugins.random.random", "/dev/random");
+#endif
 }
 END_TEST
 
@@ -435,7 +429,7 @@ static chunk_t zero_pk = chunk_from_chars(
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00);
 
-START_TEST(test_curve25519_ed25519_fail)
+START_TEST(test_ed25519_fail)
 {
        private_key_t *key;
        public_key_t *pubkey;
@@ -505,28 +499,28 @@ START_TEST(test_curve25519_ed25519_fail)
 }
 END_TEST
 
-Suite *curve25519_ed25519_suite_create()
+Suite *ed25519_suite_create()
 {
        Suite *s;
        TCase *tc;
 
-       s = suite_create("curve25519_ed25519");
+       s = suite_create("ed25519");
 
        tc = tcase_create("ed25519_sign");
-       tcase_add_loop_test(tc, test_curve25519_ed25519_sign, 0, countof(sig_tests));
+       tcase_add_loop_test(tc, test_ed25519_sign, 0, countof(sig_tests));
        suite_add_tcase(s, tc);
 
        tc = tcase_create("ed25519_gen");
-       tcase_add_test(tc, test_curve25519_ed25519_gen);
+       tcase_add_test(tc, test_ed25519_gen);
        suite_add_tcase(s, tc);
 
        tc = tcase_create("ed25519_fail");
-       tcase_add_test(tc, test_curve25519_ed25519_fail);
+       tcase_add_test(tc, test_ed25519_fail);
        suite_add_tcase(s, tc);
 
        tc = tcase_create("ed25519_speed");
        test_case_set_timeout(tc, 10);
-       tcase_add_test(tc, test_curve25519_ed25519_speed);
+       tcase_add_test(tc, test_ed25519_speed);
        suite_add_tcase(s, tc);
 
        return s;
index fabfaa8f81dec16f2b97d7752e4fafb70526e14d..79a88e27d77e422fa3dedb6acb588123a8761a55 100644 (file)
@@ -50,3 +50,5 @@ TEST_SUITE_DEPEND(mgf1_sha1_suite_create, XOF, XOF_MGF1_SHA1)
 TEST_SUITE_DEPEND(mgf1_sha256_suite_create, XOF, XOF_MGF1_SHA256)
 TEST_SUITE_DEPEND(ntru_suite_create, DH, NTRU_112_BIT)
 TEST_SUITE_DEPEND(fetch_http_suite_create, FETCHER, "http://")
+TEST_SUITE_DEPEND(ed25519_suite_create, PRIVKEY_GEN, KEY_ED25519)
+