]>
git.ipfire.org Git - people/ms/strongswan.git/blob - Source/testing/diffie_hellman_test.c
2 * @file diffie_hellman_test.c
4 * @brief Tests for the diffie_hellman_t class.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
25 #include "diffie_hellman_test.h"
28 #include <utils/logger_manager.h>
29 #include <encoding/payloads/transform_substructure.h>
30 #include <crypto/diffie_hellman.h>
33 * described in Header-File
35 void test_diffie_hellman(protected_tester_t
*tester
)
37 diffie_hellman_t
*my_diffie_hellman
, *other_diffie_hellman
;
39 chunk_t my_public_value
, other_public_value
;
40 chunk_t my_secret
, other_secret
;
42 logger
= logger_manager
->get_logger(logger_manager
,TESTER
);
45 my_diffie_hellman
= diffie_hellman_create(MODP_1024_BIT
);
46 tester
->assert_true(tester
,(my_diffie_hellman
!= NULL
), "create call check");
48 other_diffie_hellman
= diffie_hellman_create(MODP_1024_BIT
);
49 tester
->assert_true(tester
,(other_diffie_hellman
!= NULL
), "create call check");
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
);
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
);
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
);
60 free(my_public_value
.ptr
);
61 free(other_public_value
.ptr
);
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
);
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
);
69 tester
->assert_true(tester
,(memcmp(my_secret
.ptr
,other_secret
.ptr
,other_secret
.len
) == 0), "shared secret same value check");
72 free(other_secret
.ptr
);
74 my_diffie_hellman
->destroy(my_diffie_hellman
);
75 other_diffie_hellman
->destroy(other_diffie_hellman
);