Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/common/lib/libc/string Comment on possible data-dependent br...
details: https://anonhg.NetBSD.org/src/rev/bb1e1d375e9b
branches: trunk
changeset: 789633:bb1e1d375e9b
user: riastradh <riastradh%NetBSD.org@localhost>
date: Wed Aug 28 19:31:14 2013 +0000
description:
Comment on possible data-dependent branch in `!res'.
diffstat:
common/lib/libc/string/consttime_memequal.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diffs (25 lines):
diff -r 9cdce396d948 -r bb1e1d375e9b common/lib/libc/string/consttime_memequal.c
--- a/common/lib/libc/string/consttime_memequal.c Wed Aug 28 19:04:12 2013 +0000
+++ b/common/lib/libc/string/consttime_memequal.c Wed Aug 28 19:31:14 2013 +0000
@@ -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 @@
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;
}
Home |
Main Index |
Thread Index |
Old Index