Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
crypto
siphash.h
Go to the documentation of this file.
1
// Copyright (c) 2016-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_CRYPTO_SIPHASH_H
6
#define BITCOIN_CRYPTO_SIPHASH_H
7
8
#include <array>
9
#include <cstdint>
10
#include <span>
11
12
class
uint256
;
13
15
class
SipHashState
16
{
17
static
constexpr
uint64_t
C0
{0x736f6d6570736575ULL},
C1
{0x646f72616e646f6dULL},
C2
{0x6c7967656e657261ULL},
C3
{0x7465646279746573ULL};
18
19
public
:
20
explicit
SipHashState
(uint64_t k0, uint64_t k1) noexcept :
v
{
C0
^ k0,
C1
^ k1,
C2
^ k0,
C3
^ k1} {}
21
22
std::array<uint64_t, 4>
v
{};
23
};
24
26
class
CSipHasher
27
{
28
SipHashState
m_state
;
29
uint64_t
m_tmp
{0};
30
uint8_t
m_count
{0};
31
32
public
:
34
CSipHasher
(uint64_t k0, uint64_t k1);
39
CSipHasher
&
Write
(uint64_t data);
41
CSipHasher
&
Write
(std::span<const unsigned char> data);
43
uint64_t
Finalize
()
const
;
44
};
45
55
class
PresaltedSipHasher
56
{
57
const
SipHashState
m_state
;
58
59
public
:
60
explicit
PresaltedSipHasher
(uint64_t k0, uint64_t k1) noexcept :
m_state
{k0, k1} {}
61
63
uint64_t
operator()
(
const
uint256& val)
const
noexcept
;
64
69
uint64_t
operator()
(
const
uint256& val, uint32_t extra)
const
noexcept
;
70
};
71
72
#endif
// BITCOIN_CRYPTO_SIPHASH_H
CSipHasher
General SipHash-2-4 implementation.
Definition
siphash.h:27
CSipHasher::m_count
uint8_t m_count
Only the low 8 bits of the input size matter.
Definition
siphash.h:30
CSipHasher::Finalize
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
Definition
siphash.cpp:73
CSipHasher::m_tmp
uint64_t m_tmp
Definition
siphash.h:29
CSipHasher::m_state
SipHashState m_state
Definition
siphash.h:28
CSipHasher::CSipHasher
CSipHasher(uint64_t k0, uint64_t k1)
Construct a SipHash calculator initialized with 128-bit key (k0, k1).
Definition
siphash.cpp:22
CSipHasher::Write
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data.
Definition
siphash.cpp:24
PresaltedSipHasher::operator()
uint64_t operator()(const uint256 &val) const noexcept
Equivalent to CSipHasher(k0, k1).Write(val).Finalize().
Definition
siphash.cpp:91
PresaltedSipHasher::PresaltedSipHasher
PresaltedSipHasher(uint64_t k0, uint64_t k1) noexcept
Definition
siphash.h:60
PresaltedSipHasher::m_state
const SipHashState m_state
Definition
siphash.h:57
SipHashState
Shared SipHash internal state v[0..3], initialized from (k0, k1).
Definition
siphash.h:16
SipHashState::C3
static constexpr uint64_t C3
Definition
siphash.h:17
SipHashState::v
std::array< uint64_t, 4 > v
Definition
siphash.h:22
SipHashState::C2
static constexpr uint64_t C2
Definition
siphash.h:17
SipHashState::C1
static constexpr uint64_t C1
Definition
siphash.h:17
SipHashState::SipHashState
SipHashState(uint64_t k0, uint64_t k1) noexcept
Definition
siphash.h:20
SipHashState::C0
static constexpr uint64_t C0
Definition
siphash.h:17
uint256
256-bit opaque blob.
Definition
uint256.h:195
Generated on
for Bitcoin Core by
1.17.0