Files
Library/tests/package/CryptoOnly/main.cpp

42 lines
977 B
C++

#include <Void/Crypto/Crypto.hpp>
#include <array>
#include <span>
int main()
{
auto digest = Void::Crypto::sha256("abc");
if (!digest.has_value() || digest->size() != 32) {
return 1;
}
auto b2 = Void::Crypto::blake2b256("abc");
if (!b2.has_value() || b2->size() != 32) {
return 6;
}
const std::array<std::byte, 4> msg{std::byte{1}, std::byte{2}, std::byte{3},
std::byte{4}};
auto mac = Void::Crypto::hmac_sha256(msg, msg);
if (!mac.has_value() || mac->size() != Void::Crypto::HmacSha256Size) {
return 7;
}
if (Void::Crypto::has_openssl_backend()) {
auto key = Void::Crypto::Ed25519PrivateKey::generate();
if (!key.has_value()) {
return 2;
}
auto pub = key->public_key();
if (!pub.has_value()) {
return 3;
}
auto sig = Void::Crypto::sign_ed25519(msg, *key);
if (!sig.has_value()) {
return 4;
}
auto ok = Void::Crypto::verify_ed25519(msg, *sig, *pub);
if (!ok.has_value() || !*ok) {
return 5;
}
}
return 0;
}