1439ab8504b656aec1c7556650505d2c021a4b26
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 cryptographic, X.509 trust chain and
30 * identity management functions.
36 * ASN.1 definitions, parser and generator functions.
38 * @ingroup libstrongswan
42 * @defgroup crypto crypto
44 * Various cryptographic algorithms.
46 * @ingroup libstrongswan
50 * @defgroup crypters crypters
52 * Symmetric encryption algorithms, used for
53 * encryption and decryption.
59 * @defgroup hashers hashers
61 * Hashing algorithms, such as MD5 or SHA1
69 * Pseudo random functions, used to generate
70 * pseude random byte sequences.
78 * RSA private/public key algorithm.
84 * @defgroup signers signers
86 * Symmetric signing algorithms,
87 * used to ensure message integrity.
93 * @defgroup utils utils
95 * Generic helper classes.
97 * @ingroup libstrongswan
101 #include <sys/types.h>
109 * Number of bits in a byte
111 #define BITS_PER_BYTE 8
114 * Default length for various auxiliary text buffers
119 * Macro compares two strings for equality
121 #define streq(x,y) (strcmp(x, y) == 0)
124 * Macro compares two binary blobs for equality
126 #define memeq(x,y,len) (memcmp(x, y, len) == 0)
129 * Macro gives back larger of two values.
131 #define max(x,y) ((x) > (y) ? (x):(y))
134 * Macro gives back smaller of two values.
136 #define min(x,y) ((x) < (y) ? (x):(y))
139 * Call destructor of a object if object != NULL
141 #define DESTROY_IF(obj) if (obj) obj->destroy(obj)
144 * Debug macro to follow control flow
146 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
149 * Macro to allocate a sized type.
151 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
154 * Assign a function as a class method
156 #define ASSIGN(method, function) (method = (typeof(method))function)
161 #define UNDEFINED_TIME 0
164 * General purpose boolean type.
170 typedef enum status_t status_t
;
173 * Return values of function calls.
192 * The suggested operation is already done
202 * One of the arguments is invalid.
207 * Something could not be found.
212 * Error while parsing.
217 * Error while verifying.
222 * Object in invalid state.
227 * Destroy object which called method belongs to.
232 * Another call to the method is required.
238 * used by strict_crl_policy
247 * enum_names for type status_t.
249 extern enum_name_t
*status_names
;
252 * deprecated pluto style return value:
253 * error message, NULL for success
255 typedef const char *err_t
;
258 * Handle struct timeval like an own type.
260 typedef struct timeval timeval_t
;
263 * Handle struct timespec like an own type.
265 typedef struct timespec timespec_t
;
268 * Handle struct chunk_t like an own type.
270 typedef struct sockaddr sockaddr_t
;
273 * Clone a data to a newly allocated buffer
275 void *clalloc(void *pointer
, size_t size
);
278 * Same as memcpy, but XORs src into dst instead of copy
280 void memxor(u_int8_t dest
[], u_int8_t src
[], size_t n
);
283 * Special type to count references
285 typedef volatile u_int refcount_t
;
288 * @brief Get a new reference.
290 * Increments the reference counter atomic.
292 * @param ref pointer to ref counter
294 void ref_get(refcount_t
*ref
);
297 * @brief Put back a unused reference.
299 * Decrements the reference counter atomic and
300 * says if more references available.
302 * @param ref pointer to ref counter
303 * @return TRUE if no more references counted
305 bool ref_put(refcount_t
*ref
);
309 #include <printf_hook.h>
311 #endif /* LIBRARY_H_ */