diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2016-12-13 22:47:36 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2016-12-14 11:57:36 +0100 |
commit | 4f19112b1fd1c4440ed70724c6bfb177453ec6e1 (patch) | |
tree | ddf18bac127e113373cc6f94592c4e8d542b5b33 /src | |
parent | e9c2b6658b9381519a54e5eb0a6e33f8d97057b3 (diff) | |
download | strongswan-4f19112b1fd1c4440ed70724c6bfb177453ec6e1.tar.bz2 strongswan-4f19112b1fd1c4440ed70724c6bfb177453ec6e1.tar.xz |
Moved Ed25519 tests to libstrongswan
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/Makefile.am | 4 | ||||
-rw-r--r-- | src/libstrongswan/plugins/curve25519/Makefile.am | 21 | ||||
-rw-r--r-- | src/libstrongswan/plugins/curve25519/tests/.gitignore | 1 | ||||
-rw-r--r-- | src/libstrongswan/plugins/curve25519/tests/Makefile.am | 21 | ||||
-rw-r--r-- | src/libstrongswan/plugins/curve25519/tests/curve25519_tests.c | 60 | ||||
-rw-r--r-- | src/libstrongswan/plugins/curve25519/tests/curve25519_tests.h | 16 | ||||
-rw-r--r-- | src/libstrongswan/tests/Makefile.am | 3 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_ed25519.c (renamed from src/libstrongswan/plugins/curve25519/tests/suites/test_curve25519_ed25519.c) | 40 | ||||
-rw-r--r-- | src/libstrongswan/tests/tests.h | 2 |
9 files changed, 27 insertions, 141 deletions
diff --git a/src/libstrongswan/Makefile.am b/src/libstrongswan/Makefile.am index c3b31fe14..f6d6f5465 100644 --- a/src/libstrongswan/Makefile.am +++ b/src/libstrongswan/Makefile.am @@ -648,7 +648,3 @@ endif if USE_NEWHOPE SUBDIRS += plugins/newhope/tests endif - -if USE_CURVE25519 - SUBDIRS += plugins/curve25519/tests -endif diff --git a/src/libstrongswan/plugins/curve25519/Makefile.am b/src/libstrongswan/plugins/curve25519/Makefile.am index 7bbf2218b..f3e1e9295 100644 --- a/src/libstrongswan/plugins/curve25519/Makefile.am +++ b/src/libstrongswan/plugins/curve25519/Makefile.am @@ -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 index 9c83c3fff..000000000 --- a/src/libstrongswan/plugins/curve25519/tests/.gitignore +++ /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 index 30e18519f..000000000 --- a/src/libstrongswan/plugins/curve25519/tests/Makefile.am +++ /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 index 5ecae234f..000000000 --- a/src/libstrongswan/plugins/curve25519/tests/curve25519_tests.c +++ /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 index f176574f0..000000000 --- a/src/libstrongswan/plugins/curve25519/tests/curve25519_tests.h +++ /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) diff --git a/src/libstrongswan/tests/Makefile.am b/src/libstrongswan/tests/Makefile.am index caa9d3a6a..0231c1c14 100644 --- a/src/libstrongswan/tests/Makefile.am +++ b/src/libstrongswan/tests/Makefile.am @@ -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 \ diff --git a/src/libstrongswan/plugins/curve25519/tests/suites/test_curve25519_ed25519.c b/src/libstrongswan/tests/suites/test_ed25519.c index cdff16327..00842628d 100644 --- a/src/libstrongswan/plugins/curve25519/tests/suites/test_curve25519_ed25519.c +++ b/src/libstrongswan/tests/suites/test_ed25519.c @@ -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; diff --git a/src/libstrongswan/tests/tests.h b/src/libstrongswan/tests/tests.h index fabfaa8f8..79a88e27d 100644 --- a/src/libstrongswan/tests/tests.h +++ b/src/libstrongswan/tests/tests.h @@ -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) + |