I'm looking to use password-style hashing to validate an environment, where some parts may be irrelevant. For example:
requirement = 0b1010
pattern = 0b1011
mask( a, b ) = a & b
hash( a ) = <any cryptographic hash>
condition = hash( mask( requirement, pattern ) )
# public
environment = 0b1110
hash( mask( environment, pattern ) ) == condition
-> true
So for the requirement 0b1010
and pattern 0b1011
, both environments 0b1010
and 0b1110
would match (though typically there would be many more possibilities, since I expect only a small proportion of an environment to be relevant for a particular test)
The pseudo-code above would accomplish my goal, but it requires the pattern to be available in plain-text (since it must be applied to the given environment directly). The final check is performed publicly, and I would like to hide the pattern at this point, i.e.:
mask( a, b ) = ???
hash( a ) = ???
encryptedPattern = ???
condition = mask( hash( requirement ), encryptedPattern )
# public
environment = 0b1110
mask( hash( environment ), encryptedPattern ) == condition
-> true
The ultimate brute-force approach would be to generate salted hashes for every matching environment (doubling-up some possibilities to hide the information about how many bits the pattern masks out) and test them all in-turn, but clearly this isn't practical once more than a few bits are considered irrelevant.
I haven't been able to find anything on hashes constructed to have deliberate collisions, or accept ranges, and I don't believe it would be possible to retain positional information through a hash while maintaining irreversibility. At the same time, this feels like something which has probably already been studied, and I'm just missing the relevant terminology to find it.
Is there any existing work on this type of check, or methods which could be extended to support it? Alternatively, is it provably impossible?
For context, my eventual plan is to extend this by checking hash( mask( hash( environment ), encryptedPattern ) ) == hash( condition )
, and use the unhashed condition (which would only be available by getting the "password" correct) as a key to decrypt other data.
mask
andhash
, as well as thecondition
andencryptedPattern
variables in the second pseudo-code. The process which producescondition
andencryptedPattern
from the secretrequirement
andpattern
would be private. $\endgroup$