From 3db7caeeb36b9f9de6a51a70a6df5467db5a0e2b Mon Sep 17 00:00:00 2001
From: riastradh <riastradh@NetBSD.org>
Date: Wed, 28 Aug 2013 19:31:14 +0000
Subject: [PATCH] Comment on possible data-dependent branch in `!res'.

---
 common/lib/libc/string/consttime_memequal.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/common/lib/libc/string/consttime_memequal.c b/common/lib/libc/string/consttime_memequal.c
index 45c81ec65adf..a00d7e197b4b 100644
--- a/common/lib/libc/string/consttime_memequal.c
+++ b/common/lib/libc/string/consttime_memequal.c
@@ -1,4 +1,4 @@
-/* $NetBSD: consttime_memequal.c,v 1.3 2013/08/28 17:47:07 riastradh Exp $ */
+/* $NetBSD: consttime_memequal.c,v 1.4 2013/08/28 19:31:14 riastradh Exp $ */
 
 #if !defined(_KERNEL) && !defined(_STANDALONE)
 #include "namespace.h"
@@ -18,5 +18,15 @@ consttime_memequal(const void *b1, const void *b2, size_t len)
 
 	while (len --)
 		res |= *c1++ ^ *c2++;
+
+	/*
+	 * If the compiler for your favourite architecture generates a
+	 * conditional branch for `!res', it will be a data-dependent
+	 * branch, in which case this should be replaced by
+	 *
+	 *	return (1 - (1 & ((res - 1) >> 8)));
+	 *
+	 * or rewritten in assembly.
+	 */
 	return !res;
 }