1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 19:24:10 +01:00

[util] Provide method to compute SHA-1 hash from multiple data chunks

The underlying implementation supports this trivially, so we should
provide a way to use this feature.
This commit is contained in:
Philip Rebohle 2018-10-25 10:33:48 +02:00
parent 589229f4ca
commit 7eeeeaa625
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 26 additions and 6 deletions

View File

@ -21,13 +21,26 @@ namespace dxvk {
Sha1Hash Sha1Hash::compute(
const uint8_t* data,
const void* data,
size_t size) {
Sha1Data chunk = { data, size };
return compute(1, &chunk);
}
Sha1Hash Sha1Hash::compute(
size_t numChunks,
const Sha1Data* chunks) {
Sha1Digest digest;
SHA1_CTX ctx;
SHA1Init(&ctx);
SHA1Update(&ctx, data, size);
for (size_t i = 0; i < numChunks; i++) {
auto ptr = reinterpret_cast<const uint8_t*>(chunks[i].data);
SHA1Update(&ctx, ptr, chunks[i].size);
}
SHA1Final(digest.data(), &ctx);
return Sha1Hash(digest);
}

View File

@ -7,6 +7,11 @@
namespace dxvk {
using Sha1Digest = std::array<uint8_t, 20>;
struct Sha1Data {
const void* data;
size_t size;
};
class Sha1Hash {
@ -33,16 +38,18 @@ namespace dxvk {
}
static Sha1Hash compute(
const uint8_t* data,
const void* data,
size_t size);
static Sha1Hash compute(
size_t numChunks,
const Sha1Data* chunks);
template<typename T>
static Sha1Hash compute(const T& data) {
auto bytes = reinterpret_cast<const uint8_t*>(&data);
return compute(bytes, sizeof(T));
return compute(&data, sizeof(T));
}
private:
Sha1Digest m_digest;