]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Add mock QSKE implementation
authorTobias Brunner <tobias@strongswan.org>
Mon, 16 Jul 2018 13:50:09 +0000 (15:50 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 14 May 2019 09:13:04 +0000 (11:13 +0200)
src/libcharon/tests/Makefile.am
src/libcharon/tests/utils/exchange_test_helper.c
src/libcharon/tests/utils/mock_qske.c [new file with mode: 0644]
src/libcharon/tests/utils/mock_qske.h [new file with mode: 0644]

index 1d925019cfc968b4509289471f4d66c074d7d158..be1eddc0e768238775372269f986b84ef14ed5a2 100644 (file)
@@ -39,6 +39,7 @@ exchange_tests_SOURCES = \
   utils/mock_ipsec.h utils/mock_ipsec.c \
   utils/mock_net.h utils/mock_net.c \
   utils/mock_nonce_gen.h utils/mock_nonce_gen.c \
+  utils/mock_qske.h utils/mock_qske.c \
   utils/mock_sender.h utils/mock_sender.c \
   utils/sa_asserts.h \
   exchange_tests.h exchange_tests.c
index 8e58b9855ce807fc5ab6b3843e905c610fb1e7b1..b924646781aa0f6fc835e19c7e1e7983b4fdd90c 100644 (file)
@@ -18,6 +18,7 @@
 #include "mock_ipsec.h"
 #include "mock_net.h"
 #include "mock_nonce_gen.h"
+#include "mock_qske.h"
 
 #include <collections/array.h>
 #include <credentials/sets/mem_cred.h>
@@ -334,6 +335,9 @@ void exchange_test_helper_init(char *plugins)
                        PLUGIN_PROVIDE(DH, MODP_3072_BIT),
                        PLUGIN_PROVIDE(DH, ECP_256_BIT),
                        PLUGIN_PROVIDE(DH, ECP_384_BIT),
+               PLUGIN_REGISTER(QSKE, mock_qske_create),
+                       PLUGIN_PROVIDE(QSKE, QSKE_NEWHOPE_L1),
+                       PLUGIN_PROVIDE(QSKE, QSKE_NEWHOPE_L5),
                PLUGIN_REGISTER(NONCE_GEN, create_nonce_gen),
                        PLUGIN_PROVIDE(NONCE_GEN),
                                PLUGIN_DEPENDS(RNG, RNG_WEAK),
diff --git a/src/libcharon/tests/utils/mock_qske.c b/src/libcharon/tests/utils/mock_qske.c
new file mode 100644 (file)
index 0000000..94030f7
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2018 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "mock_qske.h"
+
+typedef struct private_qske_t private_qske_t;
+
+/**
+ * Private data
+ */
+struct private_qske_t {
+
+       /**
+        * Public interface
+        */
+       qske_t public;
+
+       /**
+        * Instantiated QSKE mechanism
+        */
+       qske_mechanism_t mechanism;
+};
+
+METHOD(qske_t, get_qske_mechanism, qske_mechanism_t,
+       private_qske_t *this)
+{
+       return this->mechanism;
+}
+
+METHOD(qske_t, get_public_key, bool,
+       private_qske_t *this, chunk_t *value)
+{
+       *value = chunk_empty;
+       return TRUE;
+}
+
+METHOD(qske_t, set_public_key, bool,
+       private_qske_t *this, chunk_t value)
+{
+       return TRUE;
+}
+
+METHOD(qske_t, get_ciphertext, bool,
+       private_qske_t *this, chunk_t *value)
+{
+       *value = chunk_empty;
+       return TRUE;
+}
+
+METHOD(qske_t, set_ciphertext, bool,
+       private_qske_t *this, chunk_t value)
+{
+       return TRUE;
+}
+
+METHOD(qske_t, get_shared_secret, bool,
+       private_qske_t *this, chunk_t *secret)
+{
+       *secret = chunk_empty;
+       return TRUE;
+}
+
+METHOD(qske_t, set_nist_drbg_mode, bool,
+       private_qske_t *this, bool enable, chunk_t seed)
+{
+       return TRUE;
+}
+
+METHOD(qske_t, destroy, void,
+       private_qske_t *this)
+{
+       free(this);
+}
+
+/**
+ * See header
+ */
+qske_t *mock_qske_create(qske_mechanism_t mechanism)
+{
+       private_qske_t *this;
+
+       INIT(this,
+               .public = {
+                       .get_qske_mechanism = _get_qske_mechanism,
+                       .get_public_key = _get_public_key,
+                       .set_public_key = _set_public_key,
+                       .get_ciphertext = _get_ciphertext,
+                       .set_ciphertext = _set_ciphertext,
+                       .get_shared_secret = _get_shared_secret,
+                       .set_nist_drbg_mode = _set_nist_drbg_mode,
+                       .destroy = _destroy,
+               },
+               .mechanism = mechanism,
+       );
+       return &this->public;
+}
diff --git a/src/libcharon/tests/utils/mock_qske.h b/src/libcharon/tests/utils/mock_qske.h
new file mode 100644 (file)
index 0000000..6ec767d
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * Provides a QSKE implementation that does no real work to make the tests run
+ * faster.
+ *
+ * @defgroup mock_qske mock_qske
+ * @{ @ingroup test_utils_c
+ */
+
+#ifndef MOCK_QSKE_H_
+#define MOCK_QSKE_H_
+
+#include <crypto/qske_mechanism.h>
+
+/**
+ * Creates a qske_t object.
+ *
+ * @param mechanism            QSKE mechanism
+ * @return                             created object
+ */
+qske_t *mock_qske_create(qske_mechanism_t mechanism);
+
+#endif /** MOCK_QSKE_H_ @}*/