Name Date Size #Lines LOC

..--

README.mdH A D25-Apr-20252.3 KiB4230

hash.ccH A D25-Apr-20255.7 KiB16396

hash.hH A D25-Apr-20252.7 KiB8237

hash_perftest.ccH A D25-Apr-20253 KiB9969

hash_unittest.ccH A D25-Apr-20252.5 KiB9351

legacy_hash.ccH A D25-Apr-2025691 2414

legacy_hash.hH A D25-Apr-2025683 2613

legacy_hash_unittest.ccH A D25-Apr-20251.1 KiB4029

md5.hH A D25-Apr-20252.3 KiB7322

md5_boringssl.ccH A D25-Apr-20251.1 KiB4229

md5_boringssl.hH A D25-Apr-2025597 2611

md5_constexpr.hH A D25-Apr-2025928 289

md5_constexpr_internal.hH A D25-Apr-202510.2 KiB270189

md5_constexpr_unittest.ccH A D25-Apr-20251.8 KiB5431

md5_nacl.ccH A D25-Apr-20259.2 KiB296194

md5_nacl.hH A D25-Apr-2025508 2410

md5_unittest.ccH A D25-Apr-20254.9 KiB199145

sha1.hH A D25-Apr-20251.5 KiB4927

sha1_boringssl.ccH A D25-Apr-20251.4 KiB5236

sha1_boringssl.hH A D25-Apr-2025510 198

sha1_nacl.ccH A D25-Apr-20254.1 KiB203139

sha1_nacl.hH A D25-Apr-2025738 4124

sha1_unittest.ccH A D25-Apr-20255.5 KiB156112

README.md

1# Choosing A Hash Function
2
3> Note: this document is still very much a work-in-progress. Currently missing:
4> - recommendations for hashed containers
5> - recommendations for a better persistent hash
6> - recommendations for a secure hash
7
8If a hash function with unchanging output is needed, please select from one of
9the unchanging forever options below.
10
11## Non-cryptographic
12
13name                                         | input                       | output     | unchanging forever | notes
14---------------------------------------------|-----------------------------|------------|--------------------|-------
15[`Hash()`][hash]                             | overloaded                  | `uint32_t` | no                 | This function is currently being updated to return `size_t`.
16[`PersistentHash()`][persistenthash]         | overloaded                  | `uint32_t` | yes                | Fairly weak but widely used for persisted hashes.
17[`CityHash64()`][cityhash64]                 | `base::span<const uint8_t>` | `uint64_t` | yes (note 1)       | Version 1.0.3. Has some known weaknesses.
18[`CityHash64WithSeed()`][cityhash64withseed] | `base::span<const uint8_t>` | `uint64_t` | yes (note 1)       | Version 1.0.3. Has some known weaknesses.
19
20## Cryptographic
21
22**There are no hashes in `//base` that provide cryptographic security.**
23
24 name                          | input         | output        | unchanging forever | notes
25-------------------------------|---------------|---------------|--------------------|-------
26[`MD5String()`][md5string]     | `std::string` | `std::string` | yes                | **INSECURE**
27[`SHA1HashString`][sha1string] | `std::string` | `std::string` | yes                | **INSECURE**
28
29## Deprecated
30
31> Note: CRC32, Murmur2, and Murmur3 will be listed here.
32
33Note 1: While CityHash is not guaranteed unchanging forever, the version used in
34Chrome is pinned to version 1.0.3.
35
36[hash]: https://cs.chromium.org/chromium/src/base/hash/hash.h?l=26
37[persistenthash]: https://cs.chromium.org/chromium/src/base/hash/hash.h?l=36
38[cityhash64]: https://cs.chromium.org/chromium/src/base/hash/city_v103.h?l=19
39[cityhash64withseed]: https://cs.chromium.org/chromium/src/base/hash/city_v103.h?l=20
40[md5string]: https://cs.chromium.org/chromium/src/base/hash/md5.h?l=74
41[sha1string]: https://cs.chromium.org/chromium/src/base/hash/sha1.h?l=22
42