aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2013-11-22 20:38:05 +0100
committerAndreas Steffen <andreas.steffen@strongswan.org>2013-11-27 20:21:41 +0100
commit9013973cc8e42d25a37100c14e53408b09ca48f7 (patch)
tree7c6f8f4f41f0ad800be6f4d382a7a03e4c6247d8
parent885e699b58062ab14ca80022180408d3523dd817 (diff)
downloadstrongswan-9013973cc8e42d25a37100c14e53408b09ca48f7.tar.bz2
strongswan-9013973cc8e42d25a37100c14e53408b09ca48f7.tar.xz
unit-tests: Added ntru wrong ciphertext test
-rw-r--r--src/libstrongswan/plugins/ntru/ntru_ke.c1
-rw-r--r--src/libstrongswan/tests/suites/test_ntru.c36
2 files changed, 37 insertions, 0 deletions
diff --git a/src/libstrongswan/plugins/ntru/ntru_ke.c b/src/libstrongswan/plugins/ntru/ntru_ke.c
index 8e4e5e93f..633245a58 100644
--- a/src/libstrongswan/plugins/ntru/ntru_ke.c
+++ b/src/libstrongswan/plugins/ntru/ntru_ke.c
@@ -177,6 +177,7 @@ METHOD(diffie_hellman_t, get_shared_secret, status_t,
{
if (!this->computed || !this->shared_secret.len)
{
+ *secret = chunk_empty;
return FAILED;
}
*secret = chunk_clone(this->shared_secret);
diff --git a/src/libstrongswan/tests/suites/test_ntru.c b/src/libstrongswan/tests/suites/test_ntru.c
index 5b59f53e5..59851eee5 100644
--- a/src/libstrongswan/tests/suites/test_ntru.c
+++ b/src/libstrongswan/tests/suites/test_ntru.c
@@ -176,15 +176,22 @@ END_TEST
START_TEST(test_ntru_ciphertext)
{
+ char buf_00[604], buf_ff[604];
+
chunk_t test[] = {
chunk_empty,
chunk_from_chars(0x00),
+ chunk_create(buf_00, sizeof(buf_00)),
+ chunk_create(buf_ff, sizeof(buf_ff)),
};
diffie_hellman_t *i_ntru;
chunk_t pub_key, shared_secret;
int i;
+ memset(buf_00, 0x00, sizeof(buf_00));
+ memset(buf_ff, 0xff, sizeof(buf_ff));
+
for (i = 0; i < countof(test); i++)
{
i_ntru = lib->crypto->create_dh(lib->crypto, NTRU_128_BIT);
@@ -199,6 +206,32 @@ START_TEST(test_ntru_ciphertext)
}
END_TEST
+START_TEST(test_ntru_wrong_ciphertext)
+{
+ diffie_hellman_t *i_ntru, *r_ntru, *m_ntru;
+ chunk_t pub_key_i, pub_key_m, cipher_text, shared_secret;
+
+ i_ntru = lib->crypto->create_dh(lib->crypto, NTRU_128_BIT);
+ r_ntru = lib->crypto->create_dh(lib->crypto, NTRU_128_BIT);
+ m_ntru = lib->crypto->create_dh(lib->crypto, NTRU_128_BIT);
+
+ i_ntru->get_my_public_value(i_ntru, &pub_key_i);
+ m_ntru->get_my_public_value(m_ntru, &pub_key_m);
+ r_ntru->set_other_public_value(r_ntru, pub_key_m);
+ r_ntru->get_my_public_value(r_ntru, &cipher_text);
+ i_ntru->set_other_public_value(i_ntru, cipher_text);
+ ck_assert(i_ntru->get_shared_secret(i_ntru, &shared_secret) != SUCCESS);
+ ck_assert(shared_secret.len == 0);
+
+ chunk_free(&pub_key_i);
+ chunk_free(&pub_key_m);
+ chunk_free(&cipher_text);
+ i_ntru->destroy(i_ntru);
+ m_ntru->destroy(m_ntru);
+ r_ntru->destroy(r_ntru);
+}
+END_TEST
+
Suite *ntru_suite_create()
{
Suite *s;
@@ -230,5 +263,8 @@ Suite *ntru_suite_create()
tcase_add_test(tc, test_ntru_ciphertext);
suite_add_tcase(s, tc);
+ tc = tcase_create("wrong_ciphertext");
+ tcase_add_test(tc, test_ntru_wrong_ciphertext);
+ suite_add_tcase(s, tc);
return s;
}