TrinityCore
Loading...
Searching...
No Matches
SessionKeyGenerator.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 TRINITY_SESSIONKEYGENERATOR_HPP
19
#define TRINITY_SESSIONKEYGENERATOR_HPP
20
21
#include <cstring>
22
#include "
CryptoHash.h
"
23
24
template
<
typename
Hash>
25
class
SessionKeyGenerator
26
{
27
public
:
28
template
<
typename
C>
29
SessionKeyGenerator
(C
const
& buf) :
30
o0it
(
o0
.begin())
31
{
32
uint8
const
* data = std::data(buf);
33
size_t
const
len = std::size(buf);
34
size_t
const
halflen = (len / 2);
35
36
o1
= Hash::GetDigestOf(data, halflen);
37
o2
= Hash::GetDigestOf(data + halflen, len - halflen);
38
o0
= Hash::GetDigestOf(
o1
,
o0
,
o2
);
39
}
40
41
void
Generate
(
uint8
* buf,
uint32
sz)
42
{
43
for
(
uint32
i = 0; i < sz; ++i)
44
{
45
if
(
o0it
==
o0
.end())
46
{
47
o0
= Hash::GetDigestOf(
o1
,
o0
,
o2
);
48
o0it
=
o0
.begin();
49
}
50
51
buf[i] = *(
o0it
++);
52
}
53
}
54
55
private
:
56
typename
Hash::Digest
o0
= { };
57
typename
Hash::Digest
o1
= { };
58
typename
Hash::Digest
o2
= { };
59
typename
Hash::Digest::const_iterator
o0it
;
60
};
61
62
#endif
CryptoHash.h
uint8
uint8_t uint8
Definition
Define.h:135
uint32
uint32_t uint32
Definition
Define.h:133
SessionKeyGenerator
Definition
SessionKeyGenerator.h:26
SessionKeyGenerator::o0
Hash::Digest o0
Definition
SessionKeyGenerator.h:56
SessionKeyGenerator::Generate
void Generate(uint8 *buf, uint32 sz)
Definition
SessionKeyGenerator.h:41
SessionKeyGenerator::o1
Hash::Digest o1
Definition
SessionKeyGenerator.h:57
SessionKeyGenerator::o2
Hash::Digest o2
Definition
SessionKeyGenerator.h:58
SessionKeyGenerator::o0it
Hash::Digest::const_iterator o0it
Definition
SessionKeyGenerator.h:59
SessionKeyGenerator::SessionKeyGenerator
SessionKeyGenerator(C const &buf)
Definition
SessionKeyGenerator.h:29
common
Cryptography
SessionKeyGenerator.h
Generated on Sun May 10 2026 02:30:12 for TrinityCore by
1.9.8