5d31f8c0a07c311122a3fb3499f5a58fd606ea85
[strongswan.git] / src / libcharon / encoding / payloads / transform_substructure.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup transform_substructure transform_substructure
19 * @{ @ingroup payloads
20 */
21
22 #ifndef TRANSFORM_SUBSTRUCTURE_H_
23 #define TRANSFORM_SUBSTRUCTURE_H_
24
25 typedef struct transform_substructure_t transform_substructure_t;
26
27 #include <library.h>
28 #include <encoding/payloads/payload.h>
29 #include <encoding/payloads/transform_attribute.h>
30 #include <utils/linked_list.h>
31 #include <crypto/diffie_hellman.h>
32 #include <crypto/signers/signer.h>
33 #include <crypto/prfs/prf.h>
34 #include <crypto/crypters/crypter.h>
35 #include <config/proposal.h>
36
37
38 /**
39 * IKEv1 Value for a transform payload.
40 */
41 #define TRANSFORM_TYPE_VALUE 3
42
43 /**
44 * Length of the transform substructure header in bytes.
45 */
46 #define TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH 8
47
48
49 /**
50 * Class representing an IKEv2- TRANSFORM SUBSTRUCTURE.
51 *
52 * The TRANSFORM SUBSTRUCTURE format is described in RFC section 3.3.2.
53 */
54 struct transform_substructure_t {
55 /**
56 * The payload_t interface.
57 */
58 payload_t payload_interface;
59
60 /**
61 * Creates an iterator of stored transform_attribute_t objects.
62 *
63 * When deleting an transform attribute using this iterator,
64 * the length of this transform substructure has to be refreshed
65 * by calling get_length().
66 *
67 * @param forward iterator direction (TRUE: front to end)
68 * @return created iterator_t object.
69 */
70 iterator_t * (*create_transform_attribute_iterator) (
71 transform_substructure_t *this, bool forward);
72
73 /**
74 * Adds a transform_attribute_t object to this object.
75 *
76 * @param proposal transform_attribute_t object to add
77 */
78 void (*add_transform_attribute) (transform_substructure_t *this,
79 transform_attribute_t *attribute);
80
81 /**
82 * Sets the next_payload field of this substructure
83 *
84 * If this is the last transform, next payload field is set to 0,
85 * otherwise to 3
86 *
87 * @param is_last When TRUE, next payload field is set to 0, otherwise to 3
88 */
89 void (*set_is_last_transform) (transform_substructure_t *this, bool is_last);
90
91 /**
92 * Checks if this is the last transform.
93 *
94 * @return TRUE if this is the last Transform, FALSE otherwise
95 */
96 bool (*get_is_last_transform) (transform_substructure_t *this);
97
98 /**
99 * Sets transform type of the current transform substructure.
100 *
101 * @param type type value to set
102 */
103 void (*set_transform_type) (transform_substructure_t *this, u_int8_t type);
104
105 /**
106 * get transform type of the current transform.
107 *
108 * @return Transform type of current transform substructure.
109 */
110 u_int8_t (*get_transform_type) (transform_substructure_t *this);
111
112 /**
113 * Sets transform id of the current transform substructure.
114 *
115 * @param id transform id to set
116 */
117 void (*set_transform_id) (transform_substructure_t *this, u_int16_t id);
118
119 /**
120 * get transform id of the current transform.
121 *
122 * @return Transform id of current transform substructure.
123 */
124 u_int16_t (*get_transform_id) (transform_substructure_t *this);
125
126 /**
127 * get transform id of the current transform.
128 *
129 * @param key_length The key length is written to this location
130 * @return
131 * - SUCCESS if a key length attribute is contained
132 * - FAILED if no key length attribute is part of this
133 * transform or key length uses more then 16 bit!
134 */
135 status_t (*get_key_length) (transform_substructure_t *this,
136 u_int16_t *key_length);
137
138 /**
139 * Clones an transform_substructure_t object.
140 *
141 * @return cloned transform_substructure_t object
142 */
143 transform_substructure_t* (*clone) (transform_substructure_t *this);
144
145 /**
146 * Destroys an transform_substructure_t object.
147 */
148 void (*destroy) (transform_substructure_t *this);
149 };
150
151 /**
152 * Creates an empty transform_substructure_t object.
153 *
154 * @return created transform_substructure_t object
155 */
156 transform_substructure_t *transform_substructure_create(void);
157
158 /**
159 * Creates an empty transform_substructure_t object.
160 *
161 * The key length is used for the transport types ENCRYPTION_ALGORITHM,
162 * PSEUDO_RANDOM_FUNCTION, INTEGRITY_ALGORITHM. For all
163 * other transport types the key_length parameter is not used
164 *
165 * @param transform_type type of transform to create
166 * @param transform_id transform id specifying the specific algorithm of a transform type
167 * @param key_length Key length for key lenght attribute
168 * @return transform_substructure_t object
169 */
170 transform_substructure_t *transform_substructure_create_type(
171 transform_type_t transform_type, u_int16_t transform_id,
172 u_int16_t key_length);
173
174 #endif /** TRANSFORM_SUBSTRUCTURE_H_ @}*/