Module Name: src Committed By: riastradh Date: Wed Aug 28 19:31:14 UTC 2013
Modified Files: src/common/lib/libc/string: consttime_memequal.c Log Message: Comment on possible data-dependent branch in `!res'. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/string/consttime_memequal.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/common/lib/libc/string/consttime_memequal.c diff -u src/common/lib/libc/string/consttime_memequal.c:1.3 src/common/lib/libc/string/consttime_memequal.c:1.4 --- src/common/lib/libc/string/consttime_memequal.c:1.3 Wed Aug 28 17:47:07 2013 +++ src/common/lib/libc/string/consttime_memequal.c Wed Aug 28 19:31:14 2013 @@ -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 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; }