How Unity Generates Cache Hash For AssetBundles

I am looking into the technical aspect to how Unity generates the cache name for an asset bundle.

For example, my game caches an asset bundle of URL, Hash128 and CRC to a bundle of Example_Game/b2ee2b99701af83199d653e4 using WWW.LoadFromCacheOrDownload. How does Unity generate the cache’s name from this data? (the “b2ee2b99701af83199d653e4” file name).

In summary, what cryptographic algorithm does Unity use internally to generate this hash for the file name, and how can we recreate the hash from this data ourselves?

For reference, the version of Unity I’m using is Unity 4.6 - hence the old LoadFromCacheOrDownload method that is being used.

Have you actually checked the documentation on the Hash128 class?

The hash algorithm used to compute
Hash128 values is SpookyHash V2. Note
that while this hash algorithm is
quite fast to compute and has good
hash distribution qualities, it is not
a cryptographic hash function.

They linked the wikipedia article for the SpookyHash V2. Though you should be able to find various implementations of that algorithm in the wild.

About what they base the hash on for the cached files, I just don’t know since I never used the cache functionality of the WWW class. Though my guess would be that it may be just the request URL Though if the hash is actually used to distinguish the actual content, it’s probably just the content hashed.

Once you have an implementation of the hash algorithm up and working, I would recommend to first check if it produces the same hash as Unity’s class. If it does you can simply try hashing various things related to the cached file to see if you can produces the same hash.