| 6 | #define BASE_HASH_MD5_CONSTEXPR_H_ |
| 7 |
| 8 | #include "base/hash/md5.h" |
| 9 | #include "base/hash/md5_constexpr_internal.h" |
| 10 |
| 11 | namespace base { |
| 12 |
| 13 | // An constexpr implementation of the MD5 hash function. This is no longer |
| 14 | // considered cryptographically secure, but it is useful as a string hashing |
| 15 | // primitive. |
| 16 | // |
| 17 | // This is not the most efficient implementation, so it is not intended to be |
| 18 | // used at runtime. If you do attempt to use it at runtime you will see |
| 19 | // errors about missing symbols. |
| 20 |
| 21 | // Calculates the MD5 digest of the provided data. When passing |string| with |
| 22 | // no explicit length the terminating null will not be processed. |
| 23 | constexpr MD5Digest MD5SumConstexpr(const char* string); |
| 24 | constexpr MD5Digest MD5SumConstexpr(const char* data, uint32_t length); |
| 25 |
| 26 | // Calculates the first 32/64 bits of the MD5 digest of the provided data, |
| 27 | // returned as a uint32_t/uint64_t. When passing |string| with no explicit |
| 28 | // length the terminating null will not be processed. This abstracts away |
| 29 | // endianness so that the integer will read as the first 4 or 8 bytes of the |
| 30 | // MD5 sum, ensuring that the following outputs are equivalent for |
| 31 | // convenience: |
| 32 | // |
| 33 | // printf("%08x\n", MD5HashConstexpr32("foo")); |
| 34 | // |
| 35 | // MD5Digest d = MD5SumConstexpr("foo"); |
| 36 | // printf("%02x%02x%02x%02x\n", d.a[0], d.a[1], d.a[2], d.a[3]); |
| 37 | constexpr uint64_t MD5Hash64Constexpr(const char* string); |
| 38 | constexpr uint64_t MD5Hash64Constexpr(const char* data, uint32_t length); |
| 39 | constexpr uint32_t MD5Hash32Constexpr(const char* string); |
| 40 | constexpr uint32_t MD5Hash32Constexpr(const char* data, uint32_t length); |
| 41 |
| 42 | } // namespace base |
| 43 |
| 44 | #endif // BASE_HASH_MD5_CONSTEXPR_H_ |
| 45 |