From: Andreas Steffen Date: Wed, 4 Dec 2013 20:23:30 +0000 (+0100) Subject: Moved test_rng to a test suite of its own X-Git-Tag: 5.1.2.dr2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2006709ec512b8cbdae116722666de764d1881d5;p=thirdparty%2Fstrongswan.git Moved test_rng to a test suite of its own --- diff --git a/src/libstrongswan/tests/Makefile.am b/src/libstrongswan/tests/Makefile.am index 33317a4cc6..9dbfe78d4b 100644 --- a/src/libstrongswan/tests/Makefile.am +++ b/src/libstrongswan/tests/Makefile.am @@ -41,6 +41,7 @@ tests_SOURCES = tests.h tests.c \ suites/test_pen.c \ suites/test_asn1.c \ suites/test_printf.c \ + suites/test_test_rng.c \ suites/test_ntru.c tests_CFLAGS = \ diff --git a/src/libstrongswan/tests/suites/test_ntru.c b/src/libstrongswan/tests/suites/test_ntru.c index ad8373355c..73156208f6 100644 --- a/src/libstrongswan/tests/suites/test_ntru.c +++ b/src/libstrongswan/tests/suites/test_ntru.c @@ -42,28 +42,6 @@ char *parameter_sets[] = { "x9_98_speed", "x9_98_bandwidth", "x9_98_balance", "optimum" }; -START_TEST(test_ntru_test_rng) -{ - rng_t *entropy; - chunk_t in, in1, in2, out; - - in1 = chunk_from_chars(0x01, 0x02, 0x03, 0x04, 0x05, 0x06); - in2 = chunk_from_chars(0x07, 0x08); - in = chunk_cat("cc", in1, in2); - - entropy = test_rng_create(in); - ck_assert(entropy->allocate_bytes(entropy, 6, &out)); - ck_assert(chunk_equals(in1, out)); - ck_assert(entropy->get_bytes(entropy, 2, out.ptr)); - ck_assert(memeq(in2.ptr, out.ptr, in2.len)); - ck_assert(!entropy->get_bytes(entropy, 4, out.ptr)); - chunk_free(&out); - ck_assert(!entropy->allocate_bytes(entropy, 4, &out)); - entropy->destroy(entropy); - chunk_free(&in); -} -END_TEST - typedef struct { u_int32_t requested; u_int32_t standard; @@ -498,10 +476,6 @@ Suite *ntru_suite_create() s = suite_create("ntru"); - tc = tcase_create("test_rng"); - tcase_add_test(tc, test_ntru_test_rng); - suite_add_tcase(s, tc); - tc = tcase_create("drbg_strength"); tcase_add_loop_test(tc, test_ntru_drbg_strength, 0, countof(strengths)); suite_add_tcase(s, tc); diff --git a/src/libstrongswan/tests/suites/test_test_rng.c b/src/libstrongswan/tests/suites/test_test_rng.c new file mode 100644 index 0000000000..9a983b6770 --- /dev/null +++ b/src/libstrongswan/tests/suites/test_test_rng.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2013 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 . + * + * 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 +#include + +START_TEST(test_test_rng) +{ + rng_t *entropy; + chunk_t in, in1, in2, out; + + in1 = chunk_from_chars(0x01, 0x02, 0x03, 0x04, 0x05, 0x06); + in2 = chunk_from_chars(0x07, 0x08); + in = chunk_cat("cc", in1, in2); + + entropy = test_rng_create(in); + ck_assert(entropy->allocate_bytes(entropy, 6, &out)); + ck_assert(chunk_equals(in1, out)); + ck_assert(entropy->get_bytes(entropy, 2, out.ptr)); + ck_assert(memeq(in2.ptr, out.ptr, in2.len)); + ck_assert(!entropy->get_bytes(entropy, 4, out.ptr)); + chunk_free(&out); + ck_assert(!entropy->allocate_bytes(entropy, 4, &out)); + entropy->destroy(entropy); + chunk_free(&in); +} +END_TEST + + +Suite *test_rng_suite_create() +{ + Suite *s; + TCase *tc; + + s = suite_create("test_rng"); + + tc = tcase_create("test_rng"); + tcase_add_test(tc, test_test_rng); + suite_add_tcase(s, tc); + + return s; +} diff --git a/src/libstrongswan/tests/tests.h b/src/libstrongswan/tests/tests.h index 99057be065..eae4e080c7 100644 --- a/src/libstrongswan/tests/tests.h +++ b/src/libstrongswan/tests/tests.h @@ -34,5 +34,6 @@ TEST_SUITE(host_suite_create) TEST_SUITE(printf_suite_create) TEST_SUITE(pen_suite_create) TEST_SUITE(asn1_suite_create) +TEST_SUITE(test_rng_suite_create) TEST_SUITE_DEPEND(ntru_suite_create, DH, NTRU_112_BIT)