- memory allocation tests removed
[strongswan.git] / Source / charon / testcases / diffie_hellman_test.c
1 /**
2 * @file diffie_hellman_test.c
3 *
4 * @brief Tests to test the Diffie Hellman object diffie_hellman_t
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include "diffie_hellman_test.h"
24
25 #include "../transforms/diffie_hellman.h"
26
27 #include <globals.h>
28 #include <utils/logger_manager.h>
29 #include <utils/allocator.h>
30 #include <encoding/payloads/transform_substructure.h>
31
32 /*
33 * described in Header-File
34 */
35 void test_diffie_hellman(tester_t *tester)
36 {
37 diffie_hellman_t *my_diffie_hellman, *other_diffie_hellman;
38 logger_t *logger;
39 chunk_t my_public_value, other_public_value;
40 chunk_t my_secret, other_secret;
41
42 logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Diffie Hellman");
43
44
45 my_diffie_hellman = diffie_hellman_create(MODP_1024_BIT);
46 tester->assert_true(tester,(my_diffie_hellman != NULL), "create call check");
47
48 other_diffie_hellman = diffie_hellman_create(MODP_1024_BIT);
49 tester->assert_true(tester,(other_diffie_hellman != NULL), "create call check");
50
51 my_diffie_hellman->get_my_public_value(my_diffie_hellman,&my_public_value);
52 logger->log_chunk(logger,RAW,"My public value",&my_public_value);
53
54 other_diffie_hellman->get_my_public_value(other_diffie_hellman,&other_public_value);
55 logger->log_chunk(logger,RAW,"Other public value",&other_public_value);
56
57 my_diffie_hellman->set_other_public_value(my_diffie_hellman,other_public_value);
58 other_diffie_hellman->set_other_public_value(other_diffie_hellman,my_public_value);
59
60 allocator_free(my_public_value.ptr);
61 allocator_free(other_public_value.ptr);
62
63 tester->assert_true(tester,( my_diffie_hellman->get_shared_secret(my_diffie_hellman,&my_secret) == SUCCESS), "get_shared_secret call check");
64 logger->log_chunk(logger,RAW,"My shared secret",&my_secret);
65
66 tester->assert_true(tester,( other_diffie_hellman->get_shared_secret(other_diffie_hellman,&other_secret) == SUCCESS), "get_shared_secret call check");
67 logger->log_chunk(logger,RAW,"Other shared secret",&other_secret);
68
69 tester->assert_true(tester,( memcmp(my_secret.ptr,other_secret.ptr,other_secret.len) == 0), "shared secret same value check");
70
71 allocator_free(my_secret.ptr);
72 allocator_free(other_secret.ptr);
73
74 my_diffie_hellman->destroy(my_diffie_hellman);
75 other_diffie_hellman->destroy(other_diffie_hellman);
76 global_logger_manager->destroy_logger(global_logger_manager,logger);
77 }