mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-02 01:24:11 +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(
|
Sha1Hash Sha1Hash::compute(
|
||||||
const uint8_t* data,
|
const void* data,
|
||||||
size_t size) {
|
size_t size) {
|
||||||
|
Sha1Data chunk = { data, size };
|
||||||
|
return compute(1, &chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Sha1Hash Sha1Hash::compute(
|
||||||
|
size_t numChunks,
|
||||||
|
const Sha1Data* chunks) {
|
||||||
Sha1Digest digest;
|
Sha1Digest digest;
|
||||||
|
|
||||||
SHA1_CTX ctx;
|
SHA1_CTX ctx;
|
||||||
SHA1Init(&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);
|
SHA1Final(digest.data(), &ctx);
|
||||||
return Sha1Hash(digest);
|
return Sha1Hash(digest);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,11 @@ namespace dxvk {
|
|||||||
|
|
||||||
using Sha1Digest = std::array<uint8_t, 20>;
|
using Sha1Digest = std::array<uint8_t, 20>;
|
||||||
|
|
||||||
|
struct Sha1Data {
|
||||||
|
const void* data;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
class Sha1Hash {
|
class Sha1Hash {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -33,16 +38,18 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Sha1Hash compute(
|
static Sha1Hash compute(
|
||||||
const uint8_t* data,
|
const void* data,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
|
static Sha1Hash compute(
|
||||||
|
size_t numChunks,
|
||||||
|
const Sha1Data* chunks);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static Sha1Hash compute(const T& data) {
|
static Sha1Hash compute(const T& data) {
|
||||||
auto bytes = reinterpret_cast<const uint8_t*>(&data);
|
return compute(&data, sizeof(T));
|
||||||
return compute(bytes, sizeof(T));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Sha1Digest m_digest;
|
Sha1Digest m_digest;
|
||||||
|
Loading…
Reference in New Issue
Block a user