implemented and tested functionality to create sa_payload from
[strongswan.git] / Source / charon / encoding / payloads / transform_substructure.h
1 /**
2 * @file transform_substructure.h
3 *
4 * @brief Interface of transform_substructure_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23 #ifndef TRANSFORM_SUBSTRUCTURE_H_
24 #define TRANSFORM_SUBSTRUCTURE_H_
25
26 #include <types.h>
27 #include <definitions.h>
28 #include <encoding/payloads/payload.h>
29 #include <encoding/payloads/transform_attribute.h>
30 #include <utils/linked_list.h>
31 #include <transforms/diffie_hellman.h>
32 #include <transforms/signers/signer.h>
33 #include <transforms/prfs/prf.h>
34 #include <transforms/crypters/crypter.h>
35
36
37 /**
38 * IKEv1 Value for a transform payload.
39 *
40 * @ingroup payloads
41 */
42 #define TRANSFORM_TYPE_VALUE 3
43
44 /**
45 * Length of the transform substructure header in bytes.
46 *
47 * @ingroup payloads
48 */
49 #define TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH 8
50
51
52 typedef enum transform_type_t transform_type_t;
53
54 /**
55 * Type of a transform, as in IKEv2 draft 3.3.2.
56 *
57 * @ingroup payloads
58 */
59 enum transform_type_t {
60 UNDEFINED_TRANSFORM_TYPE = 241,
61 ENCRYPTION_ALGORITHM = 1,
62 PSEUDO_RANDOM_FUNCTION = 2,
63 INTEGRITY_ALGORITHM = 3,
64 DIFFIE_HELLMAN_GROUP = 4,
65 EXTENDED_SEQUENCE_NUNBERS = 5
66 };
67
68 /**
69 * String mappings for transform_type_t.
70 *
71 * @ingroup payloads
72 */
73 extern mapping_t transform_type_m[];
74
75
76 typedef enum extended_sequence_numbers_t extended_sequence_numbers_t;
77
78 /**
79 * Extended sequence numbers, as in IKEv2 draft 3.3.2.
80 *
81 * @ingroup payloads
82 */
83 enum extended_sequence_numbers_t {
84 NO_EXT_SEQ_NUMBERS = 0,
85 EXT_SEQ_NUMBERS = 1
86 };
87
88 /**
89 * String mappings for extended_sequence_numbers_t.
90 *
91 * @ingroup payloads
92 */
93 extern mapping_t extended_sequence_numbers_m[];
94
95 typedef struct transform_substructure_t transform_substructure_t;
96
97 /**
98 * Object representing an IKEv2- TRANSFORM SUBSTRUCTURE.
99 *
100 * The TRANSFORM SUBSTRUCTURE format is described in RFC section 3.3.2.
101 *
102 * @ingroup payloads
103 */
104 struct transform_substructure_t {
105 /**
106 * The payload_t interface.
107 */
108 payload_t payload_interface;
109
110 /**
111 * @brief Creates an iterator of stored transform_attribute_t objects.
112 *
113 * @warning The created iterator has to get destroyed by the caller!
114 *
115 * @warning When deleting an transform attribute using this iterator,
116 * the length of this transform substructure has to be refreshed
117 * by calling get_length()!
118 *
119 * @param this calling transform_substructure_t object
120 * @param[in] forward iterator direction (TRUE: front to end)
121 * @return created iterator_t object.
122 */
123 iterator_t * (*create_transform_attribute_iterator) (transform_substructure_t *this, bool forward);
124
125 /**
126 * @brief Adds a transform_attribute_t object to this object.
127 *
128 * @warning The added proposal_substructure_t object is
129 * getting destroyed in destroy function of transform_substructure_t.
130 *
131 * @param this calling transform_substructure_t object
132 * @param proposal transform_attribute_t object to add
133 */
134 void (*add_transform_attribute) (transform_substructure_t *this,transform_attribute_t *attribute);
135
136 /**
137 * @brief Sets the next_payload field of this substructure
138 *
139 * If this is the last transform, next payload field is set to 0,
140 * otherwise to 3
141 *
142 * @param this calling transform_substructure_t object
143 * @param is_last When TRUE, next payload field is set to 0, otherwise to 3
144 */
145 void (*set_is_last_transform) (transform_substructure_t *this, bool is_last);
146
147 /**
148 * @brief Checks if this is the last transform.
149 *
150 * @param this calling transform_substructure_t object
151 * @return TRUE if this is the last Transform, FALSE otherwise
152 */
153 bool (*get_is_last_transform) (transform_substructure_t *this);
154
155 /**
156 * @brief Sets transform type of the current transform substructure.
157 *
158 * @param this calling transform_substructure_t object
159 * @param type type value to set
160 */
161 void (*set_transform_type) (transform_substructure_t *this,u_int8_t type);
162
163 /**
164 * @brief get transform type of the current transform.
165 *
166 * @param this calling transform_substructure_t object
167 * @return Transform type of current transform substructure.
168 */
169 u_int8_t (*get_transform_type) (transform_substructure_t *this);
170
171 /**
172 * @brief Sets transform id of the current transform substructure.
173 *
174 * @param this calling transform_substructure_t object
175 * @param id transform id to set
176 */
177 void (*set_transform_id) (transform_substructure_t *this,u_int16_t id);
178
179 /**
180 * @brief get transform id of the current transform.
181 *
182 * @param this calling transform_substructure_t object
183 * @return Transform id of current transform substructure.
184 */
185 u_int16_t (*get_transform_id) (transform_substructure_t *this);
186
187 /**
188 * @brief get transform id of the current transform.
189 *
190 * @param this calling transform_substructure_t object
191 * @param key_length The key length is written to this location
192 * @return
193 * - SUCCESS if a key length attribute is contained
194 * - FAILED if no key length attribute is part of this
195 * transform or key length uses more then 16 bit!
196 */
197 status_t (*get_key_length) (transform_substructure_t *this,u_int16_t *key_length);
198
199 /**
200 * @brief Clones an transform_substructure_t object.
201 *
202 * @param this transform_substructure_t object to clone
203 * @return cloned transform_substructure_t object
204 */
205 transform_substructure_t* (*clone) (transform_substructure_t *this);
206
207 /**
208 * @brief Destroys an transform_substructure_t object.
209 *
210 * @param this transform_substructure_t object to destroy
211 */
212 void (*destroy) (transform_substructure_t *this);
213 };
214
215 /**
216 * @brief Creates an empty transform_substructure_t object.
217 *
218 * @return created transform_substructure_t object
219 *
220 * @ingroup payloads
221 */
222 transform_substructure_t *transform_substructure_create();
223
224 /**
225 * @brief Creates an empty transform_substructure_t object.
226 *
227 * The key length is used for the transport types ENCRYPTION_ALGORITHM,
228 * PSEUDO_RANDOM_FUNCTION, INTEGRITY_ALGORITHM. For all
229 * other transport types the key_length parameter is not used
230 *
231 * @return created transform_substructure_t object
232 * @param transform_type type of transform to create
233 * @param transform_id transform id specifying the specific algorithm of a transform type
234 * @param key_length Key length for key lenght attribute
235 *
236 * @ingroup payloads
237 */
238 transform_substructure_t *transform_substructure_create_type(transform_type_t transform_type, u_int16_t transform_id, u_int16_t key_length);
239
240 #endif /*TRANSFORM_SUBSTRUCTURE_H_*/