4 * @brief Interface of 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
27 #include <utils/identification.h>
28 #include <utils/linked_list.h>
29 #include <utils/host.h>
30 #include <crypto/crypters/crypter.h>
31 #include <crypto/signers/signer.h>
32 #include <crypto/diffie_hellman.h>
33 #include <config/traffic_selector.h>
36 typedef enum protocol_id_t protocol_id_t
;
39 * Protocol ID of a proposal.
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 RFC 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 RFC 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 proposal_t proposal_t
;
123 * @brief Stores a set of algorithms used for an SA.
125 * A proposal stores algorithms for a specific
126 * protocol. It can store algorithms for more than
127 * one protocol (e.g. AH and ESP). Then the proposal
128 * means both protocols must be used.
129 * A proposal may contain more than one algorithm
130 * of the same kind. ONE of them can be selected.
132 * @warning This class is NOT thread-save!
135 * - proposal_create()
142 * @brief Add an algorithm to the proposal.
144 * The algorithms are stored by priority, first added
145 * is the most preferred.
146 * Key size is only needed for encryption algorithms
147 * with variable key size (such as AES). Must be set
148 * to zero if key size is not specified.
149 * The alg parameter accepts encryption_algorithm_t,
150 * integrity_algorithm_t, dh_group_number_t and
151 * extended_sequence_numbers_t.
153 * @warning Do not add while other threads are reading.
155 * @param this calling object
156 * @param proto desired protocol
157 * @param type kind of algorithm
158 * @param alg identifier for algorithm
159 * @param key_size key size to use
161 void (*add_algorithm
) (proposal_t
*this, protocol_id_t proto
, transform_type_t type
, u_int16_t alg
, size_t key_size
);
164 * @brief Get an iterator over algorithms for a specifc protocol/algo type.
166 * @param this calling object
167 * @param proto desired protocol
168 * @param type kind of algorithm
169 * @return iterator over algorithms
171 iterator_t
*(*create_algorithm_iterator
) (proposal_t
*this, protocol_id_t proto
, transform_type_t type
);
174 * @brief Get the algorithm for a type to use.
176 * If there are multiple algorithms, only the first is returned.
177 * Result is still owned by proposal, do not modify!
179 * @param this calling object
180 * @param proto desired protocol
181 * @param type kind of algorithm
182 * @param[out] algo pointer which receives algorithm and key size
183 * @return TRUE if algorithm of this kind available
185 bool (*get_algorithm
) (proposal_t
*this, protocol_id_t proto
, transform_type_t type
, algorithm_t
** algo
);
188 * @brief Compare two proposal, and select a matching subset.
190 * If the proposals are for the same protocols (AH/ESP), they are
191 * compared. If they have at least one algorithm of each type
192 * in common, a resulting proposal of this kind is created.
194 * @param this calling object
195 * @param other proposal to compair agains
197 * - selected proposal, if possible
198 * - NULL, if proposals don't match
200 proposal_t
*(*select
) (proposal_t
*this, proposal_t
*other
);
203 * @brief Get the number set on construction.
205 * @param this calling object
208 u_int8_t (*get_number
) (proposal_t
*this);
211 * @brief Get the protocol ids in the proposals.
213 * With AH and ESP, there could be two protocols in one
216 * @param this calling object
217 * @param ids array of protocol ids,
219 void (*get_protocols
) (proposal_t
*this, protocol_id_t ids
[2]);
222 * @brief Get the spi for a specific protocol.
224 * @param this calling object
225 * @param proto AH/ESP
226 * @return spi for proto
228 u_int64_t (*get_spi
) (proposal_t
*this, protocol_id_t proto
);
231 * @brief Set the spi for a specific protocol.
233 * @param this calling object
234 * @param proto AH/ESP
235 * @param spi spi to set for proto
237 void (*set_spi
) (proposal_t
*this, protocol_id_t proto
, u_int64_t spi
);
240 * @brief Clone a proposal.
242 * @param this proposal to clone
243 * @return clone of it
245 proposal_t
*(*clone
) (proposal_t
*this);
248 * @brief Destroys the proposal object.
250 * @param this calling object
252 void (*destroy
) (proposal_t
*this);
256 * @brief Create a child proposal for AH and/or ESP.
258 * Since the order of multiple proposals is important for
259 * key derivation, we must assign them numbers as they
260 * appear in the raw payload. Numbering starts at 1.
262 * @param number number of the proposal, as in the payload
263 * @return proposal_t object
267 proposal_t
*proposal_create(u_int8_t number
);
269 #endif /* PROPOSAL_H_ */