Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
SessionKeyGenerator.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include <cstring>
7#include "CryptoHash.h"
8
9#ifndef _SESSIONKEYGENERATOR_HPP
10#define _SESSIONKEYGENERATOR_HPP
11
12template <typename Hash>
14{
15 public:
16 template <typename C>
17 SessionKeyGenerator(C const& buf) :
18 o0it(o0.begin())
19 {
20 uint8 const* data = std::data(buf);
21 size_t const len = std::size(buf);
22 size_t const halflen = (len / 2);
23
24 o1 = Hash::GetDigestOf(data, halflen);
25 o2 = Hash::GetDigestOf(data + halflen, len - halflen);
26 o0 = Hash::GetDigestOf(o1, o0, o2);
27 }
28
29 void Generate(uint8* buf, uint32 sz)
30 {
31 for (uint32 i = 0; i < sz; ++i)
32 {
33 if (o0it == o0.end())
34 {
35 o0 = Hash::GetDigestOf(o1, o0, o2);
36 o0it = o0.begin();
37 }
38
39 buf[i] = *(o0it++);
40 }
41 }
42
43 private:
44 typename Hash::Digest o0 = { };
45 typename Hash::Digest o1 = { };
46 typename Hash::Digest o2 = { };
47 typename Hash::Digest::const_iterator o0it;
48 };
49
50#endif
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
void Generate(uint8 *buf, uint32 sz)
Hash::Digest::const_iterator o0it
SessionKeyGenerator(C const &buf)