5 ms·
I just found a use-case for the sleep( rand(1000) ) function :-)
by animex 6y ago
I just found a use-case for the sleep( rand(1000) ) function :-)
- faeyanpiraat 6y agoNope! If the rand function produces uniform random numbers, then with enough samples the signal comes out ontop the noise. If it is non-uniform, then with enough samples you can determine the non uniformity, and you are at square 1 again. Use proper security instead of obscurity.
- animex 6y agoEasily accommodated for. I can get the execution run-time and store in an average in memory for some time-period and have the sleep function top-up the difference between the two paths. Not sure what the "proper security" method is to prevent execution deltas.
- renewiltord 6y agoWhy not just run the thing (which takes some small fraction of time), then pad to five seconds, and respond. Since your work will be done in milliseconds, padding to nearest five seconds will remove any noise. And it's not a thing anyone has a legitimate interest in submitting more than that per second.
- odonnellryan 6y agoAdding five seconds to everything just adds five seconds, it doesn't matter if the difference between the two requests is .01s or 5.01s.
- throwaway894345 6y agoThe parent said "pad to 5 seconds" not "add 5 seconds". Thus everything would be 5 seconds (never 5.01). The difference between a hit and a miss would be exactly 0s. Note that I'm not advocating for or against this solution; rather, clarifying the conversation.
- renewiltord 6y agoPad to, not pad by. I.e. the padding to add is (5 - duration_of_operation) with duration of operation being far lower than 5 s.
- bitexploder 6y agoDepends. With comparison functions you can implement a constant time comparison that takes the same amount of time. In this case it isn’t really a crypto problem, so anything where we are confident about things taking the same amount of time is fine. Basically in some parent method/func make sure we always spend 2000ms or whatever time is that is always greater than the max runtime of the slowest path. Secondary / defense in depth mitigations would be rate limiting this page and making it purposefully slow on response, just to make it that much harder to collect samples / abuse it without being noticed. The captcha is a nice touch, but it didn’t seem particularly strong (a good captcha solver could break it). Still, captcha will chase off a lot of script kiddies. You don’t have to be faster than the bear, just faster than the slowest person ;)
- aljarry 6y agorand() produces linear distributon, which is uniform. Do I understand properly that rand() + rand() would return normal distribution, so #2, for which you can determine the non uniformity? What would be a proper first step to harden API for timing attacks?
- z77dj3kl 6y agorand() + rand() does not give normal. If there is any statistical difference between the timings, it's in theory possible to break. An easy mitigation would be to just drop the card number into a queue and process asynchronously without waiting and returning to the user.
- kevin_thibedeau 6y agoFlood the queue with invalid numbers and timings can still be worked out.
- eru 6y agoAdding any random noise, even perfect randomness, doesn't prevent the attack. It just means the attacker needs more samples.
- mellavora 6y agorand() + rand() does not produce normal, but adding together a few thousand rands does start to approach it. Central limit theorem.
- wodenokoto 6y agoI would have gone for `sleep(1000)` and have it run in parallel with the actual function, so that every request takes 1000 milliseconds