News for hackers. Stuff that matters.
Re:X86 is a high-level language by jlebar on Wednesday March 25, 2015 @02:54PM (#9265119)
> The fact that xor eax,eax is just a register operation doesn't mean it can leak sensitive information.

AIUI tfa's point is that you can't assume that

xor eax,eax

and

xor eax,ebx

take the same amount of time, because "x86 is a high level language". Similarly for his other examples. This, he claims, makes it difficult to write code that resists timing attacks, if you ever want to have a branch that does nothing. Thus the discussion of cmov.

Re:X86 is a high-level language by barrkel on Wednesday March 25, 2015 @03:25PM (#9265299)
The point of the grandparent's post is that timing information is only leaked if the CPU's timing is data dependent. It's not enough to show that different instructions take unpredictable amounts of time. If the sequence of CPU instructions that get executed are the same for varying data, then the unpredictability of the individual instructions doesn't create a timing attack.

xor eax,eax scans, to an x86 assembly programmer, as "eax := 0". It's idiomatic for clearing a register. There ought not be any expectation from an assembly programmer that such a frequent operation would take the same amount of time as xor eax,ebx (in particular, xor eax,eax doesn't depend on the value of eax, so it doesn't need to stall waiting for its value to be calculated). But if xor eax,eax took a different amount of time depending on whether eax was equal to 42 or not, that would be a different matter.

Re:X86 is a high-level language by TheLoneWolfling on Wednesday March 25, 2015 @04:10PM (#9265590)
Division on some processors takes a data-dependent amount of time. See riscy's comment.
Re:X86 is a high-level language by mreiland on Wednesday March 25, 2015 @05:56PM (#9266238)
Can someone explain to me why you wouldn't just count clock ticks at a higher level than the CPU? If the operation finishes early just... wait. I understand resolution and yes you'll probably only be w/i a delta of some sort, but isn't that the point?

Why wouldn't that approach work?

Re:X86 is a high-level language by jstarks on Wednesday March 25, 2015 @09:37PM (#9267294)
Even if you could figure out the worst-case timings and how to simulate them in all cases, the performance would be unacceptable. The usual operations that are data-dependent in crypto algorithms are mov with a data-dependent address, and conditional jump with a data-dependent condition. To slow these down, you'd have to simulate the absolute worst case, which means no caches of any kind, which means possibly thousands or even millions of cycles (to simulate a page fault from disk) for every operation of unknown duration. Crypto would become infeasible.

There are much better ways to achieve this, by always computing both sides of a (logical) branch or using computation instead of branching or table lookups. You likely have to write this in assembly to be sure that the compiler doesn't "optimize" any of your tricks back into branches. Some of this is hard in older crypto algorithms (AES was designed to use table lookups in software), but newer crypto algorithms are much more amenable to safe implementation.

Re:X86 is a high-level language by TheLoneWolfling on Wednesday March 25, 2015 @11:53PM (#9267732)
Your operating system hits memory pressure and pages your RAM page to disk. Some time later it restores it. Hey, look, you've suddenly had an arbitrarily long delay. So you can't always finish early.

Also, even assuming you can always finish early, that plan won't prevent, for example, measuring the delay of other responses. (As your process sleeping will have an impact on how fast other responses are sent. Due to cache pressure, in particular. But also due to CPU throttling, scheduling, etc, etc.

Re:X86 is a high-level language by mreiland on Thursday March 26, 2015 @01:18AM (#9267957)
Why is it people can't ever respond to sanity, but instead assume idiocy?

You measure page faults in terms of milliseconds, I was not suggesting you even out the cryptographic timings to the tune of milliseconds, especially when you consider most cryptographic functions are setup specifically to take longer than that.

There is a delta that you can come up with such that things like page faults fall within it and it would still have acceptable performance. All but the most pounded of servers would be able to fall within it with no problem whatsoever.

Re:X86 is a high-level language by TheLoneWolfling on Thursday March 26, 2015 @12:13PM (#9270707)
You completely missed my second point there - that even if you can afford to take the performance hit it still doesn't solve the problem.

And most of the cryptographic functions we're talking about here are things for webservers, where low performance leaves you open to easy (D)DOSing.

Re:X86 is a high-level language by mreiland on Thursday March 26, 2015 @06:44PM (#9273654)
You haven't explained why it doesn't solve the problem. My experience has been if I can't understand it, it's because it's bullshit.

So why not take another crack at explaining why that wouldn't solve the problem? And don't complain to me about DDOS, people specifically code cryptographic functions to take longer than they absolutely have to. If they're not worried about DDOS, neither are we for the purposes of this conversation.