Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src



On Thu, Aug 30, 2012 at 06:44:31PM +0000, Christos Zoulas wrote:
> In article <20120830170609.14DD160534%jupiter.mumble.net@localhost>,
> Taylor R Campbell  <campbell+netbsd-source-changes-d%mumble.net@localhost> 
> wrote:
> >   Date: Thu, 30 Aug 2012 11:44:41 -0400
> >   From: christos%zoulas.com@localhost (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?

The extra cache miss for the extra code ...
The effect of the change in the branch prediction tables....

I'm no expert here though.
FWIW which versions of memset() aren't 'constant time' ?
Apart from ones that try not to dirty pages.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index