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
24template <typename Hash>
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
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
void Generate(uint8 *buf, uint32 sz)
Hash::Digest::const_iterator o0it
SessionKeyGenerator(C const &buf)