3 ms·
Forget the dumb time.sleep() idea, I just looked at the keyczar implementation of constant time string comparison. I'll roll that in to the library, thanks.
by simonw 17y ago
Forget the dumb time.sleep() idea, I just looked at the keyczar implementation of constant time string comparison. I'll roll that in to the library, thanks.
- Tuna-Fish 17y agoGood. By the way, the time.sleep wouldn't even have worked -- the big deal with timing things on the web is that unless you run some kind of autobanning script, they get unlimited attempts. I'm pretty sure that if I get a hundred-thousand-similar-attempt dataset I can calculate the mean time to such accuracy that the random sleep time doesn't hamper me at all. And I can collect that data over such a large time you might not even notice.
- simonw 17y agoYeah, I figured that after I read up on the timing attack and saw that it's based on statistics over many runs. Crypto is hard!
- illumen 17y agohello, I just tested the keyczar routine, and it can still be found. The sleep needs to be long enough, and random enough that it makes the other variance statistically insignificant. cheers,
- tptacek 17y agoWhat version of Keyczar did you test? Here's the current code: http://code.google.com/p/keyczar/source/browse/trunk/python/src/keyczar/keys.py http://code.google.com/p/keyczar/source/browse/trunk/python/... From the code: correctMac = self.Sign(msg) if len(sig_bytes) != len(correctMac): return False result = 0 for x, y in zip(correctMac, sig_bytes): result |= ord(x) ^ ord(y) return result == 0 This code performs the same ALU ops on every byte of the MAC, and does not perform any bytewise comparisons if the MACs aren't the same size. It's not timeable.
- illumen 17y agoIt is quite easy to time for yourself. Try timing it many times with a sig_bytes off by one(only one character changed). Then compare that with the correct one. You'll notice the (small) difference. There are no tests for it in the keyczar that I could find. I doubt they tested it. The reasons are many... but this is python, so each operation is much more complicated than C/asm. There are lots of branches, memory usage and cache effects - so code is much more input dependant - especially the integer ops used here. Take a look at this code to see one of the reasons why this python code has variable timing depending on input(like most code does). x,y = 3,3 id(x) == id(y) # python shares ints in different variables
- tptacek 17y agoThe only data-dependent comparison you've got to work with is a comparison between two register-scale fixed-width integers. I think you're doing something wrong. Perhaps whatever you're doing to create the "off by one" case is disrupting the cache, and you're just seeing the effects of that.
- Tuna-Fish 17y ago> The sleep needs to be long enough, and random enough that it makes the other variance statistically insignificant. Given the restrictions, this is actually impossible. (the operation has to be quick enough that it doesn't significantly erode user satisfaction, and the smallest possible "sleep" is a single machine instruction). Your adversary can easily collect millions of samples, or even a lot more. You cannot hide the latency difference well enough.