TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SessionKeyGeneration.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef SessionKeyGeneration_h__
20 #define SessionKeyGeneration_h__
21 
22 #include "Common.h"
23 
24 template<class Hash>
26 {
27 public:
29  {
30  uint32 halfSize = size / 2;
31 
32  sh.Initialize();
33  sh.UpdateData(buff, halfSize);
34  sh.Finalize();
35 
36  memcpy(o1, sh.GetDigest(), Hash::DigestLength::value);
37 
38  sh.Initialize();
39  sh.UpdateData(buff + halfSize, size - halfSize);
40  sh.Finalize();
41 
42  memcpy(o2, sh.GetDigest(), Hash::DigestLength::value);
43 
44  memset(o0, 0x00, Hash::DigestLength::value);
45 
46  FillUp();
47  }
48 
49  void Generate(uint8* buf, uint32 sz)
50  {
51  for (uint32 i = 0; i < sz; ++i)
52  {
54  FillUp();
55 
56  buf[i] = o0[taken];
57  taken++;
58  }
59  }
60 
61 private:
62  void FillUp()
63  {
64  sh.Initialize();
65  sh.UpdateData(o1, Hash::DigestLength::value);
66  sh.UpdateData(o0, Hash::DigestLength::value);
67  sh.UpdateData(o2, Hash::DigestLength::value);
68  sh.Finalize();
69 
70  memcpy(o0, sh.GetDigest(), Hash::DigestLength::value);
71 
72  taken = 0;
73  }
74 
75  Hash sh;
80 };
81 
82 #endif // SessionKeyGeneration_h__
uint8 o1[Hash::DigestLength::value]
Definition: SessionKeyGeneration.h:78
void Generate(uint8 *buf, uint32 sz)
Definition: SessionKeyGeneration.h:49
Hash sh
Definition: SessionKeyGeneration.h:75
Definition: SessionKeyGeneration.h:25
uint8 o0[Hash::DigestLength::value]
Definition: SessionKeyGeneration.h:77
uint32 taken
Definition: SessionKeyGeneration.h:76
uint32_t uint32
Definition: Define.h:150
uint8_t uint8
Definition: Define.h:152
void FillUp()
Definition: SessionKeyGeneration.h:62
const FieldDescriptor value
Definition: descriptor.h:1522
uint8 o2[Hash::DigestLength::value]
Definition: SessionKeyGeneration.h:79
SessionKeyGenerator(uint8 *buff, uint32 size)
Definition: SessionKeyGeneration.h:28