Add context id getter to TKM DH 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 fail_if(!dh->get_id(dh), "Invalid context id (0)");
31
32 dh->dh.destroy(&dh->dh);
33 }
34 END_TEST
35
36 START_TEST(test_dh_get_my_pubvalue)
37 {
38 tkm_diffie_hellman_t *dh = tkm_diffie_hellman_create(MODP_4096_BIT);
39 fail_if(!dh, "Unable to create DH");
40
41 chunk_t value;
42 dh->dh.get_my_public_value(&dh->dh, &value);
43 dh->dh.destroy(&dh->dh);
44
45 fail_if(value.ptr == NULL, "Pubvalue is NULL");
46 fail_if(value.len != 512, "Pubvalue size mismatch");
47
48 chunk_free(&value);
49 }
50 END_TEST
51
52 TCase *make_diffie_hellman_tests(void)
53 {
54 TCase *tc = tcase_create("Diffie-Hellman tests");
55 tcase_add_test(tc, test_dh_creation);
56 tcase_add_test(tc, test_dh_get_my_pubvalue);
57
58 return tc;
59 }