Add initial TKM Diffie-Hellman implementation
[strongswan.git] / src / charon-tkm / tests / diffie_hellman_tests.c
1 /*
2 * Copyright (C) 2012 Reto Buerki
3 * Copyright (C) 2012 Adrian-Ken Rueegsegger
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include <check.h>
18
19 #include "tkm_diffie_hellman.h"
20
21 START_TEST(test_dh_creation)
22 {
23 tkm_diffie_hellman_t *dh = NULL;
24
25 dh = tkm_diffie_hellman_create(MODP_768_BIT);
26 fail_if(dh, "MODP_768 created");
27
28 dh = tkm_diffie_hellman_create(MODP_4096_BIT);
29 fail_if(!dh, "MODP_4096 not created");
30
31 dh->dh.destroy(&dh->dh);
32 }
33 END_TEST
34
35 START_TEST(test_dh_get_my_pubvalue)
36 {
37 tkm_diffie_hellman_t *dh = tkm_diffie_hellman_create(MODP_4096_BIT);
38 fail_if(!dh, "Unable to create DH");
39
40 chunk_t value;
41 dh->dh.get_my_public_value(&dh->dh, &value);
42 dh->dh.destroy(&dh->dh);
43
44 fail_if(value.ptr == NULL, "Pubvalue is NULL");
45 fail_if(value.len != 512, "Pubvalue size mismatch");
46
47 chunk_free(&value);
48 }
49 END_TEST
50
51 TCase *make_diffie_hellman_tests(void)
52 {
53 TCase *tc = tcase_create("Diffie-Hellman tests");
54 tcase_add_test(tc, test_dh_creation);
55 tcase_add_test(tc, test_dh_get_my_pubvalue);
56
57 return tc;
58 }