First off, yes I do know that SHA1 is cryptographically insecure (and has been for a long time). So this question is more academic than anything. It's also very contrived, but bear with me.
I want to publish a table of
string IDs with timestamps, but at the same time I don't want somebody to be able to look at the table and use it to enumerate all the resources available.
TmQ5YqqOOPPiEewdntZx 2021-05-05 13:26:38 SVQBu941OWIyDXzSgo2F 2021-05-05 13:26:44 gkxMiz6hEPqV36TidyeG 2021-05-07 09:56:43 vU2OxFFQ4I0gXHGofL8A 2021-05-07 09:56:43
So I can hash the IDs in the table (HMAC is pointless, as the client would need to be aware of the secret used by the table generator):
d3399d662fc58daf44647f188cb6ef30bf76938c 2021-05-05 13:26:38 fc95d2f3af27034ff5a991d5b9a0080cbf45d007 2021-05-05 13:26:44 cd982afcff4ae5e907960f51ae1504a38f4665d1 2021-05-05 13:53:42 e0f31185494f54a3a16ac3483572989f98850c36 2021-05-07 09:56:43
A client, who already knows an ID can hash it, look it up in the public table and check the timestamp. The table should be useless for anyone who doesn't already know an ID.
My thoughts are:
- Even though SHA1 is cryptographically insecure, I'm not using it for verifying the ID, but using it for obfuscation
- Even if somebody can generate a collision, it doesn't give them the ID needed to request the resource
- I don't want to use SHA2 as the shortest hash I can generate is 256 bits, which consumes 60% more storage (imagine I have a lot of them, and I'm very cheap!).
Obvious response will be:
- Just use SHA2, and it's a valid response. I could just truncate the hash if I'm that concerned about storage space and transfer costs. 160-bits is still a larger address space than 62^20, so collisions are unlikely
- Just SHA2, it's faster than SHA1. Yes it is, and actually SHA512 is faster than SHA256 (in .Net anyway)
- Use something else.
If #3, please let me know.
Obviously, I'm going to use SHA2, but is there a cryptographic reason for not using SHA1 (or even MD5 if I was feeling really retro) in this instance. Like I said, the question is mainly academic.