unit-tests: created bliss_sign test suite

This commit is contained in:
Andreas Steffen
2014-11-29 14:51:17 +01:00
parent e71813e56d
commit 3e1f6edc5a
5 changed files with 91 additions and 1 deletions
@@ -30,13 +30,22 @@ check_PROGRAMS = $(TESTS)
bliss_tests_SOURCES = \
suites/test_bliss_fft.c \
suites/test_bliss_sign.c \
bliss_fft_params.c \
bliss_fft.c \
bliss_private_key.c \
bliss_public_key.c \
bliss_param_set.c \
bliss_sampler.c \
bliss_signature.c \
bliss_utils.c \
bliss_tests.h bliss_tests.c
bliss_tests_CFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libstrongswan/tests \
-DPLUGINDIR=\""$(abs_top_builddir)/src/libstrongswan/plugins\"" \
-DPLUGINS=\""${s_plugins}\"" \
@COVERAGE_CFLAGS@
bliss_tests_LDFLAGS = @COVERAGE_LDFLAGS@
@@ -166,6 +166,7 @@ static bool verify_bliss_with_sha512(private_bliss_public_key_t *this,
{
if (indices[i] != c_indices[i])
{
DBG1(DBG_LIB, "signature verification failed");
goto end;
}
}
+16 -1
View File
@@ -31,10 +31,25 @@ static test_configuration_t tests[] = {
static bool test_runner_init(bool init)
{
if (!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;
}
@@ -14,4 +14,5 @@
*/
TEST_SUITE(bliss_fft_suite_create)
TEST_SUITE(bliss_sign_suite_create)
@@ -0,0 +1,64 @@
/*
* 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_suite.h"
#include <bliss_private_key.h>
#include <bliss_public_key.h>
static u_int key_type[] = { 1, 3, 4 };
START_TEST(test_bliss_sign_all)
{
private_key_t *privkey;
public_key_t *pubkey;
chunk_t msg, signature;
int verify_count = 1000;
msg = chunk_from_str("Hello Dolly!");
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
BUILD_KEY_SIZE, key_type[_i], BUILD_END);
ck_assert(privkey);
pubkey = privkey->get_public_key(privkey);
ck_assert(pubkey);
while (verify_count--)
{
ck_assert(privkey->sign(privkey, SIGN_BLISS_WITH_SHA512, msg,
&signature));
ck_assert(pubkey->verify(pubkey, SIGN_BLISS_WITH_SHA512, msg,
signature));
free(signature.ptr);
}
privkey->destroy(privkey);
pubkey->destroy(pubkey);
}
END_TEST
Suite *bliss_sign_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("bliss_sign");
tc = tcase_create("all");
test_case_set_timeout(tc, 30);
tcase_add_loop_test(tc, test_bliss_sign_all, 0, countof(key_type));
suite_add_tcase(s, tc);
return s;
}