- tested code-example
[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 /**
65 * @addtogroup transforms
66 *
67 * Transform algorithms of different kind.
68 */
69
70 /**
71 * @addtogroup prfs
72 *
73 * Pseudo random functions, generate a lot of pseudo
74 * randomness using random numbers.
75 *
76 * @ingroup transforms
77 */
78
79 /**
80 * @addtogroup signers
81 *
82 * Symmetric signing algorithms, used to ensure
83 * message integrity.
84 *
85 * @ingroup transforms
86 */
87
88 /**
89 * @addtogroup crypters
90 *
91 * Symmetric encryption algorithms, used to en-
92 * and decrypt.
93 *
94 * @ingroup transforms
95 */
96
97 /**
98 * @addtogroup hashers
99 *
100 * Hashing algorithms.
101 *
102 * Example for using hasher_t:
103 * @code
104 * chunk_t data;
105 * chunk_t md5_hash;
106 * u_int8_t sha1_hash[20];
107 *
108 * hasher_t *hasher;
109 *
110 * data.ptr = "string to hash";
111 * data.len = strlen(data.ptr);
112 *
113 * // use MD5, allocate hash
114 * hasher = hasher_create(HASH_MD5);
115 * hasher->allocate_hash(hasher, data, &hash);
116 * hasher->destroy(hasher);
117 *
118 * // use SHA1, hash in buffer
119 * hasher = hasher_create(HASH_SHA1);
120 * hasher->get_hash(hasher, data, &sha1_hash);
121 * hasher->destroy(hasher);
122 * @endcode
123 *
124 *
125 *
126 * @ingroup transforms
127 */
128
129 /**
130 * @addtogroup utils
131 *
132 * Generic helper classes.
133 */
134
135 /**
136 * @addtogroup threads
137 *
138 * Threaded classes, which will do their
139 * job alone.
140 */
141
142
143
144 /**
145 * macro gives back larger of two values
146 */
147 #define max(x,y) (x > y ? x : y)
148
149
150 /**
151 * macro gives back smaller of two values
152 */
153 #define min(x,y) (x < y ? x : y)
154
155
156 /**
157 * mapping entry which defines the end of a mapping_t array
158 */
159 #define MAPPING_END (-1)
160
161 typedef struct mapping_t mapping_t;
162
163 /**
164 * @brief mapping entry, where enum-to-string mappings are stored.
165 */
166 struct mapping_t
167 {
168 /**
169 * enumeration value
170 */
171 int value;
172 /**
173 * mapped string
174 */
175 char *string;
176 };
177
178
179 /**
180 * @brief find a mapping_string in the mapping[]
181 *
182 * @param mappings mappings array
183 * @param value enum-value to get the string from
184 *
185 */
186 char *mapping_find(mapping_t *mappings, int value);
187
188
189 /**
190 * Default random device used when no device is given.
191 */
192 #define DEFAULT_RANDOM_DEVICE "/dev/random"
193
194 /**
195 * Pseudo random device used when no device is given.
196 */
197 #define DEFAULT_PSEUDO_RANDOM_DEVICE "/dev/urandom"
198
199
200 #endif /*DEFINITIONS_H_*/