2 * @file child_proposal.h
4 * @brief Interface of child_proposal_t.
9 * Copyright (C) 2006 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 _CHILD_PROPOSAL_H_
24 #define _CHILD_PROPOSAL_H_
27 #include <utils/identification.h>
28 #include <utils/linked_list.h>
29 #include <network/host.h>
30 #include <transforms/crypters/crypter.h>
31 #include <transforms/signers/signer.h>
32 #include <transforms/diffie_hellman.h>
33 #include <config/traffic_selector.h>
36 typedef enum protocol_id_t protocol_id_t
;
39 * Protocol ID of a proposal.
44 UNDEFINED_PROTOCOL_ID
= 201,
51 * String mappings for protocol_id_t.
55 extern mapping_t protocol_id_m
[];
58 typedef enum transform_type_t transform_type_t
;
61 * Type of a transform, as in IKEv2 draft 3.3.2.
65 enum transform_type_t
{
66 UNDEFINED_TRANSFORM_TYPE
= 241,
67 ENCRYPTION_ALGORITHM
= 1,
68 PSEUDO_RANDOM_FUNCTION
= 2,
69 INTEGRITY_ALGORITHM
= 3,
70 DIFFIE_HELLMAN_GROUP
= 4,
71 EXTENDED_SEQUENCE_NUMBERS
= 5
75 * String mappings for transform_type_t.
79 extern mapping_t transform_type_m
[];
82 typedef enum extended_sequence_numbers_t extended_sequence_numbers_t
;
85 * Extended sequence numbers, as in IKEv2 draft 3.3.2.
89 enum extended_sequence_numbers_t
{
90 NO_EXT_SEQ_NUMBERS
= 0,
95 * String mappings for extended_sequence_numbers_t.
99 extern mapping_t extended_sequence_numbers_m
[];
102 typedef struct algorithm_t algorithm_t
;
105 * Struct used to store different kinds of algorithms. The internal
106 * lists of algorithms contain such structures.
110 * Value from an encryption_algorithm_t/integrity_algorithm_t/...
115 * the associated key size, or zero if not needed
120 typedef struct child_proposal_t child_proposal_t
;
123 * @brief Stores a proposal for a child SA.
125 * A child_proposal may contain more than one algorithm
126 * of the same kind. ONE of them can be selected.
128 * @warning This class is NOT thread-save!
131 * - child_proposal_create()
135 struct child_proposal_t
{
138 * @brief Add an algorithm to the proposal.
140 * The algorithms are stored by priority, first added
141 * is the most preferred.
142 * Key size is only needed for encryption algorithms
143 * with variable key size (such as AES), or integrity
145 * The alg parameter accepts encryption_algorithm_t,
146 * integrity_algorithm_t, dh_group_number_t and
147 * extended_sequence_numbers_t.
149 * @warning Do not add while other threads are reading.
151 * @param this calling object
152 * @param proto desired protocol
153 * @param type kind of algorithm
154 * @param alg identifier for algorithm
155 * @param key_size key size to use
157 void (*add_algorithm
) (child_proposal_t
*this, protocol_id_t proto
, transform_type_t type
, u_int16_t alg
, size_t key_size
);
160 * @brief Get an iterator over algorithms for a specifc protocol/algo type.
162 * @param this calling object
163 * @param proto desired protocol
164 * @param type kind of algorithm
165 * @return iterator over algorithms
167 iterator_t
*(*create_algorithm_iterator
) (child_proposal_t
*this, protocol_id_t proto
, transform_type_t type
);
170 * @brief Get the algorithm for a type to use.
172 * If there are multiple algorithms, only the first is returned.
173 * Result is still owned by child_proposal, do not modify!
175 * @param this calling object
176 * @param proto desired protocol
177 * @param type kind of algorithm
178 * @param[out] algo pointer which receives algorithm and key size
179 * @return TRUE if algorithm of this kind available
181 bool (*get_algorithm
) (child_proposal_t
*this, protocol_id_t proto
, transform_type_t type
, algorithm_t
** algo
);
184 * @brief Compare two proposal, and select a matching subset.
186 * If the proposals are for the same protocols (AH/ESP), they are
187 * compared. If they have at least one algorithm of each type
188 * in common, a resulting proposal of this kind is created.
190 * @param this calling object
191 * @param other proposal to compair agains
193 * - selected proposal, if possible
194 * - NULL, if proposals don't match
196 child_proposal_t
*(*select
) (child_proposal_t
*this, child_proposal_t
*other
);
199 * @brief Get the number set on construction.
201 * @param this calling object
204 u_int8_t (*get_number
) (child_proposal_t
*this);
207 * @brief Get the protocol ids in the proposals.
209 * With AH and ESP, there could be two protocols in one
212 * @param this calling object
213 * @param ids array of protocol ids,
215 void (*get_protocols
) (child_proposal_t
*this, protocol_id_t ids
[2]);
218 * @brief Get the spi for a specific protocol.
220 * @param this calling object
221 * @param proto AH/ESP
222 * @return spi for proto
224 u_int64_t (*get_spi
) (child_proposal_t
*this, protocol_id_t proto
);
227 * @brief Set the spi for a specific protocol.
229 * @param this calling object
230 * @param proto AH/ESP
231 * @param spi spi to set for proto
233 void (*set_spi
) (child_proposal_t
*this, protocol_id_t proto
, u_int64_t spi
);
236 * @brief Destroys the proposal object.
238 * @param this calling object
240 void (*destroy
) (child_proposal_t
*this);
244 * @brief Create a child proposal for AH and/or ESP.
246 * @param number number of the proposal, as in the payload
247 * @return child_proposal_t object
251 child_proposal_t
*child_proposal_create(u_int8_t number
);
253 #endif //_CHILD_PROPOSAL_H_