hash/siphash: add support by byte array keys
This commit is contained in:
parent
ce2f05ede2
commit
b3f00b2f39
@ -43,6 +43,35 @@ round (uint64_t v[4])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
static
|
||||||
|
std::array<uint64_t, 2>
|
||||||
|
bytes_to_u64 (std::span<u08, 16> val)
|
||||||
|
{
|
||||||
|
u64 r0 =
|
||||||
|
u64 (val[0 + 0]) << u64 (0 * 8) |
|
||||||
|
u64 (val[0 + 1]) << u64 (1 * 8) |
|
||||||
|
u64 (val[0 + 2]) << u64 (2 * 8) |
|
||||||
|
u64 (val[0 + 3]) << u64 (3 * 8) |
|
||||||
|
u64 (val[0 + 4]) << u64 (4 * 8) |
|
||||||
|
u64 (val[0 + 5]) << u64 (5 * 8) |
|
||||||
|
u64 (val[0 + 6]) << u64 (6 * 8) |
|
||||||
|
u64 (val[0 + 7]) << u64 (7 * 8);
|
||||||
|
|
||||||
|
u64 r1 =
|
||||||
|
u64 (val[8 + 0]) << u64 (0 * 8) |
|
||||||
|
u64 (val[8 + 1]) << u64 (1 * 8) |
|
||||||
|
u64 (val[8 + 2]) << u64 (2 * 8) |
|
||||||
|
u64 (val[8 + 3]) << u64 (3 * 8) |
|
||||||
|
u64 (val[8 + 4]) << u64 (4 * 8) |
|
||||||
|
u64 (val[8 + 5]) << u64 (5 * 8) |
|
||||||
|
u64 (val[8 + 6]) << u64 (6 * 8) |
|
||||||
|
u64 (val[8 + 7]) << u64 (7 * 8);
|
||||||
|
|
||||||
|
return { r0, r1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
template <int C, int D>
|
template <int C, int D>
|
||||||
siphash<C,D>::siphash (std::array<uint64_t,2> _key) noexcept:
|
siphash<C,D>::siphash (std::array<uint64_t,2> _key) noexcept:
|
||||||
@ -52,6 +81,13 @@ siphash<C,D>::siphash (std::array<uint64_t,2> _key) noexcept:
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <int C, int D>
|
template <int C, int D>
|
||||||
|
siphash<C, D>::siphash (std::span<u08, 16> _key) noexcept
|
||||||
|
: siphash (bytes_to_u64 (_key))
|
||||||
|
{ ; }
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <int C, int D>
|
||||||
typename siphash<C,D>::digest_t
|
typename siphash<C,D>::digest_t
|
||||||
siphash<C,D>::operator() (cruft::view<const uint8_t*> data) const noexcept
|
siphash<C,D>::operator() (cruft::view<const uint8_t*> data) const noexcept
|
||||||
{
|
{
|
||||||
|
@ -3,16 +3,16 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*
|
*
|
||||||
* Copyright 2016-2018 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2016-2022 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CRUFT_UTIL_HASH_SIPHASH_HPP
|
#pragma once
|
||||||
#define CRUFT_UTIL_HASH_SIPHASH_HPP
|
|
||||||
|
|
||||||
#include "../view.hpp"
|
#include "../view.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
namespace cruft::hash {
|
namespace cruft::hash {
|
||||||
template <int CompressionsV = 2, int FinalisationsV = 4>
|
template <int CompressionsV = 2, int FinalisationsV = 4>
|
||||||
@ -24,12 +24,11 @@ namespace cruft::hash {
|
|||||||
static constexpr auto finalisation_rounds = FinalisationsV;
|
static constexpr auto finalisation_rounds = FinalisationsV;
|
||||||
|
|
||||||
siphash (std::array<uint64_t,2>) noexcept;
|
siphash (std::array<uint64_t,2>) noexcept;
|
||||||
|
siphash (std::span<u08, 16>) noexcept;
|
||||||
|
|
||||||
digest_t operator() (cruft::view<const std::uint8_t*> data) const noexcept;
|
digest_t operator() (cruft::view<const std::uint8_t*> data) const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<uint64_t,2> m_key;
|
std::array<uint64_t,2> m_key;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user