Skip to content

Commit 29e1a30

Browse files
committed
Add project.
Credit to @Chaosvex for reversing the logic.
1 parent 8944ebd commit 29e1a30

88 files changed

Lines changed: 39551 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Debug/libeay32.dll

1.27 MB
Binary file not shown.

LoginHashCalculator.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25123.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LoginHashCalculator", "LoginHashCalculator\LoginHashCalculator.vcxproj", "{CF529CF2-772B-4838-809B-7C8180AEA66F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{CF529CF2-772B-4838-809B-7C8180AEA66F}.Debug|x64.ActiveCfg = Debug|x64
17+
{CF529CF2-772B-4838-809B-7C8180AEA66F}.Debug|x64.Build.0 = Debug|x64
18+
{CF529CF2-772B-4838-809B-7C8180AEA66F}.Debug|x86.ActiveCfg = Debug|Win32
19+
{CF529CF2-772B-4838-809B-7C8180AEA66F}.Debug|x86.Build.0 = Debug|Win32
20+
{CF529CF2-772B-4838-809B-7C8180AEA66F}.Release|x64.ActiveCfg = Release|x64
21+
{CF529CF2-772B-4838-809B-7C8180AEA66F}.Release|x64.Build.0 = Release|x64
22+
{CF529CF2-772B-4838-809B-7C8180AEA66F}.Release|x86.ActiveCfg = Release|Win32
23+
{CF529CF2-772B-4838-809B-7C8180AEA66F}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

LoginHashCalculator/Common.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef _SHARED_DEFS_H
2+
#define _SHARED_DEFS_H
3+
4+
#include <cassert>
5+
#include <cstdint>
6+
#include <stdio.h>
7+
8+
#define ASSERT(a) assert(a)
9+
10+
typedef int64_t int64;
11+
typedef int32_t int32;
12+
typedef int16_t int16;
13+
typedef int8_t int8;
14+
15+
typedef uint64_t uint64;
16+
typedef uint32_t uint32;
17+
typedef uint16_t uint16;
18+
typedef uint8_t uint8;
19+
20+
#endif
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* Copyright (C) 2005-2012 MaNGOS <http://getmangos.com/>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
#include "BigNumber.h"
20+
#include <openssl/bn.h>
21+
#include <algorithm>
22+
23+
BigNumber::BigNumber()
24+
{
25+
_bn = BN_new();
26+
}
27+
28+
BigNumber::BigNumber(BigNumber const& bn)
29+
{
30+
_bn = BN_dup(bn._bn);
31+
}
32+
33+
BigNumber::BigNumber(uint32 val)
34+
{
35+
_bn = BN_new();
36+
BN_set_word(_bn, val);
37+
}
38+
39+
BigNumber::~BigNumber()
40+
{
41+
BN_free(_bn);
42+
}
43+
44+
void BigNumber::SetDword(uint32 val)
45+
{
46+
BN_set_word(_bn, val);
47+
}
48+
49+
void BigNumber::SetQword(uint64 val)
50+
{
51+
BN_add_word(_bn, (uint32)(val >> 32));
52+
BN_lshift(_bn, _bn, 32);
53+
BN_add_word(_bn, (uint32)(val & 0xFFFFFFFF));
54+
}
55+
56+
void BigNumber::SetBinary(uint8 const* bytes, int len)
57+
{
58+
uint8 t[1000];
59+
for (int i = 0; i < len; i++)
60+
t[i] = bytes[len - 1 - i];
61+
BN_bin2bn(t, len, _bn);
62+
}
63+
64+
void BigNumber::SetHexStr(char const* str)
65+
{
66+
BN_hex2bn(&_bn, str);
67+
}
68+
69+
void BigNumber::SetRand(int numbits)
70+
{
71+
BN_rand(_bn, numbits, 0, 1);
72+
}
73+
74+
BigNumber BigNumber::operator=(BigNumber const& bn)
75+
{
76+
BN_copy(_bn, bn._bn);
77+
return *this;
78+
}
79+
80+
BigNumber BigNumber::operator+=(BigNumber const& bn)
81+
{
82+
BN_add(_bn, _bn, bn._bn);
83+
return *this;
84+
}
85+
86+
BigNumber BigNumber::operator-=(BigNumber const& bn)
87+
{
88+
BN_sub(_bn, _bn, bn._bn);
89+
return *this;
90+
}
91+
92+
BigNumber BigNumber::operator*=(BigNumber const& bn)
93+
{
94+
BN_CTX *bnctx;
95+
96+
bnctx = BN_CTX_new();
97+
BN_mul(_bn, _bn, bn._bn, bnctx);
98+
BN_CTX_free(bnctx);
99+
100+
return *this;
101+
}
102+
103+
BigNumber BigNumber::operator/=(BigNumber const& bn)
104+
{
105+
BN_CTX *bnctx;
106+
107+
bnctx = BN_CTX_new();
108+
BN_div(_bn, nullptr, _bn, bn._bn, bnctx);
109+
BN_CTX_free(bnctx);
110+
111+
return *this;
112+
}
113+
114+
BigNumber BigNumber::operator%=(BigNumber const& bn)
115+
{
116+
BN_CTX *bnctx;
117+
118+
bnctx = BN_CTX_new();
119+
BN_mod(_bn, _bn, bn._bn, bnctx);
120+
BN_CTX_free(bnctx);
121+
122+
return *this;
123+
}
124+
125+
BigNumber BigNumber::Exp(BigNumber const& bn)
126+
{
127+
BigNumber ret;
128+
BN_CTX *bnctx;
129+
130+
bnctx = BN_CTX_new();
131+
BN_exp(ret._bn, _bn, bn._bn, bnctx);
132+
BN_CTX_free(bnctx);
133+
134+
return ret;
135+
}
136+
137+
BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2)
138+
{
139+
BigNumber ret;
140+
BN_CTX *bnctx;
141+
142+
bnctx = BN_CTX_new();
143+
BN_mod_exp(ret._bn, _bn, bn1._bn, bn2._bn, bnctx);
144+
BN_CTX_free(bnctx);
145+
146+
return ret;
147+
}
148+
149+
int BigNumber::GetNumBytes(void)
150+
{
151+
return BN_num_bytes(_bn);
152+
}
153+
154+
uint32 BigNumber::AsDword()
155+
{
156+
return (uint32)BN_get_word(_bn);
157+
}
158+
159+
bool BigNumber::isZero() const
160+
{
161+
return BN_is_zero(_bn)!=0;
162+
}
163+
164+
std::vector<uint8> BigNumber::AsByteArray(int minSize, bool reverse)
165+
{
166+
int length = (minSize >= GetNumBytes()) ? minSize : GetNumBytes();
167+
168+
std::vector<uint8> byteArray(length);
169+
170+
// If we need more bytes than length of BigNumber set the rest to 0
171+
if (length > GetNumBytes())
172+
memset((void*)byteArray.data(), 0, length);
173+
174+
// Padding should add leading zeroes, not trailing
175+
int paddingOffset = length - GetNumBytes();
176+
177+
BN_bn2bin(_bn, (unsigned char*)byteArray.data() + paddingOffset);
178+
179+
if (reverse)
180+
std::reverse(byteArray.begin(), byteArray.end());
181+
182+
183+
return byteArray;
184+
}
185+
186+
char const* BigNumber::AsHexStr()
187+
{
188+
return BN_bn2hex(_bn);
189+
}
190+
191+
char const* BigNumber::AsDecStr()
192+
{
193+
return BN_bn2dec(_bn);
194+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (C) 2005-2012 MaNGOS <http://getmangos.com/>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
#ifndef _AUTH_BIGNUMBER_H
20+
#define _AUTH_BIGNUMBER_H
21+
22+
#include "../Common.h"
23+
#include <memory>
24+
#include <vector>
25+
26+
struct bignum_st;
27+
28+
class BigNumber
29+
{
30+
public:
31+
BigNumber();
32+
BigNumber(BigNumber const& bn);
33+
BigNumber(uint32);
34+
~BigNumber();
35+
36+
void SetDword(uint32);
37+
void SetQword(uint64);
38+
void SetBinary(uint8 const* bytes, int len);
39+
void SetHexStr(char const* str);
40+
41+
void SetRand(int numbits);
42+
43+
BigNumber operator=(BigNumber const& bn);
44+
45+
BigNumber operator+=(BigNumber const& bn);
46+
BigNumber operator+(BigNumber const& bn)
47+
{
48+
BigNumber t(*this);
49+
return t += bn;
50+
}
51+
BigNumber operator-=(BigNumber const& bn);
52+
BigNumber operator-(BigNumber const& bn)
53+
{
54+
BigNumber t(*this);
55+
return t -= bn;
56+
}
57+
BigNumber operator*=(BigNumber const& bn);
58+
BigNumber operator*(BigNumber const& bn)
59+
{
60+
BigNumber t(*this);
61+
return t *= bn;
62+
}
63+
BigNumber operator/=(BigNumber const& bn);
64+
BigNumber operator/(BigNumber const& bn)
65+
{
66+
BigNumber t(*this);
67+
return t /= bn;
68+
}
69+
BigNumber operator%=(BigNumber const& bn);
70+
BigNumber operator%(BigNumber const& bn)
71+
{
72+
BigNumber t(*this);
73+
return t %= bn;
74+
}
75+
76+
bool isZero() const;
77+
78+
BigNumber ModExp(BigNumber const& bn1, BigNumber const& bn2);
79+
BigNumber Exp(BigNumber const&);
80+
81+
int GetNumBytes(void);
82+
83+
struct bignum_st* BN() { return _bn; }
84+
85+
uint32 AsDword();
86+
std::vector<uint8> AsByteArray(int minSize = 0, bool reverse = true);
87+
88+
char const* AsHexStr();
89+
char const* AsDecStr();
90+
91+
private:
92+
struct bignum_st* _bn;
93+
};
94+
#endif

0 commit comments

Comments
 (0)