moved RSA key size constraints to definitions.h
[strongswan.git] / src / libstrongswan / definitions.h
1 /**
2 * @file definitions.h
3 *
4 * @brief General purpose definitions and macros.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 * Copyright (C) 1998, 1999 D. Hugh Redelmeier. (Endian stuff)
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef DEFINITIONS_H_
25 #define DEFINITIONS_H_
26
27 /* stolen from FreeS/WAN */
28 #if linux
29 # if defined(i386) && !defined(__i386__)
30 # define __i386__ 1
31 # define MYHACKFORTHIS 1
32 # endif
33 # include <endian.h>
34 # ifdef MYHACKFORTHIS
35 # undef __i386__
36 # undef MYHACKFORTHIS
37 # endif
38 #elif !(defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) && defined(BYTE_ORDER))
39 /* we don't know how to do this, so we require the macros to be defined
40 * with compiler flags:
41 * -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=BIG_ENDIAN
42 * or -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=LITTLE_ENDIAN
43 * Thse match the GNU definitions
44 */
45 # include <sys/endian.h>
46 #endif
47
48 #ifndef BIG_ENDIAN
49 #error "BIG_ENDIAN must be defined"
50 #endif
51
52 #ifndef LITTLE_ENDIAN
53 #error "LITTLE_ENDIAN must be defined"
54 #endif
55
56 #ifndef BYTE_ORDER
57 #error "BYTE_ORDER must be defined"
58 #endif
59
60 #define BITS_PER_BYTE 8
61 #define RSA_MIN_OCTETS (1024 / BITS_PER_BYTE)
62 #define RSA_MIN_OCTETS_UGH "RSA modulus too small for security: less than 1024 bits"
63 #define RSA_MAX_OCTETS (8192 / BITS_PER_BYTE)
64 #define RSA_MAX_OCTETS_UGH "RSA modulus too large: more than 8192 bits"
65
66 /**
67 * Default length for various auxiliary text buffers
68 */
69 #define BUF_LEN 512
70
71 /**
72 * Macro compares two strings for equality
73 */
74 #define streq(x,y) (strcmp(x, y) == 0)
75
76 /**
77 * Macro compares two binary blobs for equality
78 */
79 #define memeq(x,y,len) (memcmp(x, y, len) == 0)
80
81 /**
82 * Macro gives back larger of two values.
83 */
84 #define max(x,y) ((x) > (y) ? (x):(y))
85
86 /**
87 * Macro gives back smaller of two values.
88 */
89 #define min(x,y) ((x) < (y) ? (x):(y))
90
91 /**
92 * Debug macro to follow control flow
93 */
94 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
95
96 /**
97 * Macro to allocate a sized type.
98 *
99 * @param thing object on which a sizeof is performed
100 * @return poiner to allocated memory
101 */
102 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
103
104
105 /**
106 * Mapping entry which defines the end of a mapping_t array.
107 */
108 #define MAPPING_END (-1)
109
110 typedef struct mapping_t mapping_t;
111
112 /**
113 * @brief Mapping entry, where enum-to-string mappings are stored.
114 */
115 struct mapping_t
116 {
117 /**
118 * Enumeration value.
119 */
120 int value;
121
122 /**
123 * Mapped string.
124 */
125 char *string;
126 };
127
128
129 /**
130 * @brief Find a mapping_string in the mapping[].
131 *
132 * @param mappings mappings array
133 * @param value enum-value to get the string from
134 *
135 */
136 char *mapping_find(mapping_t *mappings, int value);
137
138 #endif /*DEFINITIONS_H_*/