replaced get_rsa_private_key() by rsa_signature() in order restrict the distribution...
[strongswan.git] / src / libstrongswan / library.h
1 /**
2 * @file library.h
3 *
4 * @brief Helper functions and definitions.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23 #ifndef LIBRARY_H_
24 #define LIBRARY_H_
25
26 /**
27 * @defgroup libstrongswan libstrongswan
28 *
29 * libstrongswan: library with various cryptographic, X.509 trust chain and
30 * identity management functions.
31 */
32
33 /**
34 * @defgroup asn1 asn1
35 *
36 * ASN.1 definitions, parser and generator functions.
37 *
38 * @ingroup libstrongswan
39 */
40
41 /**
42 * @defgroup crypto crypto
43 *
44 * Various cryptographic algorithms.
45 *
46 * @ingroup libstrongswan
47 */
48
49 /**
50 * @defgroup crypters crypters
51 *
52 * Symmetric encryption algorithms, used for
53 * encryption and decryption.
54 *
55 * @ingroup crypto
56 */
57
58 /**
59 * @defgroup hashers hashers
60 *
61 * Hashing algorithms, such as MD5 or SHA1
62 *
63 * @ingroup crypto
64 */
65
66 /**
67 * @defgroup prfs prfs
68 *
69 * Pseudo random functions, used to generate
70 * pseude random byte sequences.
71 *
72 * @ingroup crypto
73 */
74
75 /**
76 * @defgroup rsa rsa
77 *
78 * RSA private/public key algorithm.
79 *
80 * @ingroup crypto
81 */
82
83 /**
84 * @defgroup signers signers
85 *
86 * Symmetric signing algorithms,
87 * used to ensure message integrity.
88 *
89 * @ingroup crypto
90 */
91
92 /**
93 * @defgroup fips fips
94 *
95 * Code integrity check of libstrongswan
96 *
97 * @ingroup libstrongswan
98 */
99
100 /**
101 * @defgroup utils utils
102 *
103 * Generic helper classes.
104 *
105 * @ingroup libstrongswan
106 */
107
108 #include <gmp.h>
109 #include <sys/types.h>
110 #include <stdlib.h>
111 #include <stddef.h>
112 #include <printf.h>
113
114 #include <enum.h>
115
116 /**
117 * Number of bits in a byte
118 */
119 #define BITS_PER_BYTE 8
120
121 /**
122 * Default length for various auxiliary text buffers
123 */
124 #define BUF_LEN 512
125
126 /**
127 * Macro compares two strings for equality
128 */
129 #define streq(x,y) (strcmp(x, y) == 0)
130
131 /**
132 * Macro compares two binary blobs for equality
133 */
134 #define memeq(x,y,len) (memcmp(x, y, len) == 0)
135
136 /**
137 * Macro gives back larger of two values.
138 */
139 #define max(x,y) ((x) > (y) ? (x):(y))
140
141 /**
142 * Macro gives back smaller of two values.
143 */
144 #define min(x,y) ((x) < (y) ? (x):(y))
145
146 /**
147 * Call destructor of a object if object != NULL
148 */
149 #define DESTROY_IF(obj) if (obj) obj->destroy(obj)
150
151 /**
152 * Debug macro to follow control flow
153 */
154 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
155
156 /**
157 * Macro to allocate a sized type.
158 */
159 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
160
161 /**
162 * Assign a function as a class method
163 */
164 #define ASSIGN(method, function) (method = (typeof(method))function)
165
166 /**
167 * time_t not defined
168 */
169 #define UNDEFINED_TIME 0
170
171 /**
172 * General purpose boolean type.
173 */
174 typedef int bool;
175 #define FALSE 0
176 #define TRUE 1
177
178 typedef enum status_t status_t;
179
180 /**
181 * Return values of function calls.
182 */
183 enum status_t {
184 /**
185 * Call succeeded.
186 */
187 SUCCESS,
188
189 /**
190 * Call failed.
191 */
192 FAILED,
193
194 /**
195 * Out of resources.
196 */
197 OUT_OF_RES,
198
199 /**
200 * The suggested operation is already done
201 */
202 ALREADY_DONE,
203
204 /**
205 * Not supported.
206 */
207 NOT_SUPPORTED,
208
209 /**
210 * One of the arguments is invalid.
211 */
212 INVALID_ARG,
213
214 /**
215 * Something could not be found.
216 */
217 NOT_FOUND,
218
219 /**
220 * Error while parsing.
221 */
222 PARSE_ERROR,
223
224 /**
225 * Error while verifying.
226 */
227 VERIFY_ERROR,
228
229 /**
230 * Object in invalid state.
231 */
232 INVALID_STATE,
233
234 /**
235 * Destroy object which called method belongs to.
236 */
237 DESTROY_ME,
238
239 /**
240 * Another call to the method is required.
241 */
242 NEED_MORE,
243 };
244
245 /**
246 * used by strict_crl_policy
247 */
248 typedef enum {
249 STRICT_NO,
250 STRICT_YES,
251 STRICT_IFURI
252 } strict_t;
253
254 /**
255 * enum_names for type status_t.
256 */
257 extern enum_name_t *status_names;
258
259 /**
260 * deprecated pluto style return value:
261 * error message, NULL for success
262 */
263 typedef const char *err_t;
264
265 /**
266 * Handle struct timeval like an own type.
267 */
268 typedef struct timeval timeval_t;
269
270 /**
271 * Handle struct timespec like an own type.
272 */
273 typedef struct timespec timespec_t;
274
275 /**
276 * Handle struct chunk_t like an own type.
277 */
278 typedef struct sockaddr sockaddr_t;
279
280 /**
281 * Clone a data to a newly allocated buffer
282 */
283 void *clalloc(void *pointer, size_t size);
284
285 /**
286 * Same as memcpy, but XORs src into dst instead of copy
287 */
288 void memxor(u_int8_t dest[], u_int8_t src[], size_t n);
289
290 /**
291 * Special type to count references
292 */
293 typedef volatile u_int refcount_t;
294
295 /**
296 * @brief Get a new reference.
297 *
298 * Increments the reference counter atomic.
299 *
300 * @param ref pointer to ref counter
301 */
302 void ref_get(refcount_t *ref);
303
304 /**
305 * @brief Put back a unused reference.
306 *
307 * Decrements the reference counter atomic and
308 * says if more references available.
309 *
310 * @param ref pointer to ref counter
311 * @return TRUE if no more references counted
312 */
313 bool ref_put(refcount_t *ref);
314
315
316 #include <chunk.h>
317 #include <printf_hook.h>
318
319 #endif /* LIBRARY_H_ */