crypto: add fixed-width SipHash-1-3-UJ
What changed, and why it matters
This commit adds two new shortcut methods for computing a specific SipHash variant on fixed-size inputs. It is a pure performance/ergonomics addition: the new methods copy the hasher's internal state before operating, so they do not alter the original object. There is no indication of a security bug or fix.
No security action required. Review as normal code-quality/performance change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces SipHasher13UJ::Hash(const uint256&) and SipHasher13UJ::Hash(const uint256&, uint64_t) overloads in src/crypto/siphash.h. Both are marked ALWAYS_INLINE, work on a copy of m_state, call Compress1Jumbo (and optionally Compress1), then Finalize3U. The class comment is updated to note that these overloads optimize fixed-width inputs without modifying accumulated state. No algorithmic constants, SipRound logic, or output width are changed.
Changed components
src/crypto/siphash.hInspect captured patch +21 / −0
diff --git a/src/crypto/siphash.h b/src/crypto/siphash.h
index 0d17726c..f7b9e051 100644
--- a/src/crypto/siphash.h
+++ b/src/crypto/siphash.h
@@ -155,6 +155,7 @@ public:
*
* Other components are unchanged: initialization constants, SipRound, and 64-bit output.
* This interface serves as an executable specification for fixed-width implementations.
+ * The Hash overloads optimize fixed-width inputs without modifying the accumulated state.
*/
class SipHasher13UJ
{
@@ -169,6 +170,26 @@ public:
SipHasher13UJ& WriteJumbo(const uint256& hash) noexcept;
/** Compute the 64-bit SipHash-1-3-UJ of the data written so far. The object remains untouched. */
uint64_t Finalize() const noexcept;
+
+ /** Hash a jumbo block after the data written so far and finalize without modifying the object. */
+ ALWAYS_INLINE uint64_t Hash(const uint256& hash) const noexcept
+ {
+ return m_state.Copy()
+ .Compress1Jumbo(hash)
+ .Finalize3U();
+ }
+
+ /**
+ * Hash a jumbo block followed by a normal block after the data written so far,
+ * and finalize without modifying the object.
+ */
+ ALWAYS_INLINE uint64_t Hash(const uint256& hash, uint64_t extra) const noexcept
+ {
+ return m_state.Copy()
+ .Compress1Jumbo(hash)
+ .Compress1(extra)
+ .Finalize3U();
+ }
};
/**
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.