- added compution of all needed keys and also creation of needed
[strongswan.git] / Source / charon / encoding / payloads / transform_substructure.h
1 /**
2 * @file transform_substructure.h
3 *
4 * @brief Declaration of the class transform_substructure_t.
5 *
6 * An object of this type represents an IKEv2 TRANSFORM Substructure and contains Attributes.
7 *
8 */
9
10 /*
11 * Copyright (C) 2005 Jan Hutter, Martin Willi
12 * Hochschule fuer Technik Rapperswil
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 */
24
25 #ifndef TRANSFORM_SUBSTRUCTURE_H_
26 #define TRANSFORM_SUBSTRUCTURE_H_
27
28 #include <types.h>
29 #include <definitions.h>
30 #include <encoding/payloads/payload.h>
31 #include <encoding/payloads/transform_attribute.h>
32 #include <utils/linked_list.h>
33 #include <transforms/diffie_hellman.h>
34 #include <transforms/signers/signer.h>
35 #include <transforms/prfs/prf.h>
36 #include <transforms/crypters/crypter.h>
37
38
39 /**
40 * IKEv1 Value for a transform payload
41 */
42 #define TRANSFORM_TYPE_VALUE 3
43
44 /**
45 * Length of the transform substructure header in bytes
46 */
47 #define TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH 8
48
49
50 typedef enum transform_type_t transform_type_t;
51
52 /**
53 * Type of a transform, as in IKEv2 draft 3.3.2
54 */
55 enum transform_type_t {
56 UNDEFINED_TRANSFORM_TYPE = 241,
57 ENCRYPTION_ALGORITHM = 1,
58 PSEUDO_RANDOM_FUNCTION = 2,
59 INTEGRITY_ALGORITHM = 3,
60 DIFFIE_HELLMAN_GROUP = 4,
61 EXTENDED_SEQUENCE_NUNBERS = 5
62 };
63
64 /**
65 * string mappings for transform_type_t
66 */
67 extern mapping_t transform_type_m[];
68
69
70 typedef enum extended_sequence_numbers_t extended_sequence_numbers_t;
71
72 /**
73 * Extended sequence numbers, as in IKEv2 draft 3.3.2
74 */
75 enum extended_sequence_numbers_t {
76 NO_EXT_SEQ_NUMBERS = 0,
77 EXT_SEQ_NUMBERS = 1
78 };
79
80 /**
81 * string mappings for extended_sequence_numbers_t
82 */
83 extern mapping_t extended_sequence_numbers_m[];
84
85 typedef struct transform_substructure_t transform_substructure_t;
86
87 /**
88 * Object representing an IKEv2- TRANSFORM SUBSTRUCTURE
89 *
90 * The TRANSFORM SUBSTRUCTURE format is described in RFC section 3.3.2.
91 *
92 */
93 struct transform_substructure_t {
94 /**
95 * implements payload_t interface
96 */
97 payload_t payload_interface;
98
99 /**
100 * @brief Creates an iterator of stored transform_attribute_t objects.
101 *
102 * @warning The created iterator has to get destroyed by the caller!
103 *
104 * @warning When deleting an transform attribute using this iterator,
105 * the length of this transform substructure has to be refreshed
106 * by calling get_length()!
107 *
108 * @param this calling transform_substructure_t object
109 * @param iterator the created iterator is stored at the pointed pointer
110 * @param[in] forward iterator direction (TRUE: front to end)
111 * @return
112 * - SUCCESS or
113 * - OUT_OF_RES if iterator could not be created
114 */
115 status_t (*create_transform_attribute_iterator) (transform_substructure_t *this,iterator_t **iterator, bool forward);
116
117 /**
118 * @brief Adds a transform_attribute_t object to this object.
119 *
120 * @warning The added proposal_substructure_t object is
121 * getting destroyed in destroy function of transform_substructure_t.
122 *
123 * @param this calling transform_substructure_t object
124 * @param proposal transform_attribute_t object to add
125 * @return - SUCCESS if succeeded
126 * - FAILED otherwise
127 */
128 status_t (*add_transform_attribute) (transform_substructure_t *this,transform_attribute_t *attribute);
129
130 /**
131 * @brief Sets the next_payload field of this substructure
132 *
133 * If this is the last transform, next payload field is set to 0,
134 * otherwise to 3 (payload type of transform in IKEv1)
135 *
136 * @param this calling transform_substructure_t object
137 * @param is_last When TRUE, next payload field is set to 0, otherwise to 3
138 * @return - SUCCESS
139 */
140 status_t (*set_is_last_transform) (transform_substructure_t *this, bool is_last);
141
142 /**
143 * @brief Checks if this is the last transform.
144 *
145 * @param this calling transform_substructure_t object
146 * @return TRUE if this is the last Transform, FALSE otherwise
147 */
148 bool (*get_is_last_transform) (transform_substructure_t *this);
149
150 /**
151 * @brief Sets transform type of the current transform substructure.
152 *
153 * @param this calling transform_substructure_t object
154 * @param type type value to set
155 * @return - SUCCESS
156 */
157 status_t (*set_transform_type) (transform_substructure_t *this,u_int8_t type);
158
159 /**
160 * @brief get transform type of the current transform.
161 *
162 * @param this calling transform_substructure_t object
163 * @return Transform type of current transform substructure.
164 */
165 u_int8_t (*get_transform_type) (transform_substructure_t *this);
166
167 /**
168 * @brief Sets transform id of the current transform substructure.
169 *
170 * @param this calling transform_substructure_t object
171 * @param id transform id to set
172 * @return - SUCCESS
173 */
174 status_t (*set_transform_id) (transform_substructure_t *this,u_int16_t id);
175
176 /**
177 * @brief get transform id of the current transform.
178 *
179 * @param this calling transform_substructure_t object
180 * @return Transform id of current transform substructure.
181 */
182 u_int16_t (*get_transform_id) (transform_substructure_t *this);
183
184 /**
185 * @brief get transform id of the current transform.
186 *
187 * @param this calling transform_substructure_t object
188 * @param key_length The key length is written to this location
189 * @return
190 * - SUCCESS if a key length attribute is contained
191 * - FAILED if no key length attribute is part of this
192 * transform or key length uses more then 16 bit!
193 * - OUT_OF_RES
194 */
195 status_t (*get_key_length) (transform_substructure_t *this,u_int16_t *key_length);
196
197 /**
198 * @brief Clones an transform_substructure_t object.
199 *
200 * @param this transform_substructure_t object to clone
201 * @param clone pointer to a transform_substructure_t object pointer
202 * where the new object is stored to.
203 * @return
204 * - OUT_OF_RES
205 * - SUCCESS in any case
206 */
207 status_t (*clone) (transform_substructure_t *this,transform_substructure_t **clone);
208
209 /**
210 * @brief Destroys an transform_substructure_t object.
211 *
212 * @param this transform_substructure_t object to destroy
213 * @return
214 * SUCCESS in any case
215 */
216 status_t (*destroy) (transform_substructure_t *this);
217 };
218
219 /**
220 * @brief Creates an empty transform_substructure_t object
221 *
222 * @return
223 * - created transform_substructure_t object, or
224 * - NULL if failed
225 */
226
227 transform_substructure_t *transform_substructure_create();
228
229 #endif /*TRANSFORM_SUBSTRUCTURE_H_*/