mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-01 16:24:12 +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:
parent
589229f4ca
commit
7eeeeaa625
@ -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);
|
||||
}
|
||||
|
@ -8,6 +8,11 @@ namespace dxvk {
|
||||
|
||||
using Sha1Digest = std::array<uint8_t, 20>;
|
||||
|
||||
struct Sha1Data {
|
||||
const void* data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
class Sha1Hash {
|
||||
|
||||
public:
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user