Choosing A Hash Function

Note: this document is still very much a work-in-progress. Currently missing:

  • recommendations for hashed containers
  • recommendations for a better persistent hash
  • recommendations for a secure hash

If a hash function with unchanging output is needed, please select from one of the unchanging forever options below.

Non-cryptographic

nameinputoutputunchanging forevernotes
Hash()overloadeduint32_tnoThis function is currently being updated to return size_t.
PersistentHash()overloadeduint32_tyesFairly weak but widely used for persisted hashes.
CityHash64()base::span<const uint8_t>uint64_tyes (note 1)Version 1.0.3. Has some known weaknesses.
CityHash64WithSeed()base::span<const uint8_t>uint64_tyes (note 1)Version 1.0.3. Has some known weaknesses.

Cryptographic

There are no hashes in //base that provide cryptographic security.

nameinputoutputunchanging forevernotes
MD5String()std::stringstd::stringyesINSECURE
SHA1HashStringstd::stringstd::stringyesINSECURE

Deprecated

Note: CRC32, Murmur2, and Murmur3 will be listed here.

Note 1: While CityHash is not guaranteed unchanging forever, the version used in Chrome is pinned to version 1.0.3.