aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-07-17 03:33:13 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-07-17 13:27:46 +0200
commit7d92b1430a6fd42c4438810640576830d0ff8d13 (patch)
tree32be45317bee88287fd0b2fa19af2e3b327395a5 /src/crypto
parent57b8336dfed6312003cf34cd5ae7099f77115e73 (diff)
downloadbitcoin-7d92b1430a6fd42c4438810640576830d0ff8d13.tar.xz
refactor: use Span for SipHash::Write
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/siphash.cpp7
-rw-r--r--src/crypto/siphash.h3
2 files changed, 6 insertions, 4 deletions
diff --git a/src/crypto/siphash.cpp b/src/crypto/siphash.cpp
index 2f7555d02e..2c328d0840 100644
--- a/src/crypto/siphash.cpp
+++ b/src/crypto/siphash.cpp
@@ -45,14 +45,14 @@ CSipHasher& CSipHasher::Write(uint64_t data)
return *this;
}
-CSipHasher& CSipHasher::Write(const unsigned char* data, size_t size)
+CSipHasher& CSipHasher::Write(Span<const unsigned char> data)
{
uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];
uint64_t t = tmp;
uint8_t c = count;
- while (size--) {
- t |= ((uint64_t)(*(data++))) << (8 * (c % 8));
+ while (data.size() > 0) {
+ t |= uint64_t{data.front()} << (8 * (c % 8));
c++;
if ((c & 7) == 0) {
v3 ^= t;
@@ -61,6 +61,7 @@ CSipHasher& CSipHasher::Write(const unsigned char* data, size_t size)
v0 ^= t;
t = 0;
}
+ data = data.subspan(1);
}
v[0] = v0;
diff --git a/src/crypto/siphash.h b/src/crypto/siphash.h
index b573526932..4fb3dc2f25 100644
--- a/src/crypto/siphash.h
+++ b/src/crypto/siphash.h
@@ -7,6 +7,7 @@
#include <stdint.h>
+#include <span.h>
#include <uint256.h>
/** SipHash-2-4 */
@@ -26,7 +27,7 @@ public:
*/
CSipHasher& Write(uint64_t data);
/** Hash arbitrary bytes. */
- CSipHasher& Write(const unsigned char* data, size_t size);
+ CSipHasher& Write(Span<const unsigned char> data);
/** Compute the 64-bit SipHash-2-4 of the data written so far. The object remains untouched. */
uint64_t Finalize() const;
};