e3bb85fdadb00bac559a59885e9de2fd96156a0e
[strongswan.git] / Source / charon / definitions.h
1 /**
2 * @file definitions.h
3 *
4 * @brief general purpose definitions and macros
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 * Copyright (C) 1998, 1999 D. Hugh Redelmeier. (Endian stuff)
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef DEFINITIONS_H_
25 #define DEFINITIONS_H_
26
27
28
29 /* stolen from strongswan */
30 #if linux
31 # if defined(i386) && !defined(__i386__)
32 # define __i386__ 1
33 # define MYHACKFORTHIS 1
34 # endif
35 # include <endian.h>
36 # ifdef MYHACKFORTHIS
37 # undef __i386__
38 # undef MYHACKFORTHIS
39 # endif
40 #elif !(defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) && defined(BYTE_ORDER))
41 /* we don't know how to do this, so we require the macros to be defined
42 * with compiler flags:
43 * -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=BIG_ENDIAN
44 * or -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=LITTLE_ENDIAN
45 * Thse match the GNU definitions
46 */
47 # include <sys/endian.h>
48 #endif
49
50 #ifndef BIG_ENDIAN
51 #error "BIG_ENDIAN must be defined"
52 #endif
53
54 #ifndef LITTLE_ENDIAN
55 #error "LITTLE_ENDIAN must be defined"
56 #endif
57
58 #ifndef BYTE_ORDER
59 #error "BYTE_ORDER must be defined"
60 #endif
61
62
63 /**
64 * @defgroup config
65 *
66 * Classes which implement configuration related things.
67 */
68
69 /**
70 * @defgroup encoding
71 *
72 * Classes used to encode and decode IKEv2 Messages.
73 */
74
75 /**
76 * @defgroup network
77 *
78 * Classes for network relevant stuff.
79 */
80
81 /**
82 * @defgroup payloads
83 *
84 * Classes representing a specific IKEv2 Payload.
85 *
86 * @ingroup encoding
87 */
88
89 /**
90 * @defgroup sa
91 *
92 * Security association with all helber classes.
93 */
94
95
96 /**
97 * @defgroup states
98 *
99 * Varius states in which an IKE SA can be.
100 *
101 * @ingroup sa
102 */
103
104 /**
105 * @defgroup queues
106 *
107 * Different kind of queues.
108 */
109
110 /**
111 * @defgroup jobs
112 *
113 * Jobs used in job queue and event queue.
114 *
115 * @ingroup queues
116 */
117
118 /**
119 * @defgroup testcases
120 *
121 * Testcases used to test the different classes in seperate module tests.
122 */
123
124 /**
125 * @defgroup transforms
126 *
127 * Transform algorithms of different kind.
128 */
129
130 /**
131 * @defgroup rsa
132 *
133 * RSA public key algorithm
134 *
135 * @ingroup transforms
136 */
137
138 /**
139 * @defgroup prfs
140 *
141 * Pseudo random functions, generate a lot of pseudo
142 * randomness using random numbers.
143 *
144 * @ingroup transforms
145 */
146
147 /**
148 * @defgroup signers
149 *
150 * Symmetric signing algorithms, used to ensure
151 * message integrity.
152 *
153 * @ingroup transforms
154 */
155
156 /**
157 * @defgroup crypters
158 *
159 * Symmetric encryption algorithms, used to en-
160 * and decrypt.
161 *
162 * @ingroup transforms
163 */
164
165 /**
166 * @defgroup hashers
167 *
168 * Hashing algorithms.
169 *
170 * Example for using hasher_t:
171 * @code
172 * chunk_t data;
173 * chunk_t md5_hash;
174 * u_int8_t sha1_hash[20];
175 *
176 * hasher_t *hasher;
177 *
178 * data.ptr = "string to hash";
179 * data.len = strlen(data.ptr);
180 *
181 * // use MD5, allocate hash
182 * hasher = hasher_create(HASH_MD5);
183 * hasher->allocate_hash(hasher, data, &hash);
184 * hasher->destroy(hasher);
185 *
186 * // use SHA1, hash in buffer
187 * hasher = hasher_create(HASH_SHA1);
188 * hasher->get_hash(hasher, data, &sha1_hash);
189 * hasher->destroy(hasher);
190 * @endcode
191 *
192 *
193 *
194 * @ingroup transforms
195 */
196
197 /**
198 * @defgroup utils
199 *
200 * Generic helper classes.
201 */
202
203 /**
204 * @defgroup threads
205 *
206 * Threaded classes, which will do their
207 * job alone.
208 */
209
210
211
212 /**
213 * macro gives back larger of two values
214 */
215 #define max(x,y) (x > y ? x : y)
216
217
218 /**
219 * macro gives back smaller of two values
220 */
221 #define min(x,y) (x < y ? x : y)
222
223
224 /**
225 * mapping entry which defines the end of a mapping_t array
226 */
227 #define MAPPING_END (-1)
228
229 typedef struct mapping_t mapping_t;
230
231 /**
232 * @brief mapping entry, where enum-to-string mappings are stored.
233 */
234 struct mapping_t
235 {
236 /**
237 * enumeration value
238 */
239 int value;
240 /**
241 * mapped string
242 */
243 char *string;
244 };
245
246
247 /**
248 * @brief find a mapping_string in the mapping[]
249 *
250 * @param mappings mappings array
251 * @param value enum-value to get the string from
252 *
253 */
254 char *mapping_find(mapping_t *mappings, int value);
255
256
257 /**
258 * Default random device used when no device is given.
259 */
260 #define DEFAULT_RANDOM_DEVICE "/dev/random"
261
262 /**
263 * Pseudo random device used when no device is given.
264 */
265 #define DEFAULT_PSEUDO_RANDOM_DEVICE "/dev/urandom"
266
267
268 #endif /*DEFINITIONS_H_*/