2018-01-22 19:51:16 +11:00
|
|
|
/*
|
2018-08-04 15:18:16 +10:00
|
|
|
* 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/.
|
2018-01-22 19:51:16 +11:00
|
|
|
*
|
|
|
|
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CRUFT_CRYPTO_HASH_BLAKE2_HPP
|
|
|
|
#define CRUFT_CRYPTO_HASH_BLAKE2_HPP
|
|
|
|
|
|
|
|
#include <cruft/util/view.hpp>
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
|
|
|
|
namespace cruft::crypto::hash {
|
|
|
|
// RFC7693: The BLAKE2 Cryptographic Hash and Message Authentication Code
|
|
|
|
class blake2 {
|
|
|
|
public:
|
|
|
|
using salt_t = std::array<uint8_t,64>;
|
|
|
|
using digest_t = std::array<uint8_t,64>;
|
|
|
|
|
|
|
|
blake2 () noexcept;
|
|
|
|
blake2 (const salt_t&) noexcept;
|
2018-08-05 14:51:17 +10:00
|
|
|
blake2 (cruft::view<const uint8_t*> key);
|
2018-01-22 19:51:16 +11:00
|
|
|
|
2018-08-05 14:51:17 +10:00
|
|
|
digest_t operator() (cruft::view<const uint8_t*>) const noexcept;
|
2018-01-22 19:51:16 +11:00
|
|
|
|
|
|
|
private:
|
|
|
|
using state_t = std::array<uint64_t,8>;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
std::array<uint8_t,128> m_salt;
|
|
|
|
uint64_t m_keylen;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|