1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef _AUTH_BIGNUMBER_H |
---|
22 | #define _AUTH_BIGNUMBER_H |
---|
23 | |
---|
24 | #include "Common.h" |
---|
25 | #include "ByteBuffer.h" |
---|
26 | |
---|
27 | struct bignum_st; |
---|
28 | |
---|
29 | class BigNumber |
---|
30 | { |
---|
31 | public: |
---|
32 | BigNumber(); |
---|
33 | BigNumber(const BigNumber &bn); |
---|
34 | BigNumber(uint32); |
---|
35 | ~BigNumber(); |
---|
36 | |
---|
37 | void SetDword(uint32); |
---|
38 | void SetQword(uint64); |
---|
39 | void SetBinary(const uint8 *bytes, int len); |
---|
40 | void SetHexStr(const char *str); |
---|
41 | |
---|
42 | void SetRand(int numbits); |
---|
43 | |
---|
44 | BigNumber operator=(const BigNumber &bn); |
---|
45 | |
---|
46 | BigNumber operator+=(const BigNumber &bn); |
---|
47 | BigNumber operator+(const BigNumber &bn) |
---|
48 | { |
---|
49 | BigNumber t(*this); |
---|
50 | return t += bn; |
---|
51 | } |
---|
52 | BigNumber operator-=(const BigNumber &bn); |
---|
53 | BigNumber operator-(const BigNumber &bn) |
---|
54 | { |
---|
55 | BigNumber t(*this); |
---|
56 | return t -= bn; |
---|
57 | } |
---|
58 | BigNumber operator*=(const BigNumber &bn); |
---|
59 | BigNumber operator*(const BigNumber &bn) |
---|
60 | { |
---|
61 | BigNumber t(*this); |
---|
62 | return t *= bn; |
---|
63 | } |
---|
64 | BigNumber operator/=(const BigNumber &bn); |
---|
65 | BigNumber operator/(const BigNumber &bn) |
---|
66 | { |
---|
67 | BigNumber t(*this); |
---|
68 | return t /= bn; |
---|
69 | } |
---|
70 | BigNumber operator%=(const BigNumber &bn); |
---|
71 | BigNumber operator%(const BigNumber &bn) |
---|
72 | { |
---|
73 | BigNumber t(*this); |
---|
74 | return t %= bn; |
---|
75 | } |
---|
76 | |
---|
77 | BigNumber ModExp(const BigNumber &bn1, const BigNumber &bn2); |
---|
78 | BigNumber Exp(const BigNumber &); |
---|
79 | |
---|
80 | int GetNumBytes(void); |
---|
81 | |
---|
82 | struct bignum_st *BN() { return _bn; } |
---|
83 | |
---|
84 | uint32 AsDword(); |
---|
85 | uint8* AsByteArray(int minSize = 0); |
---|
86 | ByteBuffer AsByteBuffer(); |
---|
87 | std::vector<uint8> AsByteVector(); |
---|
88 | |
---|
89 | const char *AsHexStr(); |
---|
90 | const char *AsDecStr(); |
---|
91 | |
---|
92 | private: |
---|
93 | struct bignum_st *_bn; |
---|
94 | uint8 *_array; |
---|
95 | }; |
---|
96 | #endif |
---|