unit-tests: perform a first ECDSA test case if ECDSA is supported
authorMartin Willi <martin@revosec.ch>
Tue, 9 Apr 2013 13:06:28 +0000 (15:06 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 21 Jun 2013 08:53:21 +0000 (10:53 +0200)
src/libstrongswan/tests/Makefile.am
src/libstrongswan/tests/test_ecdsa.c [new file with mode: 0644]
src/libstrongswan/tests/test_runner.c
src/libstrongswan/tests/test_runner.h

index 3ec1082..b04a755 100644 (file)
@@ -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 (file)
index 0000000..27a4371
--- /dev/null
@@ -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 <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"
+
+/**
+ * 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;
+}
index 35642cb..305ddeb 100644 (file)
@@ -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);
index 16f0679..59515f0 100644 (file)
@@ -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_ */