/* * 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 */ #pragma once #include "../view.hpp" #include #include #include namespace cruft::hash { constexpr int SIPHASH_DEFAULT_COMPRESSIONS = 2; constexpr int SIPHASH_DEFAULT_FINALISATIONS = 4; template < int CompressionsV = SIPHASH_DEFAULT_COMPRESSIONS, int FinalisationsV = SIPHASH_DEFAULT_FINALISATIONS, int OutV = 8 > class siphash { public: static_assert (OutV == 8 or OutV == 16); static constexpr auto output_length = OutV; static constexpr auto compression_rounds = CompressionsV; static constexpr auto finalisation_rounds = FinalisationsV; using digest_t = std::array; siphash (std::array) noexcept; siphash (std::span) noexcept; digest_t operator() (cruft::view data) const noexcept; private: std::array m_key; }; template < int CompressionsV = SIPHASH_DEFAULT_COMPRESSIONS, int FinalisationsV = SIPHASH_DEFAULT_FINALISATIONS > using siphash64 = siphash; template < int CompressionsV = SIPHASH_DEFAULT_COMPRESSIONS, int FinalisationsV = SIPHASH_DEFAULT_FINALISATIONS > using siphash128 = siphash; }