3 ms·
The ideal solution is to take 20 bits (low bits, high bits, middle bits -- it doesn't matter) from HMAC-SHA256(key, URL). An HMAC is considered "broken" if an
by cperciva 19y ago
The ideal solution is to take 20 bits (low bits, high bits, middle bits -- it doesn't matter) from HMAC-SHA256(key, URL). An HMAC is considered "broken" if an attacker who doesn't know the key can do significantly better than random chance at guessing what the HMAC of a different URL would be; so until someone breaks HMAC-SHA256 and as long as your secret key remains secret, no attacker will be able to create a denial of service via hash collisions.
Weaker options may or may not be secure; speaking as someone who is professionally paranoid, I suggest not trying to invent your own mechanisms. If you don't have an implementation of HMAC-SHA256 readily available, HMAC-SHA1 or HMAC-MD5 are probably adequate, depending on how paranoid you are. (Or if C code works for you, let me know and I'll point you towards my BSD licensed HMAC-SHA256 code.)