unit-tests: Added ntru entropy, retransmission and ciphertext tests

This commit is contained in:
Andreas Steffen 2013-11-21 23:51:02 +01:00
parent 802eaf3789
commit 885e699b58
3 changed files with 69 additions and 0 deletions

View File

@ -193,6 +193,11 @@ METHOD(diffie_hellman_t, set_other_public_value, void,
if (this->priv_key.len)
{
/* initiator decrypting shared secret */
if (value.len == 0)
{
DBG1(DBG_LIB, "empty NTRU ciphertext");
return;
}
this->ciphertext = chunk_clone(value);
DBG3(DBG_LIB, "NTRU ciphertext: %B", &this->ciphertext);

View File

@ -52,4 +52,5 @@ tests_CFLAGS = \
tests_LDFLAGS = @COVERAGE_LDFLAGS@
tests_LDADD = \
$(top_builddir)/src/libstrongswan/libstrongswan.la \
$(top_builddir)/src/libstrongswan/plugins/ntru/libstrongswan-ntru.la \
libtest.la

View File

@ -15,6 +15,8 @@
#include "test_suite.h"
#include <plugins/ntru/ntru_plugin.h>
/**
* NTRU parameter sets to test
*/
@ -35,6 +37,14 @@ char *parameter_sets[] = {
"x9_98_speed", "x9_98_bandwidth", "x9_98_balance", "optimum"
};
START_TEST(test_ntru_entropy)
{
ck_assert(!ntru_plugin_get_entropy(GET_NUM_BYTES_PER_BYTE_OF_ENTROPY, NULL));
ck_assert(!ntru_plugin_get_entropy(GET_BYTE_OF_ENTROPY, NULL));
ck_assert(!ntru_plugin_get_entropy(10, NULL));
}
END_TEST
START_TEST(test_ntru_ke)
{
chunk_t pub_key, cipher_text, i_shared_secret, r_shared_secret;
@ -94,6 +104,22 @@ START_TEST(test_ntru_ke)
}
END_TEST
START_TEST(test_ntru_retransmission)
{
diffie_hellman_t *i_ntru;
chunk_t pub_key1, pub_key2;
i_ntru = lib->crypto->create_dh(lib->crypto, NTRU_256_BIT);
i_ntru->get_my_public_value(i_ntru, &pub_key1);
i_ntru->get_my_public_value(i_ntru, &pub_key2);
ck_assert(chunk_equals(pub_key1, pub_key2));
chunk_free(&pub_key1);
chunk_free(&pub_key2);
i_ntru->destroy(i_ntru);
}
END_TEST
START_TEST(test_ntru_pubkey_oid)
{
chunk_t test[] = {
@ -148,6 +174,31 @@ START_TEST(test_ntru_wrong_set)
}
END_TEST
START_TEST(test_ntru_ciphertext)
{
chunk_t test[] = {
chunk_empty,
chunk_from_chars(0x00),
};
diffie_hellman_t *i_ntru;
chunk_t pub_key, shared_secret;
int i;
for (i = 0; i < countof(test); i++)
{
i_ntru = lib->crypto->create_dh(lib->crypto, NTRU_128_BIT);
i_ntru->get_my_public_value(i_ntru, &pub_key);
i_ntru->set_other_public_value(i_ntru, test[i]);
ck_assert(i_ntru->get_shared_secret(i_ntru, &shared_secret) != SUCCESS);
ck_assert(shared_secret.len == 0);
chunk_free(&pub_key);
i_ntru->destroy(i_ntru);
}
}
END_TEST
Suite *ntru_suite_create()
{
Suite *s;
@ -155,10 +206,18 @@ Suite *ntru_suite_create()
s = suite_create("ntru");
tc = tcase_create("entropy");
tcase_add_test(tc, test_ntru_entropy);
suite_add_tcase(s, tc);
tc = tcase_create("ke");
tcase_add_loop_test(tc, test_ntru_ke, 0, countof(params));
suite_add_tcase(s, tc);
tc = tcase_create("retransmission");
tcase_add_test(tc, test_ntru_retransmission);
suite_add_tcase(s, tc);
tc = tcase_create("pubkey_oid");
tcase_add_test(tc, test_ntru_pubkey_oid);
suite_add_tcase(s, tc);
@ -167,5 +226,9 @@ Suite *ntru_suite_create()
tcase_add_test(tc, test_ntru_wrong_set);
suite_add_tcase(s, tc);
tc = tcase_create("ciphertext");
tcase_add_test(tc, test_ntru_ciphertext);
suite_add_tcase(s, tc);
return s;
}