Re: Hash function anomaly
- Posted by PeteE Sep 29, 2011
- 1240 views
I'm looking at an old source tree (4.0b3) and in the calc_hash function, for the sequence path, the prev hash is added to the tf hash:
tf.ieee_uint.a += prev.ieee_uint.b; tf.ieee_uint.b += prev.ieee_uint.a;This makes the same hash result regardless of the order of the elements (since addition is associative.)
Edit: I may be incorrect. The hash is already chained, and the addition only affects the Nth and Nth-from-last elements. I can't explain why it doesn't work.
Instead the hash calculation should be chained (untested!):
for(tfi = 0; tfi < 8; tfi++) { if (prev.ieee_char[tfi] == 0) prev.ieee_char[tfi] = (unsigned char)(tfi * 171 + 1); lHashValue = rol(lHashValue, 3) ^ (prev.ieee_char[tfi] + (tfi + 1) << 8); } for(tfi = 0; tfi < 8; tfi++) { if (tf.ieee_char[tfi] == 0) tf.ieee_char[tfi] = (unsigned char)(tfi * 171 + 1); lHashValue = rol(lHashValue, 3) ^ (tf.ieee_char[tfi] + (tfi + 1) << 8); }