summaryrefslogtreecommitdiff
path: root/common/lib/libc/string/consttime_memequal.c
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2013-06-24 04:21:19 +0000
committerriastradh <riastradh@NetBSD.org>2013-06-24 04:21:19 +0000
commitadfdcceb8aad478bc3c5692fb3aff045c0c8ef37 (patch)
treeee62fd1d002750ee339715e953885019cf401475 /common/lib/libc/string/consttime_memequal.c
parent8fcb059d64019ef3a03b90cb11f6c6d47aeeb6b9 (diff)
Replace consttime_bcmp/explicit_bzero by consttime_memequal/explicit_memset.
consttime_memequal is the same as the old consttime_bcmp. explicit_memset is to memset as explicit_bzero was to bcmp. Passes amd64 release and i386/ALL, but I'm sure I missed some spots, so please let me know.
Diffstat (limited to 'common/lib/libc/string/consttime_memequal.c')
-rw-r--r--common/lib/libc/string/consttime_memequal.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/common/lib/libc/string/consttime_memequal.c b/common/lib/libc/string/consttime_memequal.c
new file mode 100644
index 00000000000..969e53295fe
--- /dev/null
+++ b/common/lib/libc/string/consttime_memequal.c
@@ -0,0 +1,19 @@
+/* $NetBSD: consttime_memequal.c,v 1.1 2013/06/24 04:21:19 riastradh Exp $ */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <string.h>
+#define consttime_memequal __consttime_memequal
+#else
+#include <lib/libkern/libkern.h>
+#endif
+
+int
+consttime_memequal(const void *b1, const void *b2, size_t len)
+{
+ const char *c1 = b1, *c2 = b2;
+ int res = 0;
+
+ while (len --)
+ res |= *c1++ ^ *c2++;
+ return res;
+}