navid/veins / 9b2d51ea7f41b1c7e81d779b3f7568ed0a5efba0594eedb262ee3511836c86cc / xveins/src/crypto.h
crypto.h
← xveins/src · 1150 bytes · raw · download
#pragma once
#include "common.h"
#include <array>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
namespace vn {
using PublicKey = std::array<std::uint8_t, 32>;
using Signature = std::array<std::uint8_t, 64>;
using FingerprintBytes = std::array<std::uint8_t, 16>;
std::optional<PublicKey> ed25519_public_from_seed(Bytes seed);
std::optional<Signature> ed25519_sign(Bytes seed, Bytes message);
bool ed25519_verify(const PublicKey& public_key, Bytes message, Bytes signature);
FingerprintBytes key_fingerprint_bytes(const PublicKey& public_key);
std::string key_fingerprint(const PublicKey& public_key);
// RFC 4648 base32 with no padding. The reference implementation emits
// fingerprints in uppercase, so this matches it.
std::string base32_text(Bytes raw);
// Unpadded base64url.
std::string base64url_encode(Bytes raw);
std::optional<std::vector<std::uint8_t>> base64url_decode(std::string_view text);
std::string format_public_key(const PublicKey& public_key);
std::optional<PublicKey> parse_public_key(std::string_view text);
std::vector<std::uint8_t> secure_random(std::size_t count);
} // namespace vn