TrinityCore
Ed25519.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_ED25519_H
19#define TRINITYCORE_ED25519_H
20
21#include "Define.h"
22#include <array>
23#include <string>
24#include <vector>
25#include <openssl/evp.h>
26
27class BigNumber;
28
29namespace Trinity::Crypto
30{
32{
33public:
35 Ed25519(Ed25519 const& right);
36 Ed25519(Ed25519&& right) noexcept;
37 ~Ed25519();
38
39 Ed25519& operator=(Ed25519 const& right);
40 Ed25519& operator=(Ed25519&& right) noexcept;
41
42 bool LoadFromFile(std::string const& fileName);
43
44 bool LoadFromString(std::string const& keyPem);
45
46 bool LoadFromByteArray(std::array<uint8, 32> const& keyBytes);
47
48 template <std::size_t N>
49 bool Sign(std::array<uint8, N> const& message, std::vector<uint8>& output)
50 {
51 return this->Sign(message.data(), message.size(), output);
52 }
53
54 bool Sign(uint8 const* message, std::size_t messageLength, std::vector<uint8>& output);
55
56 template <std::size_t N>
57 bool SignWithContext(std::array<uint8, N> const& message, std::vector<uint8> const& context, std::vector<uint8>& output)
58 {
59 return this->SignWithContext(message.data(), message.size(), context, output);
60 }
61
62 bool SignWithContext(uint8 const* message, std::size_t messageLength, std::vector<uint8> const& context, std::vector<uint8>& output);
63
64private:
65 EVP_PKEY* _key = nullptr;
66};
67}
68
69#endif // TRINITYCORE_ED25519_H
uint8_t uint8
Definition: Define.h:144
#define TC_COMMON_API
Definition: Define.h:99
bool SignWithContext(std::array< uint8, N > const &message, std::vector< uint8 > const &context, std::vector< uint8 > &output)
Definition: Ed25519.h:57
bool Sign(std::array< uint8, N > const &message, std::vector< uint8 > &output)
Definition: Ed25519.h:49