From: Martin Willi Date: Tue, 9 Apr 2013 13:06:28 +0000 (+0200) Subject: unit-tests: perform a first ECDSA test case if ECDSA is supported X-Git-Tag: 5.1.0dr1~97^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d18ff88faf57a18f3aa0c25d7cb740a358f706f1;p=thirdparty%2Fstrongswan.git unit-tests: perform a first ECDSA test case if ECDSA is supported --- diff --git a/src/libstrongswan/tests/Makefile.am b/src/libstrongswan/tests/Makefile.am index 3ec10826be..b04a755c83 100644 --- a/src/libstrongswan/tests/Makefile.am +++ b/src/libstrongswan/tests/Makefile.am @@ -6,7 +6,7 @@ test_runner_SOURCES = \ test_runner.c test_runner.h test_suite.h \ test_linked_list.c test_enumerator.c test_linked_list_enumerator.c \ test_bio_reader.c test_bio_writer.c test_chunk.c test_enum.c test_hashtable.c \ - test_identification.c test_threading.c test_utils.c test_vectors.c + test_identification.c test_threading.c test_utils.c test_vectors.c test_ecdsa.c test_runner_CFLAGS = \ -I$(top_srcdir)/src/libstrongswan \ diff --git a/src/libstrongswan/tests/test_ecdsa.c b/src/libstrongswan/tests/test_ecdsa.c new file mode 100644 index 0000000000..27a4371699 --- /dev/null +++ b/src/libstrongswan/tests/test_ecdsa.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2013 Martin Willi + * Copyright (C) 2013 revosec AG + * + * 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 . + * + * 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" + +/** + * ECDSA key sizes to test + */ +static int key_sizes[] = { + 256, 384, 521, +}; + +START_TEST(test_gen) +{ + private_key_t *privkey; + public_key_t *pubkey; + + privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA, + BUILD_KEY_SIZE, key_sizes[_i], BUILD_END); + ck_assert(privkey != NULL); + pubkey = privkey->get_public_key(privkey); + ck_assert(pubkey != NULL); + pubkey->destroy(pubkey); + privkey->destroy(privkey); +} +END_TEST + +Suite *ecdsa_suite_create() +{ + Suite *s; + TCase *tc; + + s = suite_create("ecdsa"); + + tc = tcase_create("generate"); + tcase_add_loop_test(tc, test_gen, 0, countof(key_sizes)); + suite_add_tcase(s, tc); + + return s; +} diff --git a/src/libstrongswan/tests/test_runner.c b/src/libstrongswan/tests/test_runner.c index 35642cbb6c..305ddebfe8 100644 --- a/src/libstrongswan/tests/test_runner.c +++ b/src/libstrongswan/tests/test_runner.c @@ -83,6 +83,10 @@ int main() srunner_add_suite(sr, threading_suite_create()); srunner_add_suite(sr, utils_suite_create()); srunner_add_suite(sr, vectors_suite_create()); + if (has_feature(PLUGIN_DEPENDS(PRIVKEY_GEN, KEY_ECDSA))) + { + srunner_add_suite(sr, ecdsa_suite_create()); + } srunner_run_all(sr, CK_NORMAL); nf = srunner_ntests_failed(sr); diff --git a/src/libstrongswan/tests/test_runner.h b/src/libstrongswan/tests/test_runner.h index 16f067957f..59515f0cdd 100644 --- a/src/libstrongswan/tests/test_runner.h +++ b/src/libstrongswan/tests/test_runner.h @@ -30,5 +30,6 @@ Suite *identification_suite_create(); Suite *threading_suite_create(); Suite *utils_suite_create(); Suite *vectors_suite_create(); +Suite *ecdsa_suite_create(); #endif /** TEST_RUNNER_H_ */