b091f2601a2f5441dfc37e25b6e0ab72d56e7559
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.
95 * Code integrity check of libstrongswan
97 * @ingroup libstrongswan
101 * @defgroup utils utils
103 * Generic helper classes.
105 * @ingroup libstrongswan
109 #include <sys/types.h>
117 * Number of bits in a byte
119 #define BITS_PER_BYTE 8
122 * Default length for various auxiliary text buffers
127 * Macro compares two strings for equality
129 #define streq(x,y) (strcmp(x, y) == 0)
132 * Macro compares two binary blobs for equality
134 #define memeq(x,y,len) (memcmp(x, y, len) == 0)
137 * Macro gives back larger of two values.
139 #define max(x,y) ((x) > (y) ? (x):(y))
142 * Macro gives back smaller of two values.
144 #define min(x,y) ((x) < (y) ? (x):(y))
147 * Call destructor of an object, if object != NULL
149 #define DESTROY_IF(obj) if (obj) obj->destroy(obj)
152 * Call offset destructor of an object, if object != NULL
154 #define DESTROY_OFFSET_IF(obj, offset) if (obj) obj->destroy_offset(obj, offset);
157 * Call function destructor of an object, if object != NULL
159 #define DESTROY_FUNCTION_IF(obj, fn) if (obj) obj->destroy_function(obj, fn);
162 * Debug macro to follow control flow
164 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
167 * Macro to allocate a sized type.
169 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
172 * Assign a function as a class method
174 #define ASSIGN(method, function) (method = (typeof(method))function)
179 #define UNDEFINED_TIME 0
182 * General purpose boolean type.
188 typedef enum status_t status_t
;
191 * Return values of function calls.
210 * The suggested operation is already done
220 * One of the arguments is invalid.
225 * Something could not be found.
230 * Error while parsing.
235 * Error while verifying.
240 * Object in invalid state.
245 * Destroy object which called method belongs to.
250 * Another call to the method is required.
256 * used by strict_crl_policy
265 * enum_names for type status_t.
267 extern enum_name_t
*status_names
;
270 * deprecated pluto style return value:
271 * error message, NULL for success
273 typedef const char *err_t
;
276 * Handle struct timeval like an own type.
278 typedef struct timeval timeval_t
;
281 * Handle struct timespec like an own type.
283 typedef struct timespec timespec_t
;
286 * Handle struct chunk_t like an own type.
288 typedef struct sockaddr sockaddr_t
;
291 * Clone a data to a newly allocated buffer
293 void *clalloc(void *pointer
, size_t size
);
296 * Same as memcpy, but XORs src into dst instead of copy
298 void memxor(u_int8_t dest
[], u_int8_t src
[], size_t n
);
301 * Special type to count references
303 typedef volatile u_int refcount_t
;
306 * @brief Get a new reference.
308 * Increments the reference counter atomic.
310 * @param ref pointer to ref counter
312 void ref_get(refcount_t
*ref
);
315 * @brief Put back a unused reference.
317 * Decrements the reference counter atomic and
318 * says if more references available.
320 * @param ref pointer to ref counter
321 * @return TRUE if no more references counted
323 bool ref_put(refcount_t
*ref
);
327 #include <printf_hook.h>
329 #endif /* LIBRARY_H_ */