TrinityCore
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 "CryptoHash.h"
22
23template <typename Hash>
25{
26 public:
27 template <typename C>
28 SessionKeyGenerator(C const& buf) :
29 o0it(o0.begin())
30 {
31 uint8 const* data = std::data(buf);
32 size_t const len = std::size(buf);
33 size_t const halflen = (len / 2);
34
35 o1 = Hash::GetDigestOf(data, halflen);
36 o2 = Hash::GetDigestOf(data + halflen, len - halflen);
37 o0 = Hash::GetDigestOf(o1, o0, o2);
38 }
39
40 void Generate(uint8* buf, uint32 sz)
41 {
42 for (uint32 i = 0; i < sz; ++i)
43 {
44 if (o0it == o0.end())
45 {
46 o0 = Hash::GetDigestOf(o1, o0, o2);
47 o0it = o0.begin();
48 }
49
50 buf[i] = *(o0it++);
51 }
52 }
53
54 private:
55 typename Hash::Digest o0 = { };
56 typename Hash::Digest o1 = { };
57 typename Hash::Digest o2 = { };
58 typename Hash::Digest::const_iterator o0it;
59 };
60
61#endif
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
void Generate(uint8 *buf, uint32 sz)
Hash::Digest::const_iterator o0it
SessionKeyGenerator(C const &buf)
constexpr std::size_t size()
Definition: UpdateField.h:796