diff options
author | Jim Posen <jim.posen@gmail.com> | 2018-08-24 14:48:23 -0700 |
---|---|---|
committer | Jim Posen <jim.posen@gmail.com> | 2018-11-05 09:25:15 -0800 |
commit | 4fb789e9b2ffdf48fd50293b3982b3fce4d5fbdf (patch) | |
tree | 24f14fbfe6b2079e3dbc0952d72477431f679535 /src/crypto/siphash.h | |
parent | 6b8d0a2164b30eab76e7bccb1ffb056a10fba406 (diff) |
Extract CSipHasher to it's own file in crypto/ directory.
This is a move-only commit with the exception of changes to includes.
Diffstat (limited to 'src/crypto/siphash.h')
-rw-r--r-- | src/crypto/siphash.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/crypto/siphash.h b/src/crypto/siphash.h new file mode 100644 index 0000000000..b312f913f9 --- /dev/null +++ b/src/crypto/siphash.h @@ -0,0 +1,47 @@ +// Copyright (c) 2016-2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_CRYPTO_SIPHASH_H +#define BITCOIN_CRYPTO_SIPHASH_H + +#include <stdint.h> + +#include <uint256.h> + +/** SipHash-2-4 */ +class CSipHasher +{ +private: + uint64_t v[4]; + uint64_t tmp; + int count; + +public: + /** Construct a SipHash calculator initialized with 128-bit key (k0, k1) */ + CSipHasher(uint64_t k0, uint64_t k1); + /** Hash a 64-bit integer worth of data + * It is treated as if this was the little-endian interpretation of 8 bytes. + * This function can only be used when a multiple of 8 bytes have been written so far. + */ + CSipHasher& Write(uint64_t data); + /** Hash arbitrary bytes. */ + CSipHasher& Write(const unsigned char* data, size_t size); + /** Compute the 64-bit SipHash-2-4 of the data written so far. The object remains untouched. */ + uint64_t Finalize() const; +}; + +/** Optimized SipHash-2-4 implementation for uint256. + * + * It is identical to: + * SipHasher(k0, k1) + * .Write(val.GetUint64(0)) + * .Write(val.GetUint64(1)) + * .Write(val.GetUint64(2)) + * .Write(val.GetUint64(3)) + * .Finalize() + */ +uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256& val); +uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256& val, uint32_t extra); + +#endif // BITCOIN_CRYPTO_SIPHASH_H |