5 ms·
But in this case you'd want to use a constant-time string comparison function, which, afaik, strcmp() is not.
by akx 11y ago
But in this case you'd want to use a constant-time string comparison function, which, afaik, strcmp() is not.
- simias 11y agoIs such a timing attack really possible over the internet? I'd expect the code to expire after a few failed attempt anyway. But I guess you're right, better safe than sorry.
- brobinson 11y agoSurprisingly... yes, it is possible. See the link in my other comment: https://news.ycombinator.com/item?id=9953496 https://news.ycombinator.com/item?id=9953496
- rplnt 11y agoWe're comparing one-time fixed-length code. Is it necessary?
- mikeash 11y agoProbably not. Ideally you'd implement this endpoint to invalidate the code after a few failures, so a timing attack would be impossible to carry out. But it's a good idea to use one anyway, in case it turns out that you're wrong, or that other code is also broken somehow. It costs almost nothing to do so.
- pja 11y agoGood point. Is there are library of constant time functions for security sensitive applications to replace the standard ones in libc? (Seems like the kind of thing that the OpenBSD people might have written.) strcmp() is at least better than a buggy equivalent that doesn’t actually work :)
- SCHiM 11y agoThe idea is to use constant time hashing functions, and then compare the hashes instead of comparing the strings themselves. AFAIK there is no implementation of the C stdlib that makes sure no timing attacks can be performed.