]>
Commit | Line | Data |
---|---|---|
4750f6c6 JH |
1 | /** |
2 | * @file diffie_hellman_test.c | |
3 | * | |
ed37dee6 | 4 | * @brief Tests for the diffie_hellman_t class. |
4750f6c6 JH |
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 | */ | |
4750f6c6 | 22 | |
5113680f MW |
23 | #include <string.h> |
24 | ||
25 | #include "diffie_hellman_test.h" | |
4750f6c6 | 26 | |
0e96f7d8 | 27 | #include <daemon.h> |
94852e75 | 28 | #include <utils/logger_manager.h> |
4a962238 | 29 | #include <encoding/payloads/transform_substructure.h> |
5113680f | 30 | #include <crypto/diffie_hellman.h> |
4750f6c6 JH |
31 | |
32 | /* | |
33 | * described in Header-File | |
34 | */ | |
51d56047 | 35 | void test_diffie_hellman(protected_tester_t *tester) |
4750f6c6 | 36 | { |
6f17c7d6 | 37 | diffie_hellman_t *my_diffie_hellman, *other_diffie_hellman; |
4750f6c6 | 38 | logger_t *logger; |
6f17c7d6 JH |
39 | chunk_t my_public_value, other_public_value; |
40 | chunk_t my_secret, other_secret; | |
4750f6c6 | 41 | |
5113680f | 42 | logger = logger_manager->get_logger(logger_manager,TESTER); |
4750f6c6 JH |
43 | |
44 | ||
6f17c7d6 JH |
45 | my_diffie_hellman = diffie_hellman_create(MODP_1024_BIT); |
46 | tester->assert_true(tester,(my_diffie_hellman != NULL), "create call check"); | |
4750f6c6 | 47 | |
6f17c7d6 JH |
48 | other_diffie_hellman = diffie_hellman_create(MODP_1024_BIT); |
49 | tester->assert_true(tester,(other_diffie_hellman != NULL), "create call check"); | |
4750f6c6 | 50 | |
d0cc48e5 | 51 | my_diffie_hellman->get_my_public_value(my_diffie_hellman,&my_public_value); |
16b9a73c | 52 | logger->log_chunk(logger,RAW,"My public value",my_public_value); |
6f17c7d6 | 53 | |
d0cc48e5 | 54 | other_diffie_hellman->get_my_public_value(other_diffie_hellman,&other_public_value); |
16b9a73c | 55 | logger->log_chunk(logger,RAW,"Other public value",other_public_value); |
6f17c7d6 | 56 | |
d048df5c MW |
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); | |
4750f6c6 | 59 | |
5113680f MW |
60 | free(my_public_value.ptr); |
61 | free(other_public_value.ptr); | |
6f17c7d6 | 62 | |
dec59822 | 63 | tester->assert_true(tester,(my_diffie_hellman->get_shared_secret(my_diffie_hellman,&my_secret) == SUCCESS), "get_shared_secret call check"); |
16b9a73c | 64 | logger->log_chunk(logger,RAW,"My shared secret",my_secret); |
4750f6c6 | 65 | |
dec59822 | 66 | tester->assert_true(tester,(other_diffie_hellman->get_shared_secret(other_diffie_hellman,&other_secret) == SUCCESS), "get_shared_secret call check"); |
16b9a73c | 67 | logger->log_chunk(logger,RAW,"Other shared secret",other_secret); |
6f17c7d6 | 68 | |
dec59822 | 69 | tester->assert_true(tester,(memcmp(my_secret.ptr,other_secret.ptr,other_secret.len) == 0), "shared secret same value check"); |
6f17c7d6 | 70 | |
5113680f MW |
71 | free(my_secret.ptr); |
72 | free(other_secret.ptr); | |
4750f6c6 | 73 | |
d048df5c MW |
74 | my_diffie_hellman->destroy(my_diffie_hellman); |
75 | other_diffie_hellman->destroy(other_diffie_hellman); | |
4750f6c6 | 76 | } |