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