summaryrefslogtreecommitdiff
path: root/src/libstrongswan/chunk.h
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2009-02-28 22:02:31 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2009-02-28 22:02:31 +0000
commit19364e11c66714324bd3d5d0dc9212db397085cb (patch)
treefe7f5e55f0474dad1d0c29ba7c0a6f4546c99c3a /src/libstrongswan/chunk.h
parentc7f1b0530b85bc7654e68992f25ed8ced5d0a80d (diff)
downloadvyos-strongswan-19364e11c66714324bd3d5d0dc9212db397085cb.tar.gz
vyos-strongswan-19364e11c66714324bd3d5d0dc9212db397085cb.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.2.12)
Diffstat (limited to 'src/libstrongswan/chunk.h')
-rw-r--r--src/libstrongswan/chunk.h52
1 files changed, 46 insertions, 6 deletions
diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h
index 7e70a2a2d..2986e0db3 100644
--- a/src/libstrongswan/chunk.h
+++ b/src/libstrongswan/chunk.h
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2008 Tobias Brunner
* Copyright (C) 2005-2008 Martin Willi
* Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil
@@ -13,7 +14,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: chunk.h 4276 2008-08-22 10:44:51Z martin $
+ * $Id: chunk.h 4841 2009-01-15 01:52:44Z andreas $
*/
/**
@@ -50,7 +51,11 @@ extern chunk_t chunk_empty;
/**
* Create a new chunk pointing to "ptr" with length "len"
*/
-chunk_t chunk_create(u_char *ptr, size_t len);
+static inline chunk_t chunk_create(u_char *ptr, size_t len)
+{
+ chunk_t chunk = {ptr, len};
+ return chunk;
+}
/**
* Create a clone of a chunk pointing to "ptr"
@@ -135,12 +140,23 @@ chunk_t chunk_from_base64(chunk_t base64, char *buf);
/**
* Free contents of a chunk
*/
-void chunk_free(chunk_t *chunk);
+static inline void chunk_free(chunk_t *chunk)
+{
+ free(chunk->ptr);
+ *chunk = chunk_empty;
+}
/**
* Overwrite the contents of a chunk and free it
*/
-void chunk_clear(chunk_t *chunk);
+static inline void chunk_clear(chunk_t *chunk)
+{
+ if (chunk->ptr)
+ {
+ memset(chunk->ptr, 0, chunk->len);
+ chunk_free(chunk);
+ }
+}
/**
* Initialize a chunk to point to buffer inspectable by sizeof()
@@ -185,7 +201,16 @@ void chunk_clear(chunk_t *chunk);
/**
* Skip n bytes in chunk (forward pointer, shorten length)
*/
-chunk_t chunk_skip(chunk_t chunk, size_t bytes);
+static inline chunk_t chunk_skip(chunk_t chunk, size_t bytes)
+{
+ if (chunk.len > bytes)
+ {
+ chunk.ptr += bytes;
+ chunk.len -= bytes;
+ return chunk;
+ }
+ return chunk_empty;
+}
/**
* Compare two chunks, returns zero if a equals b
@@ -197,7 +222,22 @@ int chunk_compare(chunk_t a, chunk_t b);
* Compare two chunks for equality,
* NULL chunks are never equal.
*/
-bool chunk_equals(chunk_t a, chunk_t b);
+static inline bool chunk_equals(chunk_t a, chunk_t b)
+{
+ return a.ptr != NULL && b.ptr != NULL &&
+ a.len == b.len && memeq(a.ptr, b.ptr, a.len);
+}
+
+/**
+ * Computes a 32 bit hash of the given chunk.
+ * Note: This hash is only intended for hash tables not for cryptographic purposes.
+ */
+u_int32_t chunk_hash(chunk_t chunk);
+
+/**
+ * Incremental version of chunk_hash. Use this to hash two or more chunks.
+ */
+u_int32_t chunk_hash_inc(chunk_t chunk, u_int32_t hash);
/**
* Get printf hooks for a chunk.