From: Tobias Brunner Date: Mon, 16 Jul 2018 13:50:09 +0000 (+0200) Subject: unit-tests: Add mock QSKE implementation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98e69c3996c658333bdc9b94de1b0182a5164fbb;p=thirdparty%2Fstrongswan.git unit-tests: Add mock QSKE implementation --- diff --git a/src/libcharon/tests/Makefile.am b/src/libcharon/tests/Makefile.am index 1d925019cf..be1eddc0e7 100644 --- a/src/libcharon/tests/Makefile.am +++ b/src/libcharon/tests/Makefile.am @@ -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 diff --git a/src/libcharon/tests/utils/exchange_test_helper.c b/src/libcharon/tests/utils/exchange_test_helper.c index 8e58b9855c..b924646781 100644 --- a/src/libcharon/tests/utils/exchange_test_helper.c +++ b/src/libcharon/tests/utils/exchange_test_helper.c @@ -18,6 +18,7 @@ #include "mock_ipsec.h" #include "mock_net.h" #include "mock_nonce_gen.h" +#include "mock_qske.h" #include #include @@ -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 index 0000000000..94030f745e --- /dev/null +++ b/src/libcharon/tests/utils/mock_qske.c @@ -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 . + * + * 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 index 0000000000..6ec767d1de --- /dev/null +++ b/src/libcharon/tests/utils/mock_qske.h @@ -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 . + * + * 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 + +/** + * 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_ @}*/