0194b9904017e452ff63c9966723ccff6c81d8a8
[strongswan.git] / src / charon / 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 * $Id$
17 */
18
19 /**
20 * @defgroup transform_substructure transform_substructure
21 * @{ @ingroup payloads
22 */
23
24 #ifndef TRANSFORM_SUBSTRUCTURE_H_
25 #define TRANSFORM_SUBSTRUCTURE_H_
26
27 typedef struct transform_substructure_t transform_substructure_t;
28
29 #include <library.h>
30 #include <encoding/payloads/payload.h>
31 #include <encoding/payloads/transform_attribute.h>
32 #include <utils/linked_list.h>
33 #include <crypto/diffie_hellman.h>
34 #include <crypto/signers/signer.h>
35 #include <crypto/prfs/prf.h>
36 #include <crypto/crypters/crypter.h>
37 #include <config/proposal.h>
38
39
40 /**
41 * IKEv1 Value for a transform payload.
42 */
43 #define TRANSFORM_TYPE_VALUE 3
44
45 /**
46 * Length of the transform substructure header in bytes.
47 */
48 #define TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH 8
49
50
51 /**
52 * Class representing an IKEv2- TRANSFORM SUBSTRUCTURE.
53 *
54 * The TRANSFORM SUBSTRUCTURE format is described in RFC section 3.3.2.
55 */
56 struct transform_substructure_t {
57 /**
58 * The payload_t interface.
59 */
60 payload_t payload_interface;
61
62 /**
63 * Creates an iterator of stored transform_attribute_t objects.
64 *
65 * When deleting an transform attribute using this iterator,
66 * the length of this transform substructure has to be refreshed
67 * by calling get_length().
68 *
69 * @param forward iterator direction (TRUE: front to end)
70 * @return created iterator_t object.
71 */
72 iterator_t * (*create_transform_attribute_iterator) (
73 transform_substructure_t *this, bool forward);
74
75 /**
76 * Adds a transform_attribute_t object to this object.
77 *
78 * @param proposal transform_attribute_t object to add
79 */
80 void (*add_transform_attribute) (transform_substructure_t *this,
81 transform_attribute_t *attribute);
82
83 /**
84 * Sets the next_payload field of this substructure
85 *
86 * If this is the last transform, next payload field is set to 0,
87 * otherwise to 3
88 *
89 * @param is_last When TRUE, next payload field is set to 0, otherwise to 3
90 */
91 void (*set_is_last_transform) (transform_substructure_t *this, bool is_last);
92
93 /**
94 * Checks if this is the last transform.
95 *
96 * @return TRUE if this is the last Transform, FALSE otherwise
97 */
98 bool (*get_is_last_transform) (transform_substructure_t *this);
99
100 /**
101 * Sets transform type of the current transform substructure.
102 *
103 * @param type type value to set
104 */
105 void (*set_transform_type) (transform_substructure_t *this, u_int8_t type);
106
107 /**
108 * get transform type of the current transform.
109 *
110 * @return Transform type of current transform substructure.
111 */
112 u_int8_t (*get_transform_type) (transform_substructure_t *this);
113
114 /**
115 * Sets transform id of the current transform substructure.
116 *
117 * @param id transform id to set
118 */
119 void (*set_transform_id) (transform_substructure_t *this, u_int16_t id);
120
121 /**
122 * get transform id of the current transform.
123 *
124 * @return Transform id of current transform substructure.
125 */
126 u_int16_t (*get_transform_id) (transform_substructure_t *this);
127
128 /**
129 * get transform id of the current transform.
130 *
131 * @param key_length The key length is written to this location
132 * @return
133 * - SUCCESS if a key length attribute is contained
134 * - FAILED if no key length attribute is part of this
135 * transform or key length uses more then 16 bit!
136 */
137 status_t (*get_key_length) (transform_substructure_t *this,
138 u_int16_t *key_length);
139
140 /**
141 * Clones an transform_substructure_t object.
142 *
143 * @return cloned transform_substructure_t object
144 */
145 transform_substructure_t* (*clone) (transform_substructure_t *this);
146
147 /**
148 * Destroys an transform_substructure_t object.
149 */
150 void (*destroy) (transform_substructure_t *this);
151 };
152
153 /**
154 * Creates an empty transform_substructure_t object.
155 *
156 * @return created transform_substructure_t object
157 */
158 transform_substructure_t *transform_substructure_create(void);
159
160 /**
161 * Creates an empty transform_substructure_t object.
162 *
163 * The key length is used for the transport types ENCRYPTION_ALGORITHM,
164 * PSEUDO_RANDOM_FUNCTION, INTEGRITY_ALGORITHM. For all
165 * other transport types the key_length parameter is not used
166 *
167 * @param transform_type type of transform to create
168 * @param transform_id transform id specifying the specific algorithm of a transform type
169 * @param key_length Key length for key lenght attribute
170 * @return transform_substructure_t object
171 */
172 transform_substructure_t *transform_substructure_create_type(
173 transform_type_t transform_type, u_int16_t transform_id,
174 u_int16_t key_length);
175
176 #endif /*TRANSFORM_SUBSTRUCTURE_H_ @} */