In article <20120830170609.14dd160...@jupiter.mumble.net>, Taylor R Campbell <campbell+netbsd-source-change...@mumble.net> wrote: > Date: Thu, 30 Aug 2012 11:44:41 -0400 > From: chris...@zoulas.com (Christos Zoulas) > > memcmp() does not promise alphabetical sorting. It just promises to do the > byte comparison as unsigned so that the results are consistent. It is not > complicated to do this at all, for example: > > int > consttime_memcmp(const void *s1, const void *s2, size_t n) > { > int rv = 0, sv = 0; > const unsigned char *p1 = s1, *p2 = s2; > > do > if (rv == 0) > rv = *p1++ - *p2++; > >Data-dependent branches are totally unacceptable for a routine whose >sole purpose is to avoid timing side channels. > >Are there any applications that both want memcmp semantics and need to >avoid timing side channels?
How can you tell the difference if both branches execute code that does exactly the same work? christos