~ubuntu-branches/ubuntu/maverick/strongswan/maverick

« back to all changes in this revision

Viewing changes to src/libstrongswan/chunk.h

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2009-04-01 22:17:52 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090401221752-eozrk0ctabblo94z
* New upstream release, which incorporates the fix. Removed dpatch for it.
  Closes: #521950: CVE-2009-0790: DoS
* New support for EAP RADIUS authentication, enabled for this package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
 
2
 * Copyright (C) 2008-2009 Tobias Brunner
2
3
 * Copyright (C) 2005-2008 Martin Willi
3
4
 * Copyright (C) 2005 Jan Hutter
4
5
 * Hochschule fuer Technik Rapperswil
13
14
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
15
 * for more details.
15
16
 *
16
 
 * $Id: chunk.h 4276 2008-08-22 10:44:51Z martin $
 
17
 * $Id: chunk.h 5003 2009-03-24 17:43:01Z martin $
17
18
 */
18
19
 
19
20
/**
50
51
/**
51
52
 * Create a new chunk pointing to "ptr" with length "len"
52
53
 */
53
 
chunk_t chunk_create(u_char *ptr, size_t len);
 
54
static inline chunk_t chunk_create(u_char *ptr, size_t len)
 
55
{
 
56
        chunk_t chunk = {ptr, len};
 
57
        return chunk;
 
58
}
54
59
 
55
60
/**
56
61
 * Create a clone of a chunk pointing to "ptr"
87
92
/**
88
93
 * Convert a chunk of data to hex encoding.
89
94
 *
90
 
 * The resulting string is '\0' terminated, but the chunk does not include
91
 
 * the '\0'. If buf is supplied, it must hold at least (chunk.len * 2 + 1).
 
95
 * The resulting string is '\\0' terminated, but the chunk does not include
 
96
 * the '\\0'. If buf is supplied, it must hold at least (chunk.len * 2 + 1).
92
97
 *
93
98
 * @param chunk                 data to convert
94
 
 * @param buff                  buffer to write to, NULL to malloc
 
99
 * @param buf                   buffer to write to, NULL to malloc
95
100
 * @param uppercase             TRUE to use uppercase letters
96
101
 * @return                              chunk of encoded data
97
102
 */
112
117
/**
113
118
 * Convert a chunk of data to its base64 encoding.
114
119
 *
115
 
 * The resulting string is '\0' terminated, but the chunk does not include
116
 
 * the '\0'. If buf is supplied, it must hold at least (chunk.len * 4 / 3 + 1).
 
120
 * The resulting string is '\\0' terminated, but the chunk does not include
 
121
 * the '\\0'. If buf is supplied, it must hold at least (chunk.len * 4 / 3 + 1).
117
122
 *
118
123
 * @param chunk                 data to convert
119
 
 * @param buff                  buffer to write to, NULL to malloc
 
124
 * @param buf                   buffer to write to, NULL to malloc
120
125
 * @return                              chunk of encoded data
121
126
 */
122
127
chunk_t chunk_to_base64(chunk_t chunk, char *buf);
135
140
/**
136
141
 * Free contents of a chunk
137
142
 */
138
 
void chunk_free(chunk_t *chunk);
 
143
static inline void chunk_free(chunk_t *chunk)
 
144
{
 
145
        free(chunk->ptr);
 
146
        *chunk = chunk_empty;
 
147
}
139
148
 
140
149
/**
141
150
 * Overwrite the contents of a chunk and free it
142
151
 */
143
 
void chunk_clear(chunk_t *chunk);
 
152
static inline void chunk_clear(chunk_t *chunk)
 
153
{
 
154
        if (chunk->ptr)
 
155
        {
 
156
                memset(chunk->ptr, 0, chunk->len);
 
157
                chunk_free(chunk);
 
158
        }
 
159
}
144
160
 
145
161
/**
146
162
 * Initialize a chunk to point to buffer inspectable by sizeof()
185
201
/**
186
202
 * Skip n bytes in chunk (forward pointer, shorten length)
187
203
 */
188
 
chunk_t chunk_skip(chunk_t chunk, size_t bytes);
 
204
static inline chunk_t chunk_skip(chunk_t chunk, size_t bytes)
 
205
{
 
206
        if (chunk.len > bytes)
 
207
        {
 
208
                chunk.ptr += bytes;
 
209
                chunk.len -= bytes;
 
210
                return chunk;
 
211
        }
 
212
        return chunk_empty;
 
213
}
189
214
 
190
215
/**
191
216
 *  Compare two chunks, returns zero if a equals b
197
222
 * Compare two chunks for equality,
198
223
 * NULL chunks are never equal.
199
224
 */
200
 
bool chunk_equals(chunk_t a, chunk_t b);
201
 
 
202
 
/**
203
 
 * Get printf hooks for a chunk.
 
225
static inline bool chunk_equals(chunk_t a, chunk_t b)
 
226
{
 
227
        return a.ptr != NULL  && b.ptr != NULL &&
 
228
                        a.len == b.len && memeq(a.ptr, b.ptr, a.len);
 
229
}
 
230
 
 
231
/**
 
232
 * Computes a 32 bit hash of the given chunk.
 
233
 * Note: This hash is only intended for hash tables not for cryptographic purposes.
 
234
 */
 
235
u_int32_t chunk_hash(chunk_t chunk);
 
236
 
 
237
/**
 
238
 * Incremental version of chunk_hash. Use this to hash two or more chunks.
 
239
 */
 
240
u_int32_t chunk_hash_inc(chunk_t chunk, u_int32_t hash);
 
241
 
 
242
/**
 
243
 * printf hook function for chunk_t.
204
244
 *
205
245
 * Arguments are: 
206
246
 *    chunk_t *chunk
 
247
 * Use #-modifier to print a compact version
207
248
 */
208
 
printf_hook_functions_t chunk_get_printf_hooks();
 
249
int chunk_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec,
 
250
                                          const void *const *args);
209
251
 
210
 
#endif /* CHUNK_H_ @}*/
 
252
#endif /** CHUNK_H_ @}*/