File indexing completed on 2026-05-10 08:44:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef LLVM_SUPPORT_MD5_H
0029 #define LLVM_SUPPORT_MD5_H
0030
0031 #include "llvm/ADT/StringRef.h"
0032 #include "llvm/Support/Endian.h"
0033 #include <array>
0034 #include <cstdint>
0035
0036 namespace llvm {
0037
0038 template <unsigned N> class SmallString;
0039 template <typename T> class ArrayRef;
0040
0041 class MD5 {
0042 public:
0043 struct MD5Result : public std::array<uint8_t, 16> {
0044 SmallString<32> digest() const;
0045
0046 uint64_t low() const {
0047
0048
0049 using namespace support;
0050 return endian::read<uint64_t, llvm::endianness::little>(data());
0051 }
0052
0053 uint64_t high() const {
0054 using namespace support;
0055 return endian::read<uint64_t, llvm::endianness::little>(data() + 8);
0056 }
0057 std::pair<uint64_t, uint64_t> words() const {
0058 using namespace support;
0059 return std::make_pair(high(), low());
0060 }
0061 };
0062
0063 MD5();
0064
0065
0066 void update(ArrayRef<uint8_t> Data);
0067
0068
0069 void update(StringRef Str);
0070
0071
0072 void final(MD5Result &Result);
0073
0074
0075 MD5Result final();
0076
0077
0078
0079
0080 MD5Result result();
0081
0082
0083
0084 static void stringifyResult(MD5Result &Result, SmallVectorImpl<char> &Str);
0085
0086
0087 static MD5Result hash(ArrayRef<uint8_t> Data);
0088
0089 private:
0090
0091 typedef uint32_t MD5_u32plus;
0092
0093
0094 struct {
0095 MD5_u32plus a = 0x67452301;
0096 MD5_u32plus b = 0xefcdab89;
0097 MD5_u32plus c = 0x98badcfe;
0098 MD5_u32plus d = 0x10325476;
0099 MD5_u32plus hi = 0;
0100 MD5_u32plus lo = 0;
0101 uint8_t buffer[64];
0102 MD5_u32plus block[16];
0103 } InternalState;
0104
0105 const uint8_t *body(ArrayRef<uint8_t> Data);
0106 };
0107
0108
0109 inline uint64_t MD5Hash(StringRef Str) {
0110 using namespace support;
0111
0112 MD5 Hash;
0113 Hash.update(Str);
0114 MD5::MD5Result Result;
0115 Hash.final(Result);
0116
0117 return Result.low();
0118 }
0119
0120 }
0121
0122 #endif