diff options
author | Martin Willi <martin@strongswan.org> | 2006-04-28 10:51:19 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2006-04-28 10:51:19 +0000 |
commit | 1029d84d2365ca6e6b2d2a96e5c0a1fad3c127e3 (patch) | |
tree | d7d1152d0651f01f023b4faa09fc51f936f89e60 /src/charon/testing/diffie_hellman_test.c | |
parent | 51c3484a9f70f03b2ea73151428a40e785c0c56c (diff) | |
download | strongswan-1029d84d2365ca6e6b2d2a96e5c0a1fad3c127e3.tar.bz2 strongswan-1029d84d2365ca6e6b2d2a96e5c0a1fad3c127e3.tar.xz |
Diffstat (limited to 'src/charon/testing/diffie_hellman_test.c')
-rw-r--r-- | src/charon/testing/diffie_hellman_test.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/charon/testing/diffie_hellman_test.c b/src/charon/testing/diffie_hellman_test.c new file mode 100644 index 000000000..0a44a022a --- /dev/null +++ b/src/charon/testing/diffie_hellman_test.c @@ -0,0 +1,76 @@ +/** + * @file diffie_hellman_test.c + * + * @brief Tests for the diffie_hellman_t class. + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * 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 <string.h> + +#include "diffie_hellman_test.h" + +#include <daemon.h> +#include <utils/logger_manager.h> +#include <encoding/payloads/transform_substructure.h> +#include <crypto/diffie_hellman.h> + +/* + * described in Header-File + */ +void test_diffie_hellman(protected_tester_t *tester) +{ + diffie_hellman_t *my_diffie_hellman, *other_diffie_hellman; + logger_t *logger; + chunk_t my_public_value, other_public_value; + chunk_t my_secret, other_secret; + + logger = logger_manager->get_logger(logger_manager,TESTER); + + + my_diffie_hellman = diffie_hellman_create(MODP_1024_BIT); + tester->assert_true(tester,(my_diffie_hellman != NULL), "create call check"); + + other_diffie_hellman = diffie_hellman_create(MODP_1024_BIT); + tester->assert_true(tester,(other_diffie_hellman != NULL), "create call check"); + + my_diffie_hellman->get_my_public_value(my_diffie_hellman,&my_public_value); + logger->log_chunk(logger,RAW,"My public value",my_public_value); + + other_diffie_hellman->get_my_public_value(other_diffie_hellman,&other_public_value); + logger->log_chunk(logger,RAW,"Other public value",other_public_value); + + my_diffie_hellman->set_other_public_value(my_diffie_hellman,other_public_value); + other_diffie_hellman->set_other_public_value(other_diffie_hellman,my_public_value); + + free(my_public_value.ptr); + free(other_public_value.ptr); + + tester->assert_true(tester,(my_diffie_hellman->get_shared_secret(my_diffie_hellman,&my_secret) == SUCCESS), "get_shared_secret call check"); + logger->log_chunk(logger,RAW,"My shared secret",my_secret); + + tester->assert_true(tester,(other_diffie_hellman->get_shared_secret(other_diffie_hellman,&other_secret) == SUCCESS), "get_shared_secret call check"); + logger->log_chunk(logger,RAW,"Other shared secret",other_secret); + + tester->assert_true(tester,(memcmp(my_secret.ptr,other_secret.ptr,other_secret.len) == 0), "shared secret same value check"); + + free(my_secret.ptr); + free(other_secret.ptr); + + my_diffie_hellman->destroy(my_diffie_hellman); + other_diffie_hellman->destroy(other_diffie_hellman); +} |