libcruft-util/hash/siphash.hpp

34 lines
877 B
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*
* Copyright 2016-2022 Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include "../view.hpp"
#include <cstdint>
#include <type_traits>
#include <span>
namespace cruft::hash {
template <int CompressionsV = 2, int FinalisationsV = 4>
class siphash {
public:
using digest_t = u64;
static constexpr auto compression_rounds = CompressionsV;
static constexpr auto finalisation_rounds = FinalisationsV;
siphash (std::array<u64, 2>) noexcept;
siphash (std::span<u08, 16>) noexcept;
digest_t operator() (cruft::view<u08 const*> data) const noexcept;
private:
std::array<u64,2> m_key;
};
};