Final goal: I want to identify equality of mesh geometry data (and other attributes)
my choice of the mean: by comparing their "top sha1 hash".
But to make the top hash, I need to combine hashes from sub-routines hashing their own data.
TLDR
question: how do you combine cryptographical hashes, such as a sha1
hash ?
(I'd like a boost::hash_combine<160>(h1, h2)
)
NLEWTRM (Not Long Enough Want To Read More)
In typical procedural programming you have a "funtion call tree", equivalent to what happens when you let the compiler generate your copy constructors, and when you use it from a top-class, you get a cascade of calls which executes a "deep copy".
So, e.g. equivalently, you can write (manually) a series of hashable types which implements size_t hash_value()
(an unordered
containers requirement), and calling hash_value()
on any type (via ADL) will result in a "deep hash" because you cared of using boost::hash_combine
when calculating your object "local top hash."
I have seen how boost::hash_combine
is implemented, and that is all well for a size_t
.
This combination is necessary for progressive calculation of the hash from subroutines that respect encapsulation.
I reckon this problem is similar to "hash tree" or "hash lists" somehow, and also has been addressed in MD5 in terms of "blocks" (from my knowledge), when hashing a stream for which you can't store all data at once.
Note that in my usage I don't need THE HASH that would be made by hashing all the data at once. Because my implementation (call tree) would be stable, 2 different mesh-object will produce the same hash if they have the same data, and that is the only thing that counts. (because I need comparability, not officialism or canonicalism, nor do I need crypto strength. BUT I need reasonable uniqueness guarantees (more than what a size_t
offers))
obvious way 1: what I think about now as a solution, is to use the sub hash themselves as a message, concatenate and re-hash. newsha = sha1(hash1 + hash2)
with + a message (buffer) concatenation operation.
second obvious way: apply newsha = hash1 ^ hash2
with ^
a modulo operator.