I have concerns regarding truncated SHA-256 hashes in an application I am building at the moment:
Nomenclature
secret
- the full 256-bit SHA-256 result of hashing 16 random bytes
public
- a unique identifier for an object.
hash
- the output of SHA-256(secret || - || public)
prefix
- the first 8 characters (32-bit) of hex encoded hash
.
Scenario
secret
is generated once and remains constant throughout the lifecycle of the scenario.
It is not known to the attacker
Identifiers for all objects (publics
) are known to the attacker.
prefix
will be the base for further computation and information retrieval for a given object.
The first 4 bytes (32 bit) of hash
have to be sufficient for that.
It is important that a potential attacker cannot generate a valid prefix
for a given public
.
Concerns
The attacker's utopia is to find secret
so they can generate a valid hash
for every object.
This is unrealistic to brute force (computation would take forever).
However, because only the first 32 bit of hash
matter, is there a mechanic / cryptographic attribute, that makes it feasible for the attacker to guess / compute a valid secret
that would allow them to generate prefix
values for given publics
?
Example
secret = 'af8b81c94d68...' (256-bit)
public = '123456'
hash = 'fe13c815ab44...' (256-bit)
prefix = hash[0...8] = 'fe13c815'
Can the attacker guess secret
such that they would end up with a valid prefix
?
Can the attacker use that guessed, validated secret
and compute prefix
values for different publics
?
prefix
for a given `public"; how do you define a valid prefix? What is the validation process to check if a prefix is valid? If the attacker just picks an arbitrary value for the prefix, how do we know that it's not valid? $\endgroup$