]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Register nonce generator and make first nonce byte configurable
authorTobias Brunner <tobias@strongswan.org>
Tue, 17 May 2016 18:06:24 +0000 (20:06 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 17 Jun 2016 16:48:02 +0000 (18:48 +0200)
src/libcharon/tests/utils/exchange_test_helper.c
src/libcharon/tests/utils/exchange_test_helper.h

index 47da9e49a75a69e78ad0af6a58a2de15677ec92e..018804e6c85dd35344dc923816394d46aabc2928 100644 (file)
@@ -14,8 +14,9 @@
  */
 
 #include "exchange_test_helper.h"
-#include "mock_ipsec.h"
 #include "mock_dh.h"
+#include "mock_ipsec.h"
+#include "mock_nonce_gen.h"
 
 #include <credentials/sets/mem_cred.h>
 
@@ -196,6 +197,14 @@ static void initialize_logging()
        charon->load_loggers(charon, NULL, TRUE);
 }
 
+/**
+ * Create a nonce generator with the first byte
+ */
+static nonce_gen_t *create_nonce_gen()
+{
+       return mock_nonce_gen_create(exchange_test_helper->nonce_first_byte);
+}
+
 /*
  * Described in header
  */
@@ -208,6 +217,9 @@ void exchange_test_helper_init(char *plugins)
                        PLUGIN_PROVIDE(DH, MODP_2048_BIT),
                        PLUGIN_PROVIDE(DH, MODP_3072_BIT),
                        PLUGIN_PROVIDE(DH, ECP_256_BIT),
+               PLUGIN_REGISTER(NONCE_GEN, create_nonce_gen),
+                       PLUGIN_PROVIDE(NONCE_GEN),
+                               PLUGIN_DEPENDS(RNG, RNG_WEAK),
        };
 
        INIT(this,
index 9768d42d0f2325ab82bd191dc244b7d097dedef5..861ce0d47538617305f43a39781478b929a5cab6 100644 (file)
@@ -40,6 +40,12 @@ struct exchange_test_helper_t {
         */
        mock_sender_t *sender;
 
+       /**
+        * Set the initial byte of all nonces generated by future nonce
+        * generators (already instatiated nonce generators are not affected).
+        */
+       u_char nonce_first_byte;
+
        /**
         * Creates an established IKE_SA/CHILD_SA
         *