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

View File

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