2 * @file transform_substructure.h
4 * @brief Interface of transform_substructure_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
23 #ifndef TRANSFORM_SUBSTRUCTURE_H_
24 #define TRANSFORM_SUBSTRUCTURE_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>
38 * IKEv1 Value for a transform payload.
42 #define TRANSFORM_TYPE_VALUE 3
45 * Length of the transform substructure header in bytes.
49 #define TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH 8
52 typedef enum transform_type_t transform_type_t
;
55 * Type of a transform, as in IKEv2 draft 3.3.2.
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_NUMBERS
= 5
69 * String mappings for transform_type_t.
73 extern mapping_t transform_type_m
[];
76 typedef enum extended_sequence_numbers_t extended_sequence_numbers_t
;
79 * Extended sequence numbers, as in IKEv2 draft 3.3.2.
83 enum extended_sequence_numbers_t
{
84 NO_EXT_SEQ_NUMBERS
= 0,
89 * String mappings for extended_sequence_numbers_t.
93 extern mapping_t extended_sequence_numbers_m
[];
95 typedef struct transform_substructure_t transform_substructure_t
;
98 * Object representing an IKEv2- TRANSFORM SUBSTRUCTURE.
100 * The TRANSFORM SUBSTRUCTURE format is described in RFC section 3.3.2.
104 struct transform_substructure_t
{
106 * The payload_t interface.
108 payload_t payload_interface
;
111 * @brief Creates an iterator of stored transform_attribute_t objects.
113 * @warning The created iterator has to get destroyed by the caller!
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()!
119 * @param this calling transform_substructure_t object
120 * @param[in] forward iterator direction (TRUE: front to end)
121 * @return created iterator_t object.
123 iterator_t
* (*create_transform_attribute_iterator
) (transform_substructure_t
*this, bool forward
);
126 * @brief Adds a transform_attribute_t object to this object.
128 * @warning The added proposal_substructure_t object is
129 * getting destroyed in destroy function of transform_substructure_t.
131 * @param this calling transform_substructure_t object
132 * @param proposal transform_attribute_t object to add
134 void (*add_transform_attribute
) (transform_substructure_t
*this,transform_attribute_t
*attribute
);
137 * @brief Sets the next_payload field of this substructure
139 * If this is the last transform, next payload field is set to 0,
142 * @param this calling transform_substructure_t object
143 * @param is_last When TRUE, next payload field is set to 0, otherwise to 3
145 void (*set_is_last_transform
) (transform_substructure_t
*this, bool is_last
);
148 * @brief Checks if this is the last transform.
150 * @param this calling transform_substructure_t object
151 * @return TRUE if this is the last Transform, FALSE otherwise
153 bool (*get_is_last_transform
) (transform_substructure_t
*this);
156 * @brief Sets transform type of the current transform substructure.
158 * @param this calling transform_substructure_t object
159 * @param type type value to set
161 void (*set_transform_type
) (transform_substructure_t
*this,u_int8_t type
);
164 * @brief get transform type of the current transform.
166 * @param this calling transform_substructure_t object
167 * @return Transform type of current transform substructure.
169 u_int8_t (*get_transform_type
) (transform_substructure_t
*this);
172 * @brief Sets transform id of the current transform substructure.
174 * @param this calling transform_substructure_t object
175 * @param id transform id to set
177 void (*set_transform_id
) (transform_substructure_t
*this,u_int16_t id
);
180 * @brief get transform id of the current transform.
182 * @param this calling transform_substructure_t object
183 * @return Transform id of current transform substructure.
185 u_int16_t (*get_transform_id
) (transform_substructure_t
*this);
188 * @brief get transform id of the current transform.
190 * @param this calling transform_substructure_t object
191 * @param key_length The key length is written to this location
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!
197 status_t (*get_key_length
) (transform_substructure_t
*this,u_int16_t
*key_length
);
200 * @brief Clones an transform_substructure_t object.
202 * @param this transform_substructure_t object to clone
203 * @return cloned transform_substructure_t object
205 transform_substructure_t
* (*clone
) (transform_substructure_t
*this);
208 * @brief Destroys an transform_substructure_t object.
210 * @param this transform_substructure_t object to destroy
212 void (*destroy
) (transform_substructure_t
*this);
216 * @brief Creates an empty transform_substructure_t object.
218 * @return created transform_substructure_t object
222 transform_substructure_t
*transform_substructure_create();
225 * @brief Creates an empty transform_substructure_t object.
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
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
238 transform_substructure_t
*transform_substructure_create_type(transform_type_t transform_type
, u_int16_t transform_id
, u_int16_t key_length
);
240 #endif /*TRANSFORM_SUBSTRUCTURE_H_*/