hash/siphash: prefer short integer names

This commit is contained in:
Danny Robson 2022-07-21 15:44:07 +10:00
parent ea8d23bf17
commit 77071e3334
2 changed files with 14 additions and 14 deletions

View File

@ -17,7 +17,7 @@ using cruft::hash::siphash;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static constexpr static constexpr
uint64_t INITIALISERS[4] = { u64 INITIALISERS[4] = {
0x736f6d6570736575, 0x736f6d6570736575,
0x646f72616e646f6d, 0x646f72616e646f6d,
0x6c7967656e657261, 0x6c7967656e657261,
@ -27,7 +27,7 @@ uint64_t INITIALISERS[4] = {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static void static void
round (uint64_t v[4]) round (u64 v[4])
{ {
using cruft::rotatel; using cruft::rotatel;
@ -45,7 +45,7 @@ round (uint64_t v[4])
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static static
std::array<uint64_t, 2> std::array<u64, 2>
bytes_to_u64 (std::span<u08, 16> val) bytes_to_u64 (std::span<u08, 16> val)
{ {
u64 r0 = u64 r0 =
@ -74,7 +74,7 @@ bytes_to_u64 (std::span<u08, 16> val)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
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<u64,2> _key) noexcept:
m_key (_key) m_key (_key)
{ ; } { ; }
@ -89,10 +89,10 @@ siphash<C, D>::siphash (std::span<u08, 16> _key) noexcept
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <int C, int D> 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<u08 const*> data) const noexcept
{ {
// init // init
uint64_t state[4] = { u64 state[4] = {
m_key[0] ^ INITIALISERS[0], m_key[0] ^ INITIALISERS[0],
m_key[1] ^ INITIALISERS[1], m_key[1] ^ INITIALISERS[1],
m_key[0] ^ INITIALISERS[2], m_key[0] ^ INITIALISERS[2],
@ -101,8 +101,8 @@ siphash<C,D>::operator() (cruft::view<const uint8_t*> data) const noexcept
// update // update
auto cursor = data.begin (); auto cursor = data.begin ();
for ( ; data.end () - cursor >= 8; cursor += sizeof (uint64_t)) { for ( ; data.end () - cursor >= 8; cursor += sizeof (u64)) {
auto word = readle<uint64_t> (cursor); auto word = readle<u64> (cursor);
state[3] ^= word; state[3] ^= word;
for (int c = 0; c < C; ++c) for (int c = 0; c < C; ++c)
@ -112,8 +112,8 @@ siphash<C,D>::operator() (cruft::view<const uint8_t*> data) const noexcept
// drain // drain
union { union {
uint64_t d64 = 0; u64 d64 = 0;
uint8_t d08[8]; u08 d08[8];
} accum; } accum;
if (cursor != data.cend ()) { if (cursor != data.cend ()) {

View File

@ -18,17 +18,17 @@ namespace cruft::hash {
template <int CompressionsV = 2, int FinalisationsV = 4> template <int CompressionsV = 2, int FinalisationsV = 4>
class siphash { class siphash {
public: public:
using digest_t = std::uint64_t; using digest_t = u64;
static constexpr auto compression_rounds = CompressionsV; static constexpr auto compression_rounds = CompressionsV;
static constexpr auto finalisation_rounds = FinalisationsV; static constexpr auto finalisation_rounds = FinalisationsV;
siphash (std::array<uint64_t,2>) noexcept; siphash (std::array<u64, 2>) noexcept;
siphash (std::span<u08, 16>) noexcept; siphash (std::span<u08, 16>) noexcept;
digest_t operator() (cruft::view<const std::uint8_t*> data) const noexcept; digest_t operator() (cruft::view<u08 const*> data) const noexcept;
private: private:
std::array<uint64_t,2> m_key; std::array<u64,2> m_key;
}; };
}; };