/* * 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 2018 Danny Robson */ #pragma once #include #include #include namespace cruft::crypto::hash { // RFC7693: The BLAKE2 Cryptographic Hash and Message Authentication Code class blake2 { public: using salt_t = std::array; using digest_t = std::array; blake2 () noexcept; blake2 (const salt_t&) noexcept; blake2 (cruft::view key); digest_t operator() (cruft::view) const noexcept; private: using state_t = std::array; // we store zero padded salt because it simplifies later state // updates, not because it's a functional requirement. either way we // need to copy at least 64 bytes, so the user shouldn't be copying // these too much regardless. union { std::array val08; std::array val64; } m_salt; uint64_t m_keylen; }; };