Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/backends/nntpchan-daemon/libnntpchan/crypto.cpp

24 lines
632 B
C++
Raw Normal View History

2017-10-17 19:29:56 +05:00
#include <cassert>
2017-10-24 17:51:21 +05:00
#include <nntpchan/base64.hpp>
2017-10-11 18:48:27 +05:00
#include <nntpchan/crypto.hpp>
2017-05-03 20:37:09 +05:00
#include <sodium.h>
2016-10-15 21:37:59 +05:00
namespace nntpchan
{
2017-10-17 19:29:56 +05:00
void SHA512(const uint8_t *d, const std::size_t l, SHA512Digest &h) { crypto_hash(h.data(), d, l); }
2017-05-03 20:37:09 +05:00
2017-10-24 17:51:21 +05:00
void Blake2B(const uint8_t *d, std::size_t l, Blake2BDigest & h) { crypto_generichash(h.data(), h.size(), d, l, nullptr, 0); }
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-17 19:29:56 +05:00
Crypto::Crypto() { assert(sodium_init() == 0); }
2017-05-03 20:37:09 +05:00
2017-10-17 19:29:56 +05:00
Crypto::~Crypto() {}
2016-10-15 21:37:59 +05:00
}