refactor(Core/Common): restyle common lib with astyle (#3461)

This commit is contained in:
Kargatum
2020-09-12 03:50:48 +07:00
committed by GitHub
parent e15a493927
commit 3a0b0356ac
101 changed files with 4524 additions and 4418 deletions

View File

@@ -12,14 +12,14 @@
class ARC4
{
public:
ARC4(uint32 len);
ARC4(uint8* seed, uint32 len);
~ARC4();
void Init(uint8* seed);
void UpdateData(int len, uint8* data);
private:
EVP_CIPHER_CTX* m_ctx;
public:
ARC4(uint32 len);
ARC4(uint8* seed, uint32 len);
~ARC4();
void Init(uint8* seed);
void UpdateData(int len, uint8* data);
private:
EVP_CIPHER_CTX* m_ctx;
};
#endif

View File

@@ -17,11 +17,11 @@ void AuthCrypt::Init(BigNumber* K)
{
uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
uint8 *encryptHash = serverEncryptHmac.ComputeHash(K);
uint8* encryptHash = serverEncryptHmac.ComputeHash(K);
uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE };
HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);
uint8* decryptHash = clientDecryptHmac.ComputeHash(K);
//ARC4 _serverDecrypt(encryptHash);
_clientDecrypt.Init(decryptHash);
@@ -43,7 +43,7 @@ void AuthCrypt::Init(BigNumber* K)
_initialized = true;
}
void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
void AuthCrypt::DecryptRecv(uint8* data, size_t len)
{
if (!_initialized)
return;
@@ -51,7 +51,7 @@ void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
_clientDecrypt.UpdateData(len, data);
}
void AuthCrypt::EncryptSend(uint8 *data, size_t len)
void AuthCrypt::EncryptSend(uint8* data, size_t len)
{
if (!_initialized)
return;

View File

@@ -13,18 +13,18 @@ class BigNumber;
class AuthCrypt
{
public:
AuthCrypt();
public:
AuthCrypt();
void Init(BigNumber* K);
void DecryptRecv(uint8 *, size_t);
void EncryptSend(uint8 *, size_t);
void Init(BigNumber* K);
void DecryptRecv(uint8*, size_t);
void EncryptSend(uint8*, size_t);
bool IsInitialized() const { return _initialized; }
bool IsInitialized() const { return _initialized; }
private:
ARC4 _clientDecrypt;
ARC4 _serverEncrypt;
bool _initialized;
private:
ARC4 _clientDecrypt;
ARC4 _serverEncrypt;
bool _initialized;
};
#endif

View File

@@ -87,7 +87,7 @@ BigNumber BigNumber::operator-=(BigNumber const& bn)
BigNumber BigNumber::operator*=(BigNumber const& bn)
{
BN_CTX *bnctx;
BN_CTX* bnctx;
bnctx = BN_CTX_new();
BN_mul(_bn, _bn, bn._bn, bnctx);
@@ -98,7 +98,7 @@ BigNumber BigNumber::operator*=(BigNumber const& bn)
BigNumber BigNumber::operator/=(BigNumber const& bn)
{
BN_CTX *bnctx;
BN_CTX* bnctx;
bnctx = BN_CTX_new();
BN_div(_bn, NULL, _bn, bn._bn, bnctx);
@@ -109,7 +109,7 @@ BigNumber BigNumber::operator/=(BigNumber const& bn)
BigNumber BigNumber::operator%=(BigNumber const& bn)
{
BN_CTX *bnctx;
BN_CTX* bnctx;
bnctx = BN_CTX_new();
BN_mod(_bn, _bn, bn._bn, bnctx);
@@ -121,7 +121,7 @@ BigNumber BigNumber::operator%=(BigNumber const& bn)
BigNumber BigNumber::Exp(BigNumber const& bn)
{
BigNumber ret;
BN_CTX *bnctx;
BN_CTX* bnctx;
bnctx = BN_CTX_new();
BN_exp(ret._bn, _bn, bn._bn, bnctx);
@@ -133,7 +133,7 @@ BigNumber BigNumber::Exp(BigNumber const& bn)
BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2)
{
BigNumber ret;
BN_CTX *bnctx;
BN_CTX* bnctx;
bnctx = BN_CTX_new();
BN_mod_exp(ret._bn, _bn, bn1._bn, bn2._bn, bnctx);
@@ -178,12 +178,12 @@ std::unique_ptr<uint8[]> BigNumber::AsByteArray(int32 minSize, bool littleEndian
return ret;
}
char * BigNumber::AsHexStr() const
char* BigNumber::AsHexStr() const
{
return BN_bn2hex(_bn);
}
char * BigNumber::AsDecStr() const
char* BigNumber::AsDecStr() const
{
return BN_bn2dec(_bn);
}

View File

@@ -17,74 +17,74 @@ struct bignum_st;
class BigNumber
{
public:
BigNumber();
BigNumber(BigNumber const& bn);
BigNumber(uint32);
~BigNumber();
public:
BigNumber();
BigNumber(BigNumber const& bn);
BigNumber(uint32);
~BigNumber();
void SetDword(uint32);
void SetQword(uint64);
void SetBinary(uint8 const* bytes, int32 len);
void SetHexStr(char const* str);
void SetDword(uint32);
void SetQword(uint64);
void SetBinary(uint8 const* bytes, int32 len);
void SetHexStr(char const* str);
void SetRand(int32 numbits);
void SetRand(int32 numbits);
BigNumber& operator=(BigNumber const& bn);
BigNumber& operator=(BigNumber const& bn);
BigNumber operator+=(BigNumber const& bn);
BigNumber operator+(BigNumber const& bn)
{
BigNumber t(*this);
return t += bn;
}
BigNumber operator+=(BigNumber const& bn);
BigNumber operator+(BigNumber const& bn)
{
BigNumber t(*this);
return t += bn;
}
BigNumber operator-=(BigNumber const& bn);
BigNumber operator-(BigNumber const& bn)
{
BigNumber t(*this);
return t -= bn;
}
BigNumber operator-=(BigNumber const& bn);
BigNumber operator-(BigNumber const& bn)
{
BigNumber t(*this);
return t -= bn;
}
BigNumber operator*=(BigNumber const& bn);
BigNumber operator*(BigNumber const& bn)
{
BigNumber t(*this);
return t *= bn;
}
BigNumber operator*=(BigNumber const& bn);
BigNumber operator*(BigNumber const& bn)
{
BigNumber t(*this);
return t *= bn;
}
BigNumber operator/=(BigNumber const& bn);
BigNumber operator/(BigNumber const& bn)
{
BigNumber t(*this);
return t /= bn;
}
BigNumber operator/=(BigNumber const& bn);
BigNumber operator/(BigNumber const& bn)
{
BigNumber t(*this);
return t /= bn;
}
BigNumber operator%=(BigNumber const& bn);
BigNumber operator%(BigNumber const& bn)
{
BigNumber t(*this);
return t %= bn;
}
BigNumber operator%=(BigNumber const& bn);
BigNumber operator%(BigNumber const& bn)
{
BigNumber t(*this);
return t %= bn;
}
bool isZero() const;
bool isZero() const;
BigNumber ModExp(BigNumber const& bn1, BigNumber const& bn2);
BigNumber Exp(BigNumber const&);
BigNumber ModExp(BigNumber const& bn1, BigNumber const& bn2);
BigNumber Exp(BigNumber const&);
int32 GetNumBytes(void);
int32 GetNumBytes(void);
struct bignum_st *BN() { return _bn; }
struct bignum_st* BN() { return _bn; }
uint32 AsDword();
uint32 AsDword();
std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true);
std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true);
char * AsHexStr() const;
char * AsDecStr() const;
char* AsHexStr() const;
char* AsDecStr() const;
private:
struct bignum_st *_bn;
private:
struct bignum_st* _bn;
};
#endif

View File

@@ -12,7 +12,7 @@
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX* HMAC_CTX_new()
{
HMAC_CTX *ctx = new HMAC_CTX();
HMAC_CTX* ctx = new HMAC_CTX();
HMAC_CTX_init(ctx);
return ctx;
}

View File

@@ -18,18 +18,18 @@ class BigNumber;
class HmacHash
{
public:
HmacHash(uint32 len, uint8* seed);
~HmacHash();
void UpdateData(std::string const& str);
void UpdateData(uint8 const* data, size_t len);
void Finalize();
uint8* ComputeHash(BigNumber* bn);
uint8* GetDigest() { return m_digest; }
int GetLength() const { return SHA_DIGEST_LENGTH; }
private:
HMAC_CTX* m_ctx;
uint8 m_digest[SHA_DIGEST_LENGTH];
public:
HmacHash(uint32 len, uint8* seed);
~HmacHash();
void UpdateData(std::string const& str);
void UpdateData(uint8 const* data, size_t len);
void Finalize();
uint8* ComputeHash(BigNumber* bn);
uint8* GetDigest() { return m_digest; }
int GetLength() const { return SHA_DIGEST_LENGTH; }
private:
HMAC_CTX* m_ctx;
uint8 m_digest[SHA_DIGEST_LENGTH];
};
#endif

View File

@@ -19,7 +19,7 @@ static void lockingCallback(int mode, int type, char const* /*file*/, int /*line
else
cryptoLocks[type]->unlock();
}
static void threadIdCallback(CRYPTO_THREADID * id)
static void threadIdCallback(CRYPTO_THREADID* id)
{
(void)id;
CRYPTO_THREADID_set_numeric(id, std::hash<std::thread::id>()(std::this_thread::get_id()));

View File

@@ -19,12 +19,12 @@ SHA1Hash::~SHA1Hash()
SHA1_Init(&mC);
}
void SHA1Hash::UpdateData(const uint8 *dta, int len)
void SHA1Hash::UpdateData(const uint8* dta, int len)
{
SHA1_Update(&mC, dta, len);
}
void SHA1Hash::UpdateData(const std::string &str)
void SHA1Hash::UpdateData(const std::string& str)
{
UpdateData((uint8 const*)str.c_str(), str.length());
}

View File

@@ -15,24 +15,24 @@ class BigNumber;
class SHA1Hash
{
public:
SHA1Hash();
~SHA1Hash();
public:
SHA1Hash();
~SHA1Hash();
void UpdateBigNumbers(BigNumber* bn0, ...);
void UpdateBigNumbers(BigNumber* bn0, ...);
void UpdateData(const uint8 *dta, int len);
void UpdateData(const std::string &str);
void UpdateData(const uint8* dta, int len);
void UpdateData(const std::string& str);
void Initialize();
void Finalize();
void Initialize();
void Finalize();
uint8 *GetDigest(void) { return mDigest; };
int GetLength(void) const { return SHA_DIGEST_LENGTH; };
uint8* GetDigest(void) { return mDigest; };
int GetLength(void) const { return SHA_DIGEST_LENGTH; };
private:
SHA_CTX mC;
uint8 mDigest[SHA_DIGEST_LENGTH];
private:
SHA_CTX mC;
uint8 mDigest[SHA_DIGEST_LENGTH];
};
#endif

View File

@@ -14,7 +14,7 @@ class SHA1Randx
public:
SHA1Randx(uint8* buff, uint32 size)
{
uint32 taken = size/2;
uint32 taken = size / 2;
sh.Initialize();
sh.UpdateData(buff, taken);