Index: include/llvm/Support/MD5.h =================================================================== --- include/llvm/Support/MD5.h +++ include/llvm/Support/MD5.h @@ -62,6 +62,9 @@ /// deposited into \p Str. The result will be of length 32. static void stringifyResult(MD5Result &Result, SmallString<32> &Str); + /// \brief Computes the hash for a given bytes. + static std::vector hash(ArrayRef Data); + private: const uint8_t *body(ArrayRef Data); }; Index: include/llvm/Support/SHA1.h =================================================================== --- include/llvm/Support/SHA1.h +++ include/llvm/Support/SHA1.h @@ -53,6 +53,9 @@ /// made into update. StringRef result(); + /// Returns a raw 160-bit SHA1 hash for the given data. + static std::vector hash(ArrayRef Data); + private: /// Define some constants. /// "static constexpr" would be cleaner but MSVC does not support it yet. Index: lib/Support/MD5.cpp =================================================================== --- lib/Support/MD5.cpp +++ lib/Support/MD5.cpp @@ -283,4 +283,12 @@ Res << format("%.2x", Result[i]); } +std::vector MD5::hash(ArrayRef Data) { + MD5 Hash; + Hash.update(Data); + MD5::MD5Result Res; + Hash.final(Res); + return {Res, Res + sizeof(Res)}; +} + } Index: lib/Support/SHA1.cpp =================================================================== --- lib/Support/SHA1.cpp +++ lib/Support/SHA1.cpp @@ -269,3 +269,11 @@ // Return pointer to hash (20 characters) return Hash; } + +std::vector SHA1::hash(ArrayRef Data) { + SHA1 Hash; + Hash.update(Data); + StringRef S = Hash.final().data(); + auto *P = reinterpret_cast(S.data()); + return {P, P + S.size()}; +}