Removed unnecessary debug statement
[strongswan.git] / src / libpts / pts / pts_dh_group.c
1 /*
2 * Copyright (C) 2011 Sansar Choinyambuu
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "pts_dh_group.h"
17
18 #include <debug.h>
19
20 /**
21 * Described in header.
22 */
23 bool pts_probe_dh_groups(pts_dh_group_t *groups)
24 {
25 enumerator_t *enumerator;
26 diffie_hellman_group_t dh_group;
27 const char *plugin_name;
28 char format1[] = " %s PTS Diffie Hellman Group %N[%s] available";
29 char format2[] = " %s PTS Diffie Hellman Group %N[%s] not available";
30
31 *groups = 0;
32
33 enumerator = lib->crypto->create_dh_enumerator(lib->crypto);
34 while (enumerator->enumerate(enumerator, &dh_group, &plugin_name))
35 {
36 if (dh_group == MODP_1024_BIT)
37 {
38 *groups |= PTS_DH_GROUP_IKE2;
39 DBG2(DBG_PTS, format1, "optional", diffie_hellman_group_names, dh_group,
40 plugin_name);
41 }
42 else if (dh_group == MODP_1536_BIT)
43 {
44 *groups |= PTS_DH_GROUP_IKE5;
45 DBG2(DBG_PTS, format1, "optional", diffie_hellman_group_names, dh_group,
46 plugin_name);
47 }
48 else if (dh_group == MODP_2048_BIT)
49 {
50 *groups |= PTS_DH_GROUP_IKE14;
51 DBG2(DBG_PTS, format1, "optional", diffie_hellman_group_names, dh_group,
52 plugin_name);
53 }
54 else if (dh_group == ECP_256_BIT)
55 {
56 *groups |= PTS_DH_GROUP_IKE19;
57 DBG2(DBG_PTS, format1, "mandatory", diffie_hellman_group_names, dh_group,
58 plugin_name);
59 }
60 else if (dh_group == ECP_384_BIT)
61 {
62 *groups |= PTS_DH_GROUP_IKE20;
63 DBG2(DBG_PTS, format1, "optional", diffie_hellman_group_names, dh_group,
64 plugin_name);
65 }
66 }
67 enumerator->destroy(enumerator);
68
69 if (*groups & PTS_DH_GROUP_IKE19)
70 {
71 return TRUE;
72 }
73 else
74 {
75 DBG1(DBG_PTS, format2, "mandatory", diffie_hellman_group_names, ECP_256_BIT, plugin_name);
76 }
77
78 return FALSE;
79 }
80
81 /**
82 * Described in header.
83 */
84 bool pts_update_supported_dh_groups(char *dh_group, pts_dh_group_t *groups)
85 {
86 if (strcaseeq(dh_group, "ike20"))
87 {
88 /* nothing to update, all groups are supported */
89 return TRUE;
90 }
91 else if (strcaseeq(dh_group, "ike19"))
92 {
93 /* remove DH Group 20 */
94 *groups = ~PTS_DH_GROUP_IKE20;
95 return TRUE;
96 }
97 else if (strcaseeq(dh_group, "ike14"))
98 {
99 /* remove DH Group 19 and 20 */
100 *groups = ~PTS_DH_GROUP_IKE20 | ~PTS_DH_GROUP_IKE19;
101 return TRUE;
102 }
103 else if (strcaseeq(dh_group, "ike5"))
104 {
105 /* remove DH Group 14, 19 and 20 */
106 *groups = ~PTS_DH_GROUP_IKE20 | ~PTS_DH_GROUP_IKE19
107 | ~PTS_DH_GROUP_IKE14;
108 return TRUE;
109 }
110 else if (strcaseeq(dh_group, "ike2"))
111 {
112 /* remove DH Group 5, 14, 19 and 20 */
113 *groups = ~PTS_DH_GROUP_IKE20 | ~PTS_DH_GROUP_IKE19 |
114 ~PTS_DH_GROUP_IKE14 | ~PTS_DH_GROUP_IKE5;
115 return TRUE;
116 }
117
118 DBG1(DBG_PTS, "Unknown DH Group: %s configured");
119 return FALSE;
120 }
121
122 /**
123 * Described in header.
124 */
125 diffie_hellman_group_t pts_dh_group_to_strongswan_dh_group(pts_dh_group_t dh_group)
126 {
127 switch (dh_group)
128 {
129 case PTS_DH_GROUP_IKE2:
130 return MODP_1024_BIT;
131 case PTS_DH_GROUP_IKE5:
132 return MODP_1536_BIT;
133 case PTS_DH_GROUP_IKE14:
134 return MODP_2048_BIT;
135 case PTS_DH_GROUP_IKE19:
136 return ECP_256_BIT;
137 case PTS_DH_GROUP_IKE20:
138 return ECP_384_BIT;
139 default:
140 return MODP_NONE;
141 }
142 }