2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2019-2022 The Bitcoin Core developers
|
2019-09-17 17:02:56 -04:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
2022-06-09 16:26:55 +01:00
|
|
|
#include <crypto/siphash.h>
|
2019-09-17 17:02:56 -04:00
|
|
|
#include <random.h>
|
2022-06-09 16:26:55 +01:00
|
|
|
#include <span.h>
|
2019-09-17 17:02:56 -04:00
|
|
|
#include <util/hasher.h>
|
|
|
|
|
|
2024-06-27 11:40:00 -04:00
|
|
|
SaltedTxidHasher::SaltedTxidHasher() :
|
|
|
|
|
k0{FastRandomContext().rand64()},
|
|
|
|
|
k1{FastRandomContext().rand64()} {}
|
2019-09-17 17:02:56 -04:00
|
|
|
|
2023-02-01 18:52:11 -05:00
|
|
|
SaltedOutpointHasher::SaltedOutpointHasher(bool deterministic) :
|
2024-06-27 11:40:00 -04:00
|
|
|
k0{deterministic ? 0x8e819f2607a18de6 : FastRandomContext().rand64()},
|
|
|
|
|
k1{deterministic ? 0xf4020d2e3983b0eb : FastRandomContext().rand64()}
|
2023-02-01 18:52:11 -05:00
|
|
|
{}
|
2019-09-17 19:29:59 -04:00
|
|
|
|
2024-06-27 11:40:00 -04:00
|
|
|
SaltedSipHasher::SaltedSipHasher() :
|
|
|
|
|
m_k0{FastRandomContext().rand64()},
|
|
|
|
|
m_k1{FastRandomContext().rand64()} {}
|
2019-09-17 19:29:59 -04:00
|
|
|
|
|
|
|
|
size_t SaltedSipHasher::operator()(const Span<const unsigned char>& script) const
|
|
|
|
|
{
|
2023-07-17 03:33:13 +02:00
|
|
|
return CSipHasher(m_k0, m_k1).Write(script).Finalize();
|
2019-09-17 19:29:59 -04:00
|
|
|
}
|