diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2013-11-20 00:14:07 +0100 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2013-11-27 20:21:40 +0100 |
commit | 2c620cb08966a09b2c5e02cce8d290cfec29a5a1 (patch) | |
tree | e292ff7191c0a35f463f70078ba80a8bfa4b0fd9 | |
parent | d5cd6eba2b1d1f53a3b5b3e895bc2bfcf6fe6fbc (diff) | |
download | strongswan-2c620cb08966a09b2c5e02cce8d290cfec29a5a1.tar.bz2 strongswan-2c620cb08966a09b2c5e02cce8d290cfec29a5a1.tar.xz |
unit-tests: first NTRU test case
-rw-r--r-- | src/libstrongswan/plugins/ntru/Makefile.am | 2 | ||||
-rw-r--r-- | src/libstrongswan/tests/Makefile.am | 3 | ||||
-rw-r--r-- | src/libstrongswan/tests/suites/test_ntru.c | 90 | ||||
-rw-r--r-- | src/libstrongswan/tests/tests.h | 2 |
4 files changed, 95 insertions, 2 deletions
diff --git a/src/libstrongswan/plugins/ntru/Makefile.am b/src/libstrongswan/plugins/ntru/Makefile.am index 67f4a57ee..ebfe95d0b 100644 --- a/src/libstrongswan/plugins/ntru/Makefile.am +++ b/src/libstrongswan/plugins/ntru/Makefile.am @@ -2,7 +2,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/libstrongswan AM_CFLAGS = \ - -rdynamic + -rdynamic @COVERAGE_CFLAGS@ if MONOLITHIC noinst_LTLIBRARIES = libstrongswan-ntru.la diff --git a/src/libstrongswan/tests/Makefile.am b/src/libstrongswan/tests/Makefile.am index d785f240d..f21c63299 100644 --- a/src/libstrongswan/tests/Makefile.am +++ b/src/libstrongswan/tests/Makefile.am @@ -39,7 +39,8 @@ tests_SOURCES = tests.h tests.c \ suites/test_host.c \ suites/test_pen.c \ suites/test_asn1.c \ - suites/test_printf.c + suites/test_printf.c \ + suites/test_ntru.c tests_CFLAGS = \ -I$(top_srcdir)/src/libstrongswan \ diff --git a/src/libstrongswan/tests/suites/test_ntru.c b/src/libstrongswan/tests/suites/test_ntru.c new file mode 100644 index 000000000..fb735e6ce --- /dev/null +++ b/src/libstrongswan/tests/suites/test_ntru.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2013 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_suite.h" + +/** + * NTRU parameter sets to test + */ +static struct { + diffie_hellman_group_t group; + char *group_name; +} params[] = { + { NTRU_112_BIT, "NTRU_112" }, + { NTRU_128_BIT, "NTRU_128" }, + { NTRU_192_BIT, "NTRU_192" }, + { NTRU_256_BIT, "NTRU_256" } +}; + +START_TEST(test_ke) +{ + chunk_t pub_key, cipher_text, i_shared_secret, r_shared_secret; + diffie_hellman_t *i_ntru, *r_ntru; + char buf[10]; + int len; + status_t status; + + len = snprintf(buf, sizeof(buf), "%N", diffie_hellman_group_names, + params[_i].group); + ck_assert(len == 8); + ck_assert(streq(buf, params[_i].group_name)); + + i_ntru = lib->crypto->create_dh(lib->crypto, params[_i].group); + ck_assert(i_ntru != NULL); + ck_assert(i_ntru->get_dh_group(i_ntru) == params[_i].group); + + i_ntru->get_my_public_value(i_ntru, &pub_key); + ck_assert(pub_key.len > 0); + + r_ntru = lib->crypto->create_dh(lib->crypto, params[_i].group); + ck_assert(r_ntru != NULL); + + r_ntru->set_other_public_value(r_ntru, pub_key); + r_ntru->get_my_public_value(r_ntru, &cipher_text); + ck_assert(cipher_text.len > 0); + + i_ntru->set_other_public_value(i_ntru, cipher_text); + status = i_ntru->get_shared_secret(i_ntru, &i_shared_secret); + ck_assert(status == SUCCESS); + ck_assert(i_shared_secret.len > 0); + + status = r_ntru->get_shared_secret(r_ntru, &r_shared_secret); + ck_assert(status == SUCCESS); + ck_assert(r_shared_secret.len > 0); + + ck_assert(chunk_equals(i_shared_secret, r_shared_secret)); + + chunk_clear(&i_shared_secret); + chunk_clear(&r_shared_secret); + chunk_free(&pub_key); + chunk_free(&cipher_text); + i_ntru->destroy(i_ntru); + r_ntru->destroy(r_ntru); +} +END_TEST + +Suite *ntru_suite_create() +{ + Suite *s; + TCase *tc; + + s = suite_create("ntru"); + + tc = tcase_create("ke"); + tcase_add_loop_test(tc, test_ke, 0, countof(params)); + suite_add_tcase(s, tc); + + return s; +} diff --git a/src/libstrongswan/tests/tests.h b/src/libstrongswan/tests/tests.h index 6316692aa..c00744554 100644 --- a/src/libstrongswan/tests/tests.h +++ b/src/libstrongswan/tests/tests.h @@ -34,3 +34,5 @@ TEST_SUITE(host_suite_create) TEST_SUITE(printf_suite_create) TEST_SUITE(pen_suite_create) TEST_SUITE(asn1_suite_create) +TEST_SUITE_DEPEND(ntru_suite_create, CUSTOM, "ntru-rng") + |