7c7f087f076d30e29cd525bb83a437c30e971a62
4 * @brief Helper functions and definitions.
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 * @defgroup libstrongswan libstrongswan
29 * libstrongswan: library with various crypto related things.
35 * ASN1 definitions, parser and generator functions.
37 * @ingroup libstrongswan
41 * @defgroup crypto crypto
43 * Crypto algorithms of different kind.
45 * @ingroup libstrongswan
49 * @defgroup crypters crypters
51 * Symmetric encryption algorithms, used for
52 * encryption and decryption.
58 * @defgroup hashers hashers
60 * Hashing algorithms, such as MD5 or SHA1
68 * Pseudo random functions, used to generate
69 * pseude random byte sequences.
77 * RSA private/public key algorithm.
83 * @defgroup signers signers
85 * Symmetric signing algorithms,
86 * used to ensure message integrity.
92 * @defgroup utils utils
94 * Generic helper classes.
96 * @ingroup libstrongswan
100 #include <sys/types.h>
108 * Number of bits in a byte
110 #define BITS_PER_BYTE 8
113 * Default length for various auxiliary text buffers
118 * Macro compares two strings for equality
120 #define streq(x,y) (strcmp(x, y) == 0)
123 * Macro compares two binary blobs for equality
125 #define memeq(x,y,len) (memcmp(x, y, len) == 0)
128 * Macro gives back larger of two values.
130 #define max(x,y) ((x) > (y) ? (x):(y))
133 * Macro gives back smaller of two values.
135 #define min(x,y) ((x) < (y) ? (x):(y))
138 * Call destructor of a object if object != NULL
140 #define DESTROY_IF(obj) if (obj) obj->destroy(obj)
143 * Debug macro to follow control flow
145 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
148 * Macro to allocate a sized type.
150 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
153 * Assign a function as a class method
155 #define ASSIGN(method, function) (method = (typeof(method))function)
160 #define UNDEFINED_TIME 0
163 * General purpose boolean type.
169 typedef enum status_t status_t
;
172 * Return values of function calls.
191 * The suggested operation is already done
201 * One of the arguments is invalid.
206 * Something could not be found.
211 * Error while parsing.
216 * Error while verifying.
221 * Object in invalid state.
226 * Destroy object which called method belongs to.
231 * Another call to the method is required.
237 * enum_names for type status_t.
239 extern enum_name_t
*status_names
;
242 * deprecated pluto style return value:
243 * error message, NULL for success
245 typedef const char *err_t
;
248 * Handle struct timeval like an own type.
250 typedef struct timeval timeval_t
;
253 * Handle struct timespec like an own type.
255 typedef struct timespec timespec_t
;
258 * Handle struct chunk_t like an own type.
260 typedef struct sockaddr sockaddr_t
;
263 * Clone a data to a newly allocated buffer
265 void *clalloc(void *pointer
, size_t size
);
268 * Same as memcpy, but XORs src into dst instead of copy
270 void memxor(u_int8_t dest
[], u_int8_t src
[], size_t n
);
273 * Special type to count references
275 typedef volatile u_int refcount_t
;
278 * @brief Get a new reference.
280 * Increments the reference counter atomic.
282 * @param ref pointer to ref counter
284 void ref_get(refcount_t
*ref
);
287 * @brief Put back a unused reference.
289 * Decrements the reference counter atomic and
290 * says if more references available.
292 * @param ref pointer to ref counter
293 * @return TRUE if no more references counted
295 bool ref_put(refcount_t
*ref
);
299 #include <printf_hook.h>
301 #endif /* LIBRARY_H_ */