2017-10-17 10:29:56 -04:00
|
|
|
#include <cassert>
|
2017-10-24 08:51:21 -04:00
|
|
|
#include <nntpchan/base64.hpp>
|
2017-10-11 09:48:27 -04:00
|
|
|
#include <nntpchan/crypto.hpp>
|
2017-05-03 11:37:09 -04:00
|
|
|
#include <sodium.h>
|
2016-10-15 12:37:59 -04:00
|
|
|
|
|
|
|
|
namespace nntpchan
|
|
|
|
|
{
|
2017-10-17 10:29:56 -04:00
|
|
|
void SHA512(const uint8_t *d, const std::size_t l, SHA512Digest &h) { crypto_hash(h.data(), d, l); }
|
2017-05-03 11:37:09 -04:00
|
|
|
|
2018-05-06 08:10:20 -04:00
|
|
|
void Blake2B(const uint8_t *d, std::size_t l, Blake2BDigest &h)
|
|
|
|
|
{
|
|
|
|
|
crypto_generichash(h.data(), h.size(), d, l, nullptr, 0);
|
|
|
|
|
}
|
2017-10-24 08:51:21 -04:00
|
|
|
|
2018-05-06 08:10:20 -04:00
|
|
|
std::string Blake2B_base32(const std::string &str)
|
|
|
|
|
{
|
|
|
|
|
Blake2BDigest d;
|
|
|
|
|
Blake2B(reinterpret_cast<const uint8_t *>(str.c_str()), str.size(), d);
|
|
|
|
|
return B32Encode(d.data(), d.size());
|
|
|
|
|
}
|
2017-10-24 08:51:21 -04:00
|
|
|
|
2017-10-17 10:29:56 -04:00
|
|
|
Crypto::Crypto() { assert(sodium_init() == 0); }
|
2017-05-03 11:37:09 -04:00
|
|
|
|
2017-10-17 10:29:56 -04:00
|
|
|
Crypto::~Crypto() {}
|
2016-10-15 12:37:59 -04:00
|
|
|
}
|