aboutsummaryrefslogtreecommitdiff
path: root/zencore/blake3.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-24 14:24:50 +0200
committerStefan Boberg <[email protected]>2021-05-24 14:24:50 +0200
commit84ce8f67868a7964f9f8fa8528f9f35f19afdb7e (patch)
treed944627d8ac856a7aec52039a9e147f697e6bd6c /zencore/blake3.cpp
parentInitial implementation of CompositeBuffer (diff)
downloadzen-84ce8f67868a7964f9f8fa8528f9f35f19afdb7e.tar.xz
zen-84ce8f67868a7964f9f8fa8528f9f35f19afdb7e.zip
Added BLAKE3::HashBuffer for hashing composite buffers
Diffstat (limited to 'zencore/blake3.cpp')
-rw-r--r--zencore/blake3.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/zencore/blake3.cpp b/zencore/blake3.cpp
index ec5d496d5..d8e0596d5 100644
--- a/zencore/blake3.cpp
+++ b/zencore/blake3.cpp
@@ -4,8 +4,9 @@
#include <zencore/string.h>
#include <zencore/zencore.h>
-#include "../3rdparty/BLAKE3/c/blake3.h"
+#include <zencore/compositebuffer.h>
+#include "../3rdparty/BLAKE3/c/blake3.h"
#pragma comment(lib, "blake3.lib")
#include <doctest/doctest.h>
@@ -35,6 +36,24 @@ BLAKE3::HashMemory(const void* data, size_t byteCount)
return b3;
}
+BLAKE3
+BLAKE3::HashBuffer(const CompositeBuffer& Buffer)
+{
+ BLAKE3 Hash;
+
+ blake3_hasher Hasher;
+ blake3_hasher_init(&Hasher);
+
+ for (const SharedBuffer& Segment : Buffer.GetSegments())
+ {
+ blake3_hasher_update(&Hasher, Segment.GetData(), Segment.GetSize());
+ }
+
+ blake3_hasher_finalize(&Hasher, Hash.Hash, sizeof Hash.Hash);
+
+ return Hash;
+}
+
BLAKE3
BLAKE3::FromHexString(const char* string)
{