aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2013-11-28 18:06:09 +0100
committerAndreas Steffen <andreas.steffen@strongswan.org>2013-12-04 20:32:59 +0100
commitd5a0abfa9201b73c2c2e42c852c60831aadf218a (patch)
treeb59b92590832691d01d56ca4202bf52026d0425d
parent4cea186b64c573a2030a66377c51857b401dbea0 (diff)
downloadstrongswan-d5a0abfa9201b73c2c2e42c852c60831aadf218a.tar.bz2
strongswan-d5a0abfa9201b73c2c2e42c852c60831aadf218a.tar.xz
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.
-rw-r--r--src/libstrongswan/plugins/ntru/ntru_drbg.c12
-rw-r--r--src/libstrongswan/tests/Makefile.am1
-rw-r--r--src/libstrongswan/tests/suites/test_ntru.c4
3 files changed, 11 insertions, 6 deletions
diff --git a/src/libstrongswan/plugins/ntru/ntru_drbg.c b/src/libstrongswan/plugins/ntru/ntru_drbg.c
index e6b29ab09..bf8d7fda2 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 <utils/debug.h>
+#include <utils/test.h>
#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 39e03092e..33317a4cc 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 600e159cb..ad8373355 100644
--- a/src/libstrongswan/tests/suites/test_ntru.c
+++ b/src/libstrongswan/tests/suites/test_ntru.c
@@ -17,6 +17,10 @@
#include <tests/utils/test_rng.h>
#include <plugins/ntru/ntru_drbg.h>
+#include <utils/test.h>
+
+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