From: Tobias Brunner Date: Thu, 28 Nov 2013 17:06:09 +0000 (+0100) Subject: unit-tests: Export ntru_drbg_create as testable function so no linking is required X-Git-Tag: 5.1.2.dr2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5a0abfa9201b73c2c2e42c852c60831aadf218a;p=thirdparty%2Fstrongswan.git unit-tests: Export ntru_drbg_create as testable function so no linking is required This way the plugin does not have to be linked explicitly to the test runner, which otherwise would require that the plugin is either always enabled to build the tests or that ifdefs are added to the Makefile. --- diff --git a/src/libstrongswan/plugins/ntru/ntru_drbg.c b/src/libstrongswan/plugins/ntru/ntru_drbg.c index e6b29ab09b..bf8d7fda26 100644 --- a/src/libstrongswan/plugins/ntru/ntru_drbg.c +++ b/src/libstrongswan/plugins/ntru/ntru_drbg.c @@ -16,6 +16,7 @@ #include "ntru_drbg.h" #include +#include #define MAX_STRENGTH_BITS 256 #define MAX_DRBG_REQUESTS 0xfffffffe @@ -80,7 +81,7 @@ static bool update(private_ntru_drbg_t *this, chunk_t data) !this->hmac->get_signature(this->hmac, this->value, NULL) || !this->hmac->get_signature(this->hmac, ch_00, NULL) || !this->hmac->get_signature(this->hmac, data, this->key.ptr) || - !this->hmac->set_key(this->hmac, this->key) || + !this->hmac->set_key(this->hmac, this->key) || !this->hmac->get_signature(this->hmac, this->value, this->value.ptr)) { @@ -93,7 +94,7 @@ static bool update(private_ntru_drbg_t *this, chunk_t data) !this->hmac->get_signature(this->hmac, this->value, NULL) || !this->hmac->get_signature(this->hmac, ch_01, NULL) || !this->hmac->get_signature(this->hmac, data, this->key.ptr) || - !this->hmac->set_key(this->hmac, this->key) || + !this->hmac->set_key(this->hmac, this->key) || !this->hmac->get_signature(this->hmac, this->value, this->value.ptr)) { @@ -147,7 +148,7 @@ METHOD(ntru_drbg_t, generate, bool, { return FALSE; } - output = chunk_create(out, len); + output = chunk_create(out, len); if (this->reseed_counter > this->max_requests) { @@ -175,7 +176,7 @@ METHOD(ntru_drbg_t, generate, bool, return FALSE; } this->reseed_counter++; - + return TRUE; } @@ -227,7 +228,7 @@ ntru_drbg_t *ntru_drbg_create(u_int32_t strength, chunk_t pers_str, DBG1(DBG_LIB, "could not instantiate HMAC-SHA256"); return NULL; } - + max_requests = lib->settings->get_int(lib->settings, "libstrongswan.plugins.ntru.max_drbg_requests", MAX_DRBG_REQUESTS); @@ -275,3 +276,4 @@ ntru_drbg_t *ntru_drbg_create(u_int32_t strength, chunk_t pers_str, return &this->public; } +EXPORT_FUNCTION_FOR_TESTS(ntru, ntru_drbg_create); diff --git a/src/libstrongswan/tests/Makefile.am b/src/libstrongswan/tests/Makefile.am index 39e03092ea..33317a4cc6 100644 --- a/src/libstrongswan/tests/Makefile.am +++ b/src/libstrongswan/tests/Makefile.am @@ -53,5 +53,4 @@ 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 diff --git a/src/libstrongswan/tests/suites/test_ntru.c b/src/libstrongswan/tests/suites/test_ntru.c index 600e159cbe..ad8373355c 100644 --- a/src/libstrongswan/tests/suites/test_ntru.c +++ b/src/libstrongswan/tests/suites/test_ntru.c @@ -17,6 +17,10 @@ #include #include +#include + +IMPORT_FUNCTION_FOR_TESTS(ntru, ntru_drbg_create, ntru_drbg_t*, + u_int32_t strength, chunk_t pers_str, rng_t *entropy) /** * NTRU parameter sets to test