Skip to content

Commit 06dbbe7

Browse files
committed
Merge bitcoin#19931: Change CSipHasher's count variable to uint8_t
812037c Change CSipHasher's count variable to uint8_t (Pieter Wuille) Pull request description: SipHash technically supports arbitrarily long inputs (at least, I couldn't find a limit in the [paper](https://eprint.iacr.org/2012/351.pdf)), but only the low 8 bits of the length matter. Because of that we should use an unsigned type to track the length (as any signed type could overflow, which is UB). `uint8_t` is sufficient, however. Fixes bitcoin#19930. ACKs for top commit: laanwj: anyhow re-ACK 812037c elichai: utACK 812037c practicalswift: ACK 812037c theStack: ACK 812037c Tree-SHA512: 5b1440c9e4591460da198991fb421ad47d2d96def2014e761726ce361aa9575752f2c4085656e7e9badee3660ff005cc76fbd1afe4848faefe4502f3412bd896
2 parents ba4b3fb + 812037c commit 06dbbe7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Diff for: src/crypto/siphash.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ CSipHasher& CSipHasher::Write(const unsigned char* data, size_t size)
4949
{
5050
uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];
5151
uint64_t t = tmp;
52-
int c = count;
52+
uint8_t c = count;
5353

5454
while (size--) {
5555
t |= ((uint64_t)(*(data++))) << (8 * (c % 8));

Diff for: src/crypto/siphash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CSipHasher
1515
private:
1616
uint64_t v[4];
1717
uint64_t tmp;
18-
int count;
18+
uint8_t count; // Only the low 8 bits of the input size matter.
1919

2020
public:
2121
/** Construct a SipHash calculator initialized with 128-bit key (k0, k1) */

0 commit comments

Comments
 (0)