# Is hashing a list of hashes safe?

I have an arbitrary long list of hashes (e.g. git tree hashes), and I'm wondering by how much I am increasing the risk of hash collisions by condensing them into a single hash, like so:

import hashlib
...
rehash(list_of_hashes):
return hashlib.sha224("".join(sorted(list_of_hashes))).hexdigest()


My feeling is that it doesn't increase the odds by an amount I need to worry about, but wouldn't mind confirmation by experts.

-

## migrated from stackoverflow.comAug 27 '14 at 9:46

This question came from our site for professional and enthusiast programmers.

I do need rehash() to return the same result regardless of the order in which the hashes are listed. I will code to avoid duplicates, but if I can't guarantee it, then I'll consider adding code into rehash() to skip over duplicates. –  Christian Goetze Aug 26 '14 at 18:40
There is one common pitfall: In hashtrees you often need to tag leaves and inner notes differently, to ensure an unambiguous tree structure. You didn't include enough context to know if this applies to your scheme as well, but I suspect that you need to use different prefixes when hashing a list of hashes and when hashing a plain file. –  CodesInChaos Aug 27 '14 at 10:01
If you are really worried about collisions, use a larger size hash, eg SHA-512 –  Richie Frame Aug 28 '14 at 0:28

Unless I'm missing something, sorting will trivially increase chance of collisions since $H(h_1, h_2)$ becomes equal to $H(h_2, h_1)$. –  otus Aug 28 '14 at 9:26