TrinityCore
Loading...
Searching...
No Matches
RSA.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_RSA_H
19
#define TRINITYCORE_RSA_H
20
21
#include "
Define.h
"
22
#include <openssl/evp.h>
23
#include <array>
24
#include <memory>
25
#include <string>
26
#include <vector>
27
28
namespace
Trinity
29
{
30
namespace
Crypto
31
{
32
class
TC_COMMON_API
RsaSignature
33
{
34
public
:
35
class
TC_COMMON_API
DigestGenerator
36
{
37
public
:
38
struct
EVP_MD_Deleter
39
{
40
void
operator()(EVP_MD* md)
const
;
41
};
42
43
virtual
~DigestGenerator
() =
default
;
44
virtual
std::unique_ptr<EVP_MD, EVP_MD_Deleter>
GetGenerator
()
const
= 0;
45
46
virtual
OSSL_LIB_CTX*
GetLib
()
const
= 0;
47
virtual
std::unique_ptr<OSSL_PARAM[]>
GetParams
()
const
= 0;
48
};
49
50
class
TC_COMMON_API
SHA256
:
public
DigestGenerator
51
{
52
public
:
53
std::unique_ptr<EVP_MD, EVP_MD_Deleter> GetGenerator()
const override
;
54
55
OSSL_LIB_CTX* GetLib()
const override
;
56
std::unique_ptr<OSSL_PARAM[]> GetParams()
const override
;
57
};
58
59
class
TC_COMMON_API
HMAC_SHA256
:
public
DigestGenerator
60
{
61
public
:
62
explicit
HMAC_SHA256
(
uint8
const
* key,
size_t
keyLength) : _key(key), _keyLength(keyLength) { }
63
64
std::unique_ptr<EVP_MD, EVP_MD_Deleter> GetGenerator()
const override
;
65
66
OSSL_LIB_CTX* GetLib()
const override
;
67
std::unique_ptr<OSSL_PARAM[]> GetParams()
const override
;
68
69
private
:
70
uint8
const
*
_key
;
71
size_t
_keyLength
;
72
};
73
74
RsaSignature
();
75
RsaSignature
(
RsaSignature
const
& other);
76
RsaSignature
(
RsaSignature
&& other)
noexcept
;
77
~RsaSignature
();
78
79
RsaSignature
& operator=(
RsaSignature
const
& right);
80
RsaSignature
& operator=(
RsaSignature
&& right)
noexcept
;
81
82
bool
LoadKeyFromFile(std::string
const
& fileName);
83
84
bool
LoadKeyFromString(std::string
const
& keyPem);
85
86
template
<std::
size_t
N>
87
bool
Sign
(std::array<uint8, N>
const
& message,
DigestGenerator
& generator, std::vector<uint8>& output)
88
{
89
return
this->Sign(message.data(), message.size(), generator, output);
90
}
91
92
bool
Sign(
uint8
const
* message, std::size_t messageLength, DigestGenerator& generator, std::vector<uint8>& output);
93
94
private
:
95
EVP_MD_CTX* _ctx =
nullptr
;
96
EVP_PKEY* _key =
nullptr
;
97
};
98
}
99
}
100
101
#endif
// TRINITYCORE_RSA_H
Define.h
uint8
uint8_t uint8
Definition
Define.h:156
TC_COMMON_API
#define TC_COMMON_API
Definition
Define.h:99
Trinity::Crypto::RsaSignature::DigestGenerator
Definition
RSA.h:36
Trinity::Crypto::RsaSignature::DigestGenerator::GetParams
virtual std::unique_ptr< OSSL_PARAM[]> GetParams() const =0
Trinity::Crypto::RsaSignature::DigestGenerator::GetGenerator
virtual std::unique_ptr< EVP_MD, EVP_MD_Deleter > GetGenerator() const =0
Trinity::Crypto::RsaSignature::DigestGenerator::~DigestGenerator
virtual ~DigestGenerator()=default
Trinity::Crypto::RsaSignature::DigestGenerator::GetLib
virtual OSSL_LIB_CTX * GetLib() const =0
Trinity::Crypto::RsaSignature::HMAC_SHA256
Definition
RSA.h:60
Trinity::Crypto::RsaSignature::HMAC_SHA256::_key
uint8 const * _key
Definition
RSA.h:70
Trinity::Crypto::RsaSignature::HMAC_SHA256::_keyLength
size_t _keyLength
Definition
RSA.h:71
Trinity::Crypto::RsaSignature::HMAC_SHA256::HMAC_SHA256
HMAC_SHA256(uint8 const *key, size_t keyLength)
Definition
RSA.h:62
Trinity::Crypto::RsaSignature::SHA256
Definition
RSA.h:51
Trinity::Crypto::RsaSignature
Definition
RSA.h:33
Trinity::Crypto::RsaSignature::Sign
bool Sign(std::array< uint8, N > const &message, DigestGenerator &generator, std::vector< uint8 > &output)
Definition
RSA.h:87
Trinity
Definition
AsioHacksFwd.h:64
Trinity::Crypto::RsaSignature::DigestGenerator::EVP_MD_Deleter
Definition
RSA.h:39
common
Cryptography
RSA.h
Generated on Sun May 10 2026 02:08:51 for TrinityCore by
1.9.8