- encryptino payload
[strongswan.git] / Source / charon / encoding / payloads / encodings.h
1 /**
2 * @file encodings.h
3 *
4 * @brief Type definitions for parser and generator,
5 * also payload types are defined here.
6 *
7 * Header is parsed like a payload and gets its one payload_id
8 * from PRIVATE USE space. Also the substructures
9 * of specific payload types get their own payload_id
10 * from PRIVATE_USE space. See RFC for mor informations.
11 *
12 */
13
14 /*
15 * Copyright (C) 2005 Jan Hutter, Martin Willi
16 * Hochschule fuer Technik Rapperswil
17 *
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the
20 * Free Software Foundation; either version 2 of the License, or (at your
21 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
22 *
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * for more details.
27 */
28
29 #ifndef ENCODINGS_H_
30 #define ENCODINGS_H_
31
32 #include <types.h>
33 #include <definitions.h>
34
35
36 typedef enum encoding_type_t encoding_type_t;
37
38 /**
39 * @brief All different kinds of encoding types.
40 *
41 * Each field of an IKEv2-Message (in header or payload)
42 * which has to be parsed or generated differently has its own
43 * type defined here.
44 */
45 enum encoding_type_t{
46 /**
47 * Representing a 4 Bit unsigned int value
48 *
49 *
50 * When generating it must be changed from host to network order.
51 * The value is read from the associated data struct.
52 * The current write position is moved 4 bit forward afterwards.
53 *
54 * When parsing it must be changed from network to host order.
55 * The value is written to the associated data struct.
56 * The current read pointer is moved 4 bit forward afterwards.
57 */
58 U_INT_4,
59 /**
60 * Representing a 8 Bit unsigned int value
61 *
62 *
63 * When generating it must be changed from host to network order.
64 * The value is read from the associated data struct.
65 * The current write position is moved 8 bit forward afterwards.
66 *
67 * When parsing it must be changed from network to host order.
68 * The value is written to the associated data struct.
69 * The current read pointer is moved 8 bit forward afterwards.
70 */
71 U_INT_8,
72 /**
73 * Representing a 16 Bit unsigned int value
74 *
75 *
76 * When generating it must be changed from host to network order.
77 * The value is read from the associated data struct.
78 * The current write position is moved 16 bit forward afterwards.
79 *
80 * When parsing it must be changed from network to host order.
81 * The value is written to the associated data struct.
82 * The current read pointer is moved 16 bit forward afterwards.
83 */
84 U_INT_16,
85 /**
86 * Representing a 32 Bit unsigned int value
87 *
88 * When generating it must be changed from host to network order.
89 * The value is read from the associated data struct.
90 * The current write position is moved 32 bit forward afterwards.
91 *
92 * When parsing it must be changed from network to host order.
93 * The value is written to the associated data struct.
94 * The current read pointer is moved 32 bit forward afterwards.
95 */
96
97 U_INT_32,
98 /**
99 * Representing a 64 Bit unsigned int value
100 *
101 * When generating it must be changed from host to network order.
102 * The value is read from the associated data struct.
103 * The current write position is moved 64 bit forward afterwards.
104 *
105 * When parsing it must be changed from network to host order.
106 * The value is written to the associated data struct.
107 * The current read pointer is moved 64 bit forward afterwards.
108 */
109 U_INT_64,
110 /**
111 * @brief represents a RESERVED_BIT used in FLAG-Bytes
112 *
113 * When generating, the next bit is set to zero and the current write
114 * position is moved one bit forward.
115 * No value is read from the associated data struct.
116 * The current write position is moved 1 bit forward afterwards.
117 *
118 * When parsing, the current read pointer is moved one bit forward.
119 * No value is written to the associated data struct.
120 * The current read pointer is moved 1 bit forward afterwards.
121 */
122 RESERVED_BIT,
123 /**
124 * @brief represents a RESERVED_BYTE
125 *
126 * When generating, the next byte is set to zero and the current write
127 * position is moved one byte forward.
128 * No value is read from the associated data struct.
129 * The current write position is moved 1 byte forward afterwards.
130 *
131 * When parsing, the current read pointer is moved one byte forward.
132 * No value is written to the associated data struct.
133 * The current read pointer is moved 1 byte forward afterwards.
134 */
135 RESERVED_BYTE,
136 /**
137 * Representing a 1 Bit flag.
138 *
139 * When generation, the next bit is set to 1 if the associated value
140 * in the data struct is TRUE, 0 otherwise. The current write position
141 * is moved 1 bit forward afterwards.
142 *
143 * When parsing, the next bit is read and stored in the associated data
144 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
145 * is moved 1 bit forward afterwards
146 */
147 FLAG,
148 /**
149 * Representating a length field of a payload
150 *
151 * When generating it must be changed from host to network order.
152 * The value is read from the associated data struct.
153 * The current write position is moved 16 bit forward afterwards.
154 *
155 * When parsing it must be changed from network to host order.
156 * The value is written to the associated data struct.
157 * The current read pointer is moved 16 bit forward afterwards.
158 */
159 PAYLOAD_LENGTH,
160 /**
161 * Representating a length field of a header
162 *
163 * When generating it must be changed from host to network order.
164 * The value is read from the associated data struct.
165 * The current write position is moved 32 bit forward afterwards.
166 *
167 * When parsing it must be changed from network to host order.
168 * The value is written to the associated data struct.
169 * The current read pointer is moved 32 bit forward afterwards.
170 */
171 HEADER_LENGTH,
172 /**
173 * Representating a spi size field
174 *
175 * When generating it must be changed from host to network order.
176 * The value is read from the associated data struct.
177 * The current write position is moved 8 bit forward afterwards.
178 *
179 * When parsing it must be changed from network to host order.
180 * The value is written to the associated data struct.
181 * The current read pointer is moved 8 bit forward afterwards.
182 */
183 SPI_SIZE,
184 /**
185 * Representating a spi field
186 *
187 * When generating the content of the chunkt pointing to
188 * is written.
189 *
190 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
191 */
192 SPI,
193 /**
194 * Representating a Key Exchange Data field
195 *
196 * When generating the content of the chunkt pointing to
197 * is written.
198 *
199 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
200 */
201 KEY_EXCHANGE_DATA,
202 /**
203 * Representating a Notification field
204 *
205 * When generating the content of the chunkt pointing to
206 * is written.
207 *
208 * When parsing (Payload Length - spi size - 8) bytes are read and written into the chunk pointing to.
209 */
210 NOTIFICATION_DATA,
211 /**
212 * Representating one or more proposal substructures
213 *
214 * The offset points to a linked_list_t pointer.
215 *
216 * When generating the proposal_substructure_t objects are stored
217 * in the pointed linked_list.
218 *
219 * When parsing the parsed proposal_substructure_t objects have
220 * to be stored in the pointed linked_list.
221 */
222 PROPOSALS,
223 /**
224 * Representating one or more transform substructures
225 *
226 * The offset points to a linked_list_t pointer.
227 *
228 * When generating the transform_substructure_t objects are stored
229 * in the pointed linked_list.
230 *
231 * When parsing the parsed transform_substructure_t objects have
232 * to be stored in the pointed linked_list.
233 */
234 TRANSFORMS,
235 /**
236 * Representating one or more Attributes of a transform substructure
237 *
238 * The offset points to a linked_list_t pointer.
239 *
240 * When generating the transform_attribute_t objects are stored
241 * in the pointed linked_list.
242 *
243 * When parsing the parsed transform_attribute_t objects have
244 * to be stored in the pointed linked_list.
245 */
246 TRANSFORM_ATTRIBUTES,
247 /**
248 * Representing a 1 Bit flag specifying the format of a transform attribute.
249 *
250 * When generation, the next bit is set to 1 if the associated value
251 * in the data struct is TRUE, 0 otherwise. The current write position
252 * is moved 1 bit forward afterwards.
253 *
254 * When parsing, the next bit is read and stored in the associated data
255 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
256 * is moved 1 bit forward afterwards.
257 */
258 ATTRIBUTE_FORMAT,
259 /**
260 * Representing a 15 Bit unsigned int value used as attribute type
261 * in an attribute transform
262 *
263 *
264 * When generating it must be changed from host to network order.
265 * The value is read from the associated data struct.
266 * The current write position is moved 15 bit forward afterwards.
267 *
268 * When parsing it must be changed from network to host order.
269 * The value is written to the associated data struct.
270 * The current read pointer is moved 15 bit forward afterwards.
271 */
272 ATTRIBUTE_TYPE,
273
274 /**
275 * Depending on the field of type ATTRIBUTE_FORMAT
276 * this field contains the length or the value of an transform attribute.
277 * Its stored in a 16 unsigned integer field
278 *
279 * When generating it must be changed from host to network order.
280 * The value is read from the associated data struct.
281 * The current write position is moved 16 bit forward afterwards.
282 *
283 * When parsing it must be changed from network to host order.
284 * The value is written to the associated data struct.
285 * The current read pointer is moved 16 bit forward afterwards.
286 */
287 ATTRIBUTE_LENGTH_OR_VALUE,
288
289 /**
290 * Depending on the field of type ATTRIBUTE_FORMAT
291 * this field is available or missing and so parsed/generated
292 * or not parsed/not generated
293 *
294 * When generating the content of the chunkt pointing to
295 * is written.
296 *
297 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
298 */
299 ATTRIBUTE_VALUE,
300
301 /**
302 * Representating a Nonce Data field
303 *
304 * When generating the content of the chunkt pointing to
305 * is written.
306 *
307 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
308 */
309 NONCE_DATA,
310
311 /**
312 * Representating an IKE_SPI field in an IKEv2 Header
313 *
314 * When generating the value of the u_int64_t pointing to
315 * is written (host and networ order is not changed).
316 *
317 * When parsing 8 bytes are read and written into the u_int64_t pointing to.
318 */
319 IKE_SPI,
320
321 ENCRYPTED_DATA,
322
323 };
324
325 /**
326 * mappings to map encoding_type_t's to strings
327 */
328 extern mapping_t encoding_type_m[];
329
330 /**
331 * An encoding rule is a mapping of a specific encoding type to
332 * a location in the data struct where the current field is stored to
333 * or read from.
334 *
335 * For examples see directory encodings/.
336 *
337 * This rules are used by parser and generator.
338 */
339 typedef struct encoding_rule_t encoding_rule_t;
340
341 struct encoding_rule_t {
342 /**
343 * Encoding type
344 */
345 encoding_type_t type;
346 /**
347 * Offset in the data struct
348 *
349 * When parsing, data are written to this offset of the
350 * data struct.
351 *
352 * When generating, data are read from this offset in the
353 * data struct.
354 */
355 u_int32_t offset;
356 };
357
358
359
360
361
362 #endif /*ENCODINGS_H_*/