aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/SHA256.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/SHA256.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/SHA256.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/SHA256.cpp b/contrib/llvm-project/llvm/lib/Support/SHA256.cpp
index 3b81506847ec..81d897fb4187 100644
--- a/contrib/llvm-project/llvm/lib/Support/SHA256.cpp
+++ b/contrib/llvm-project/llvm/lib/Support/SHA256.cpp
@@ -243,7 +243,7 @@ void SHA256::pad() {
addUncounted(len);
}
-StringRef SHA256::final() {
+void SHA256::final(std::array<uint32_t, HASH_LENGTH / 4> &HashResult) {
// Pad to complete the last block
pad();
@@ -261,12 +261,19 @@ StringRef SHA256::final() {
(((InternalState.State[i]) >> 24) & 0x000000ff);
}
#endif
+}
- // Return pointer to hash (32 characters)
- return StringRef((char *)HashResult, HASH_LENGTH);
+std::array<uint8_t, 32> SHA256::final() {
+ union {
+ std::array<uint32_t, HASH_LENGTH / 4> HashResult;
+ std::array<uint8_t, HASH_LENGTH> ReturnResult;
+ };
+ static_assert(sizeof(HashResult) == sizeof(ReturnResult), "");
+ final(HashResult);
+ return ReturnResult;
}
-StringRef SHA256::result() {
+std::array<uint8_t, 32> SHA256::result() {
auto StateToRestore = InternalState;
auto Hash = final();
@@ -281,11 +288,7 @@ StringRef SHA256::result() {
std::array<uint8_t, 32> SHA256::hash(ArrayRef<uint8_t> Data) {
SHA256 Hash;
Hash.update(Data);
- StringRef S = Hash.final();
-
- std::array<uint8_t, 32> Arr;
- memcpy(Arr.data(), S.data(), S.size());
- return Arr;
+ return Hash.final();
}
} // namespace llvm