Question

I've got a Map<SHA1, BinaryBlob>. Very similar to Git.

I'd like to put a small, finite number of "special" entries into this map. I'd like to be able to change the values of the binary blobs, but still refer to them by the same key.

The right way to do this is to use a Map<Either<SHA1, SpecialKey>, BinaryBlob>.

The hack way to do this (which is the way I'm actually doing this) is to define:

SHA1 specialKeyA = 0x00000 ... 00
SHA1 specialKeyB = 0x00000 ... 01

I understand that SHA1 produces values which are evenly distributed. But I wonder if maybe there's an asterisk, and if there are a couple corner-case hashes (such as 0x00.. or maybe 0xFF...) which are guaranteed not to happen.

I feel pretty safe with my current design, but I was just curious :)

EDIT: I'm already counting on hash uniqueness, so I feel very safe with the design. The question is for curiosity's sake: are there a handful of values which SHA1 happens to be incapable of generating. Census in the comments so far seems to be no...

Was it helpful?

Solution

To the best of my knowledge SHA1 does not have a known pre-image of 00…00 (and neither 00…01,00…02, or other "special" values). Even though it would not violate any of the formal definitions of a secure hash the IVs are designed to avoid such human recognizable patterns.

Still I would probably advise against the use of these values, because others might, too, have come up with the idea to use these special values, see this question about a git commit with all zeros for example. If it is all the same to you I would generate a random 80bit value, for example 83a…c3, and append your counter to it, for example 83a…c300…01, 83a…c300…02,etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top