summaryrefslogtreecommitdiff
path: root/src/libstrongswan/utils/chunk.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/utils/chunk.h')
-rw-r--r--src/libstrongswan/utils/chunk.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/chunk.h b/src/libstrongswan/utils/chunk.h
index 48405b77e..2ec7f7543 100644
--- a/src/libstrongswan/utils/chunk.h
+++ b/src/libstrongswan/utils/chunk.h
@@ -310,6 +310,19 @@ static inline bool chunk_equals(chunk_t a, chunk_t b)
}
/**
+ * Compare two chunks for equality, constant time for cryptographic purposes.
+ *
+ * Note that this function is constant time only for chunks with the same
+ * length, i.e. it does not protect against guessing the length of one of the
+ * chunks.
+ */
+static inline bool chunk_equals_const(chunk_t a, chunk_t b)
+{
+ return a.ptr != NULL && b.ptr != NULL &&
+ a.len == b.len && memeq_const(a.ptr, b.ptr, a.len);
+}
+
+/**
* Compare two chunks (given as pointers) for equality (useful as callback),
* NULL chunks are never equal.
*/