]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
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 e6b29ab09bdfa77f030b66bd91198e14e62ba814..bf8d7fda2632ca131f03341885a42978473d214d 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 39e03092ea464dcc5760f8a11c30fb18f56d22c8..33317a4cc64aefd10b1fd8c08ef8e3404be82b06 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 600e159cbec21093714de0d85bd76682a1d7f0f7..ad8373355c1f5e0e7acc99d3c724d6c12f021179 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