[PATCH] D128289: [lld/mac] Extract a sha256() function
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 21 11:03:06 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGca25baee7ecc: [lld/mac] Extract a sha256() function (authored by thakis).
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128289/new/
https://reviews.llvm.org/D128289
Files:
lld/MachO/SyntheticSections.cpp
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -43,6 +43,14 @@
using namespace lld;
using namespace lld::macho;
+// Reads `len` bytes at data and writes the 32-byte SHA256 checksum to `output`.
+static void sha256(const uint8_t *data, size_t len, uint8_t *output) {
+ ArrayRef<uint8_t> block(data, len);
+ std::array<uint8_t, 32> hash = SHA256::hash(block);
+ assert(hash.size() == CodeSignatureSection::hashSize);
+ memcpy(output, hash.data(), hash.size());
+}
+
InStruct macho::in;
std::vector<SyntheticSection *> macho::syntheticSections;
@@ -1239,13 +1247,8 @@
uint8_t *codeEnd = buf + fileOff;
uint8_t *hashes = codeEnd + allHeadersSize;
while (code < codeEnd) {
- StringRef block(reinterpret_cast<char *>(code),
- std::min(codeEnd - code, static_cast<ssize_t>(blockSize)));
- SHA256 hasher;
- hasher.update(block);
- std::array<uint8_t, 32> hash = hasher.final();
- assert(hash.size() == hashSize);
- memcpy(hashes, hash.data(), hashSize);
+ sha256(code, std::min(static_cast<size_t>(codeEnd - code), blockSize),
+ hashes);
code += blockSize;
hashes += hashSize;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128289.438765.patch
Type: text/x-patch
Size: 1290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220621/0e96f3ab/attachment.bin>
More information about the llvm-commits
mailing list