aboutsummaryrefslogtreecommitdiff
path: root/src/common/di_ops.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-05-09 18:39:23 -0400
committerNick Mathewson <nickm@torproject.org>2011-05-11 16:12:33 -0400
commit4b19730c8234de3587bd50256fcb11660fb07388 (patch)
tree01a606ed8b66ea94ec482395b09c16762b9bc91a /src/common/di_ops.h
parent8a36f2125137dc31a0771a8eeac0f2bb8c1343d0 (diff)
downloadtor-4b19730c8234de3587bd50256fcb11660fb07388.tar
tor-4b19730c8234de3587bd50256fcb11660fb07388.tar.gz
Add a data-independent variant of memcmp and a d-i memeq function.
The tor_memcmp code is by Robert Ransom, and the tor_memeq code is by me. Both incorporate some ideas from DJB's stuff.
Diffstat (limited to 'src/common/di_ops.h')
-rw-r--r--src/common/di_ops.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/common/di_ops.h b/src/common/di_ops.h
new file mode 100644
index 000000000..1b223d9ab
--- /dev/null
+++ b/src/common/di_ops.h
@@ -0,0 +1,28 @@
+/* Copyright (c) 2003-2004, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2011, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file di_ops.h
+ * \brief Headers for di_ops.c
+ **/
+
+#ifndef TOR_DI_OPS_H
+#define TOR_DI_OPS_H
+
+#include "orconfig.h"
+#include "torint.h"
+
+int tor_memcmp(const void *a, const void *b, size_t sz);
+int tor_memeq(const void *a, const void *b, size_t sz);
+#define tor_memneq(a,b,sz) (!tor_memeq((a),(b),(sz)))
+
+/** Alias for the platform's memcmp() function. This function is
+ * <em>not</em> data-independent: we define this alias so that we can
+ * mark cases where we are deliberately using a data-dependent memcmp()
+ * implementation.
+ */
+#define fast_memcmp(a,b,c) (memcmp((a),(b),(c)))
+
+#endif