Files
TCPlayerbotCore/src/shared/Auth/BigNumber.h
T

97 lines
2.6 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#ifndef _AUTH_BIGNUMBER_H
#define _AUTH_BIGNUMBER_H
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Common.h"
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
struct bignum_st;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
class BigNumber
{
public:
BigNumber();
BigNumber(const BigNumber &bn);
BigNumber(uint32);
~BigNumber();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void SetDword(uint32);
void SetQword(uint64);
void SetBinary(const uint8 *bytes, int len);
void SetHexStr(const char *str);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void SetRand(int numbits);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
BigNumber operator=(const BigNumber &bn);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
BigNumber operator+=(const BigNumber &bn);
BigNumber operator+(const BigNumber &bn)
{
BigNumber t(*this);
return t += bn;
}
BigNumber operator-=(const BigNumber &bn);
BigNumber operator-(const BigNumber &bn)
{
BigNumber t(*this);
return t -= bn;
}
BigNumber operator*=(const BigNumber &bn);
BigNumber operator*(const BigNumber &bn)
{
BigNumber t(*this);
return t *= bn;
}
BigNumber operator/=(const BigNumber &bn);
BigNumber operator/(const BigNumber &bn)
{
BigNumber t(*this);
return t /= bn;
}
BigNumber operator%=(const BigNumber &bn);
BigNumber operator%(const BigNumber &bn)
{
BigNumber t(*this);
return t %= bn;
}
2009-10-17 15:51:44 -07:00
bool isZero() const;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
BigNumber ModExp(const BigNumber &bn1, const BigNumber &bn2);
BigNumber Exp(const BigNumber &);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
int GetNumBytes(void);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
struct bignum_st *BN() { return _bn; }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint32 AsDword();
uint8* AsByteArray(int minSize = 0);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
const char *AsHexStr();
const char *AsDecStr();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
private:
struct bignum_st *_bn;
uint8 *_array;
};
#endif
2009-02-17 20:07:49 -06:00