unit-tests: Export ntru_drbg_create as testable function so no linking is required
authorTobias Brunner <tobias@strongswan.org>
Thu, 28 Nov 2013 17:06:09 +0000 (18:06 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 4 Dec 2013 19:32:59 +0000 (20:32 +0100)
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.

src/libstrongswan/plugins/ntru/ntru_drbg.c
src/libstrongswan/tests/Makefile.am
src/libstrongswan/tests/suites/test_ntru.c

index e6b29ab..bf8d7fd 100644 (file)
@@ -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);
index 39e0309..33317a4 100644 (file)
@@ -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
index 600e159..ad83733 100644 (file)
 
 #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