UUHash is a hash algorithm employed by clients on the FastTrack network. It is employed for its ability to hash very large files in a very short period of time, even on older computers. However, this is achieved by only hashing a fraction of the file. This weakness makes it trivial to create a hash collision, allowing large sections to be completely altered without altering the checksum.
Contents
This method is used by Kazaa. The weakness of UUHash is exploited by anti-p2p agencies to corrupt downloads.
How it works
The UUHash is a 160-bit string that is usually Base64-encoded for presentation. It is a concatenation of an MD5 hash and a CRC32 sum of selected chunks of the file.
The first 307200 bytes (300 Kibibyte, one "chunk size") of the file are MD5-hashed (less if file is shorter). The 32 bit little endian integer value smallhash is initialized to 0.
If the file is strictly larger than one chunk size, a series of chunks at file offsets of 2n MiB (n ≥ 0) and one chunk right at the end of the file are hashed using a CRC32 (polynomial 0xEDB88320 reversed, 0x04C11DB7 normal). The last chunk of the power-of-two series ends strictly more than one chunk size before the end of the file, i.e. there is always at least one unread byte between the last two chunks (if there are that many chunks). The end-of-file chunk may be shorter than one chunk size; it starts at or after one chunk size into the file. The CRC is initialized using smallhash and stored into smallhash.
So, for example:
offset 0 MiB, 300 KiB hashed with MD5offset 1 MiB, 300 KiB hashed with CRC32offset 2 MiB, 300 KiB hashed...offset 4 MiB, 300 KiB hashed...offset 8 MiB, 300 KiB hashed......last 300 KiB of file hashed with CRC32Finally, the bitwise complement of smallhash (still zero for files up to 300 KiB) is XORed together with the file size in bytes. The 160-bit UUHash is now the concatenation of the 128-bit MD5 hash and the final 32-bit smallhash value.
Test Vectors
Given are hashes (base64 and hex) for strings of various lengths containing only 0x00 or 0xFF bytes:
Notice that all strings that have a complete MD5 chunk have the same 128-bit prefix. For files that have the same number of chunks the CRC part differs only because of the included file length (all chunks are identical, or this weren't the case). For files up to 300 KiB, the file length can be extracted from the last four bytes of the hash; smallhash is ~0.
Sig2Dat
The name UUHash derives from the sig2dat utility which creates URIs referencing files on Kazaa. These URIs are of the form:
sig2dat://|File: surprise.mp3|Length:5845871Bytes|UUHash:=1LDYkHDl65OprVz37xN1VSo9b00=Not considering the fact that this URI format is not RFC compliant, UUHash refers to the Base64-encoding of the hash and not the hash itself.