Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
SipHasher13UJ Class Reference

A custom weaker variant of SipHash-1-3 without padding, and supporting "jumbo" inputs. More...

#include <siphash.h>

Collaboration diagram for SipHasher13UJ:
[legend]

Public Member Functions

 SipHasher13UJ (uint64_t k0, uint64_t k1) noexcept
 Construct a SipHash-1-3-UJ calculator initialized with 128-bit key (k0, k1).
SipHasher13UJ & Write (uint64_t data) noexcept
 Hash a normal 64-bit value.
SipHasher13UJ & WriteJumbo (const uint256 &hash) noexcept
 Hash a 256-bit value as a jumbo block.
uint64_t Finalize () const noexcept
 Compute the 64-bit SipHash-1-3-UJ of the data written so far.
ALWAYS_INLINE uint64_t Hash (const uint256 &hash) 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, uint64_t extra) const noexcept
 Hash a jumbo block followed by a normal block after the data written so far, and finalize without modifying the object.

Private Attributes

SipHashState m_state

Detailed Description

A custom weaker variant of SipHash-1-3 without padding, and supporting "jumbo" inputs.

Compared to the traditional SipHash-2-4, this incorporates 3 changes:

  • Use SipHash-1-3: This common variant reduces the number of rounds between input blocks from 2 to 1, and the number of finalization rounds at the end from 4 to 3. It is a standard faster choice with weaker security guarantees. It is considered strong enough for use in hash tables and other applications with only weak security requirements, in particular when attackers cannot directly observe the hash function output, and cannot control k0 and k1.
  • Remove padding: Standard SipHash operates on byte-oriented inputs, which are converted into 8-byte blocks internally by adding a padding of 1-8 bytes to obtain a multiple of 8 bytes. In this variant, the input is a sequence of blocks instead, which are used without padding. This saves 1 round for inputs that are a multiple of 8 bytes already. The padding normally adds a commitment to the input's byte length, but since our input is block oriented, and there is one round per input, the function of that commitment is directly fulfilled by the number of rounds. The empty input is permitted; it yields the result of finalizing the initialization directly. Out of an abundance of caution the finalizing v2 ^= 0xff is changed to v2 ^= 0x6465646461706e75 ("unpadded" in LE64), to avoid collisions between standard SipHash-1-3 and this variant.
  • Jumbo blocks: We generalize the input to consist of a sequence of blocks which are each either exactly 8 bytes (normal blocks) or 32 bytes (jumbo blocks), and may be arbitrarily mixed. For hash-table use, cryptographic hash outputs must make up all but a small bounded number of retained jumbo blocks. Note that the block structure matters: hashing one jumbo block is not the same as hashing the same data split up into four normal blocks. Jumbo blocks are interpreted as 4 LE64 integers (d0,d1,d2,d3), and XOR'ed into the state before a round as (v0,v1,v2,v3) ^= (d1,d2,d3,d0), and XOR'ed into the state after a round as (v0,v1,v2,v3) ^= (d0,d1,d2,d3). This is a strict generalization of normal block processing, in the sense that if d1..d3=0, it is identical to processing a normal block d0 (a single LE64 integer). Of course, making d1..d3=0 should be impossible in the output of a cryptographic hash function. These jumbo blocks are acceptable because even though they may give the attacker more control within a single round, that control is limited by the cryptographic hash in between.

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.

Definition at line 160 of file siphash.h.

Constructor & Destructor Documentation

◆ SipHasher13UJ()

SipHasher13UJ::SipHasher13UJ ( uint64_t k0,
uint64_t k1 )
inlinenoexcept

Construct a SipHash-1-3-UJ calculator initialized with 128-bit key (k0, k1).

Definition at line 166 of file siphash.h.

Here is the caller graph for this function:

Member Function Documentation

◆ Finalize()

uint64_t SipHasher13UJ::Finalize ( ) const
noexcept

Compute the 64-bit SipHash-1-3-UJ of the data written so far.

The object remains untouched.

Definition at line 64 of file siphash.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Hash() [1/2]

ALWAYS_INLINE uint64_t SipHasher13UJ::Hash ( const uint256 & hash) const
inlinenoexcept

Hash a jumbo block after the data written so far and finalize without modifying the object.

Definition at line 175 of file siphash.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Hash() [2/2]

ALWAYS_INLINE uint64_t SipHasher13UJ::Hash ( const uint256 & hash,
uint64_t extra ) const
inlinenoexcept

Hash a jumbo block followed by a normal block after the data written so far, and finalize without modifying the object.

Definition at line 186 of file siphash.h.

Here is the call graph for this function:

◆ Write()

SipHasher13UJ & SipHasher13UJ::Write ( uint64_t data)
noexcept

Hash a normal 64-bit value.

Definition at line 52 of file siphash.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteJumbo()

SipHasher13UJ & SipHasher13UJ::WriteJumbo ( const uint256 & hash)
noexcept

Hash a 256-bit value as a jumbo block.

For hash-table use, non-hash inputs must remain few and bounded.

Definition at line 58 of file siphash.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_state

SipHashState SipHasher13UJ::m_state
private

Definition at line 162 of file siphash.h.


The documentation for this class was generated from the following files: