Коммит 6c69a396 создал по автору Моисеенко Андрей Алексеевич's avatar Моисеенко Андрей Алексеевич
Просмотр файлов

~

владелец 49ecb013
......@@ -16,7 +16,7 @@
#define MAX_TRY_PATTERN 0x11111111
CAntiRobot::CAntiRobot(CMaaString fn, bool bThrow, int MaxCaptcheRequests, int RequestsPeriod, int MaxTriesNumber, int MaxCaptcheValidStore, int MaxRecords, int MaxCaptcheSuccessfulAccepts, int MaxCaptcheSuccessfulAcceptsPeriod)
: m_f(fn, "RWCD|SrSw", bThrow),
: m_f(fn, CMaaFile::eRWCD_SrSw, bThrow),
m_MaxTriesNumber(MaxTriesNumber <= -100 ? MAX_TRY_N : MaxTriesNumber),
m_Recs(m_MaxRecords = (MaxRecords >= 100 ? MaxRecords : 100), bThrow ? 1 : 0),
m_IsModified(0),
......@@ -94,7 +94,7 @@ int CAntiRobot::Set(ANTIROBOT_IP Ip, CMaaString &OutHash /*8+1 bytes*/, CMaaStri
break;
}
CMaaString Text = "This is a text";
CMaaString Text = CMaaStringRO("This is a text");
Text.Format("%d %c %d = ", rnd1, (char)QuestionType, rnd2);
GetRnd(&x, (int)sizeof(x));
......@@ -164,9 +164,9 @@ int CAntiRobot::GenerateHash(ANTIROBOT_IP Ip, CMaaString &OutHash, CMaaString *p
return Set(Ip, OutHash, pQuestion ? *pQuestion : Question, QuestionType);
}
int CAntiRobot::GetQuestion(ANTIROBOT_IP Ip, CMaaString Hash, CMaaString &Question)
int CAntiRobot::GetQuestion(ANTIROBOT_IP Ip, CMaaString Hash, CMaaString &Question) noexcept
{
_dword t = (_dword)time(nullptr);
const _dword t = (_dword)time(nullptr);
_dword t0 = 0;
int n = 0;
int nAcceptsCompleted = 0;
......@@ -181,15 +181,15 @@ int CAntiRobot::GetQuestion(ANTIROBOT_IP Ip, CMaaString Hash, CMaaString &Questi
{
nAcceptsCompleted++;
}
if (m_Recs[i].m_Ip == Ip && Hash == CMaaString(m_Recs[i].m_Hash, 8))
if (m_Recs[i].m_Ip == Ip && Hash == CMaaString(m_Recs[i].m_Hash, 8, CMaaString::eMemString))
{
if ((_sdword)(m_Recs[i].m_Time - t) > -m_MaxCaptcheValidStore && (_sdword)(m_Recs[i].m_Time - t) < m_MaxCaptcheValidStore && m_Recs[i].m_Tries < (_dword)m_MaxTriesNumber)
{
CMaaString Ops = "+-*/";
int QuestionType = m_Recs[i].m_Op;
CMaaString Ops = CMaaStringRO("+-*/");
const int QuestionType = m_Recs[i].m_Op;
if ((QuestionType & 0xff) == QuestionType && Ops.Find((char)QuestionType) >= 0)
{
CMaaString Text = "This is a text";
CMaaString Text = CMaaStringRO("This is a text");
Text.Format2("%d%c%d", "%1 %2 %3 = ", m_Recs[i].m_Arg1, (char)QuestionType, m_Recs[i].m_Arg2);
Question = Text;
return 1;
......@@ -232,7 +232,7 @@ int CAntiRobot::GetQuestion(ANTIROBOT_IP Ip, CMaaString Hash, CMaaString &Questi
}
if (n >= m_MaxCaptcheRequests && t0)
{
int s = (int)(m_RequestsPeriod - (int)(t - t0));
const int s = (int)(m_RequestsPeriod - (int)(t - t0));
if (s > 0)
{
CMaaString Text;
......@@ -269,7 +269,7 @@ int CAntiRobot::GetAnswer(ANTIROBOT_IP Ip, CMaaString Hash) // -1 on error
_dword g_Temp_dword______________________________________ = 1234567890;
_dword CAntiRobot::MaskInt(_dword x, _dword Mask) noexcept
{
_dword r = x & Mask;
const _dword r = x & Mask;
m_Temp = r + 12345678;
g_Temp_dword______________________________________ += m_Temp + 987654321;
return r;
......@@ -303,7 +303,7 @@ bool CAntiRobot::Check(ANTIROBOT_IP Ip, int Num, CMaaString Hash, CMaaString *pe
_dword Mask = 0;
while(1)
{
_dword NewMask = (Mask << 1) | 1;
const _dword NewMask = (Mask << 1) | 1;
if (NewMask == Mask)
{
Answer = m_Recs[i].m_Op == '+' ?
......
......@@ -36,7 +36,7 @@ public:
bool Check(ANTIROBOT_IP Ip, int Num, CMaaString Hash, CMaaString *pexterr = nullptr) noexcept;
bool Check(ANTIROBOT_IP Ip, CMaaString Reply, CMaaString Hash, CMaaString *pexterr = nullptr) noexcept;
int GenerateHash(ANTIROBOT_IP Ip, CMaaString &OutHash, CMaaString *pQuestion = nullptr, int QuestionType = '+');
int GetQuestion(ANTIROBOT_IP Ip, CMaaString Hash, CMaaString &Question);
int GetQuestion(ANTIROBOT_IP Ip, CMaaString Hash, CMaaString &Question) noexcept;
private:
protected:
_dword m_Temp;
......
......@@ -72,7 +72,7 @@
//CGostBsMaa gGostBsMaa;
void GostMain();
void GostMain() noexcept;
// GOST
//
......@@ -904,7 +904,7 @@ void CGostBsMaa::Hash(const void * Key, const void * InData, size_t Size, const
#endif
_dword n12[2] = { *(const _dword *)Salt, *((const _dword *)Salt + 1) };
unsigned char Sum = 0;
unsigned char * p = (unsigned char *)n12;
const unsigned char * p = (unsigned char *)n12;
size_t i, s3 = (Size >> 3);
for (i = 0; i < s3; i++)
......@@ -992,7 +992,7 @@ void CGostBsMaa::JoinHash(const void * Key, const void * Hash1, const void * Has
char * pData = HashSize <= 1024 ? __data_buffer : (char *)__Data;
memcpy(pData, Hash2, HashSize);
memcpy(HashSize + pData, Hash1, HashSize);
_qword _Salt = htonq(1);
const _qword _Salt = htonq(1);
Salt = Salt ? Salt : &_Salt;
OutSalt = OutSalt ? OutSalt : (void *)Salt;
//Encrypt(Key, pData, 2 * HashSize, Salt, pData, OutSalt);
......@@ -1006,7 +1006,7 @@ void CGostBsMaa::GenSalt(void *OutSalt) const
{
memset(OutSalt, 0, 8);
GetRnd(OutSalt, 8);
_dword _0[2] = {0, 0};
const _dword _0[2] = {0, 0};
if (!memcmp(OutSalt, _0, 8))
{
*(char *)OutSalt = 1;
......@@ -1134,7 +1134,7 @@ CMaaString CGostBsMaa::DecryptByPassword(CMaaString strPassword, CMaaString Data
{
bResult = false;
int DataLength = Data.Length() - 2 * sizeof(_qword);
const int DataLength = Data.Length() - 2 * sizeof(_qword);
if (DataLength >= 0)
{
char key[32];
......@@ -1487,7 +1487,7 @@ bool DecryptSFK2(CMaaString &ttt)
}
#endif
void GostMain()
void GostMain() noexcept
{
CGostBsMaa g;
_dword k[8];
......@@ -1495,9 +1495,9 @@ void GostMain()
for (i = 0; i < 8; i++) k[i] = i;
_dword Data[21], Data2[21], Data3[21];
for (i = 0; i < 21; i++) Data[i] = i;
_dword Salt[2] = {1, 2};
const _dword Salt[2] = {1, 2};
_dword Salt2[2];
size_t NN = 20 * sizeof(_dword);
const size_t NN = 20 * sizeof(_dword);
g.Encrypt(k, Data, NN / 2, Salt, Data2, Salt2);
g.Encrypt(k, Data + 10, NN / 2 + 4, Salt2, Data2 + 10, nullptr);
......@@ -1798,7 +1798,7 @@ static int test_gost_speed()
{
StaticKey[i] = i + 1;
}
int len = 100 * 1024 * 1024 - 1;
const int len = 100 * 1024 * 1024 - 1;
unsigned char* t1 = new unsigned char[len];
unsigned char* t2 = new unsigned char[len];
if (!t1 || !t2)
......@@ -1820,7 +1820,7 @@ static int test_gost_speed()
g.Encrypt(nullptr, t1, len, Salt1);
//g.Decrypt(nullptr, c1text, len, Salt1, o1text);
_qword u = tx.GetTime(1000000);
double x1 = (double)len / u * 1000000.0;
const double x1 = (double)len / u * 1000000.0;
printf("CGostBsMaa::Encrypt(): x1 = %.0lf B/s = %.2lf KB/s = %.3lf MB/s = %.3lf mbits/s\n", x1, x1 / 1024, x1 / 1024 / 1024, x1 * 8 / 1000000);
memset(t2, 123, len);
......@@ -1833,7 +1833,7 @@ static int test_gost_speed()
//GOST_Crypt_GF_Data(t2, len, (uint8_t*)Salt2, _GOST_Mode_Encrypt, Gost_Table_BS, StaticKey); // mismatch and slower
//g.Decrypt(nullptr, c1text, len, Salt1, o1text);
u = tx.GetTime(1000000);
double x2 = (double)len / u * 1000000.0;
const double x2 = (double)len / u * 1000000.0;
printf("CGostBsMaa_tst::Encrypt(): x2 = %.0lf B/s = %.2lf KB/s = %.3lf MB/s = %.3lf mbits/s\n", x2, x2 / 1024, x2 / 1024 / 1024, x2 * 8 / 1000000);
printf("x2/x1 = %.6lf, x1/x2 = %.6lf\n", x2 / x1, x1 / x2);
......
......@@ -286,7 +286,7 @@ void CMyExponent5::CreateR_2R ()
// B - второй множитель
// Result - результат
//------------------------------------------------------------------------------
void CMyExponent5::MonMul(const LongInt2 &A, LongInt2 &B, LongInt2 &Result, LongInt2 &WorkBuffer)
void CMyExponent5::MonMul(const LongInt2 &A, const LongInt2 &B, LongInt2 &Result, LongInt2 &WorkBuffer)
{
WorkBuffer.Mul(A, B);
......@@ -425,7 +425,7 @@ void pr(const char * txt, LongInt2 &x);
bool CMyExponent5::Exponent(const LongInt2 &A, const LongInt2 &X, LongInt2 &Y)
{
LongInt2 &P = *m_P;
const LongInt2 &P = *m_P;
// Test
/*
......
......@@ -85,7 +85,7 @@ public:
int m_TwoTab[256], m_OddTab[256];
unsigned char m_MulIndex[256];
void MonMul(const LongInt2 &A, LongInt2 &B, LongInt2 &Result, LongInt2 &WorkBuffer);
void MonMul(const LongInt2 &A, const LongInt2 &B, LongInt2 &Result, LongInt2 &WorkBuffer);
void MonSqr(const LongInt2 &A, LongInt2 &Result, LongInt2 &WorkBuffer);
void Reduce(LongInt2 &Result);
void CreateR_2R();
......
......@@ -562,8 +562,8 @@ LongInt2 & LongInt2::CalcRest(const LongInt2 & Dividend, const LongInt2 & Divide
LongInt2 & LongInt2::CalcRestEx(const LongInt2 & Dividend, const LongInt2 & Divider, LongInt2 ** pMulTable)
{
LONG_INT2_INC_STAT(m_RestEx);
int DividendSize = Dividend.GetSize(),
DividerSize = Divider.GetSize();
const int DividendSize = Dividend.GetSize();
const int DividerSize = Divider.GetSize();
// ( )
int RealDividerSize = Divider.GetRealSize();
......@@ -589,7 +589,7 @@ LongInt2 & LongInt2::CalcRestEx(const LongInt2 & Dividend, const LongInt2 & Divi
_dword x = rGet(Rest, i - 2) + (Rest.m_Number[i] << 16);
_dword y = rGet(Divider, RealDividerSize - 2);
_dword z = x / y;
_dword z0 = z;
const _dword z0 = z;
_sdword v = 0;
if (z > 0)
{
......@@ -610,7 +610,7 @@ LongInt2 & LongInt2::CalcRestEx(const LongInt2 & Dividend, const LongInt2 & Divi
v = 0;
for (int j = 0; j < RealDividerSize + 2; j += 2)
{
_dword m = rGet(Divider, j);
const _dword m = rGet(Divider, j);
v = (_sdword)rGet(Rest, i - RealDividerSize + j) + (_sdword)m + v;
rSet(Rest, i - RealDividerSize + j, (_dword)v);
v >>= 16;
......@@ -631,8 +631,8 @@ LongInt2 & LongInt2::CalcRestEx(const LongInt2 & Dividend, const LongInt2 & Divi
LongInt2 & LongInt2::Mul(const LongInt2 & Mul1, const LongInt2 & Mul2)
{
LONG_INT2_INC_STAT(m_Mul);
int Mul1Size = Mul1.GetRealSize();
int Mul2Size = Mul2.GetRealSize();
const int Mul1Size = Mul1.GetRealSize();
const int Mul2Size = Mul2.GetRealSize();
if ( Mul1Size == 0 || Mul2Size == 0 )
{
......@@ -641,14 +641,14 @@ LongInt2 & LongInt2::Mul(const LongInt2 & Mul1, const LongInt2 & Mul2)
}
#ifdef CRYPTLIB_USE_ASM64
_sdword Mul1SizeQw = (Mul1Size + 7) / 8;
_sdword Mul2SizeQw = (Mul2Size + 7) / 8; // modified in asm
const _sdword Mul1SizeQw = (Mul1Size + 7) / 8;
const _sdword Mul2SizeQw = (Mul2Size + 7) / 8; // modified in asm
if (m_TotalSize < 8 * (Mul1SizeQw + Mul2SizeQw + 1) || this == &Mul1 || this == &Mul2)
{
//
LongInt2 Product(8 * (Mul1SizeQw + Mul2SizeQw + 1));
Product.Mul(Mul1, Mul2);
int r = Product.GetRealSize();
const int r = Product.GetRealSize();
if (GetSize() < r)
{
Throw("Not enough size for multiplication result size");
......
......@@ -85,7 +85,7 @@ CCryptRandom::~CCryptRandom()
}
}
bool CCryptRandom::Get(void * ptr, int len)
bool CCryptRandom::Get(void * ptr, int len) // noexcept
{
#ifdef _WIN32
if (!m_hProv && !(m_Mode & eAllowRunTimeRandForStartingKey))
......
......@@ -106,7 +106,7 @@ public:
CNtlmProxyAuth::CNtlmProxyAuth(CMaaString HostName, CMaaString DomainName, CMaaString UserName, CMaaString Password)
{
memset(m_Nonce, 0, sizeof(m_Nonce));
int n = HostName.Find('.');
const int n = HostName.Find('.');
if (n >= 0)
{
HostName = HostName.Left(n);
......@@ -121,8 +121,26 @@ CNtlmProxyAuth::CNtlmProxyAuth(CMaaString HostName, CMaaString DomainName, CMaaS
CNtlmProxyAuth::~CNtlmProxyAuth()
{
memset(m_Nonce, 0, sizeof(m_Nonce));
m_UserName.Fill();
m_Password.Fill();
try
{
if (m_UserName.IsRWSingleOwner())
{
m_UserName.Fill();
}
}
catch (...)
{
}
try
{
if (m_Password.IsRWSingleOwner())
{
m_Password.Fill();
}
}
catch (...)
{
}
}
CMaaString CNtlmProxyAuth::GetType1Message(
......@@ -136,7 +154,7 @@ CMaaString CNtlmProxyAuth::GetType1Message(
memcpy(hdr.protocol, "NTLMSSP\0", 8);
hdr.type = 0x01;
hdr.flags = htons_le(0xb203);
int x = 0x20;
const int x = 0x20;
hdr.host_off = htons_le(x);
hdr.host_len1 = hdr.host_len2 = htons_le(m_HostName.Length());
hdr.dom_off = htons_le(x + m_HostName.Length());
......@@ -387,7 +405,7 @@ void CNtlmProxyAuth::calc_resp(unsigned char *keys, unsigned char *plaintext, un
des_ecb_encrypt((des_cblock*) plaintext, (des_cblock*) (results+16), ks, DES_ENCRYPT);
}
void CNtlmProxyAuth::setup_des_key(void * key_56_, des_key_schedule ks)
void CNtlmProxyAuth::setup_des_key(void * key_56_, des_key_schedule ks) noexcept
{
unsigned char * key_56 = (unsigned char *)key_56_;
/*
......
......@@ -83,12 +83,12 @@ protected:
//byte nt_resp[*]; // NT response
};
static _uword htons_le(_uword x) // storing LittleEndianWord
static _uword htons_le(_uword x) noexcept // storing LittleEndianWord
{
return x;
}
static _uword ntohs_le(_uword x) // reading LittleEndianWord
static _uword ntohs_le(_uword x) noexcept // reading LittleEndianWord
{
return x;
}
......@@ -124,7 +124,7 @@ protected:
//Helpers
static void calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results);
static void setup_des_key(void * key_56_, des_key_schedule ks);
static void setup_des_key(void * key_56_, des_key_schedule ks) noexcept;
};
......
......@@ -123,7 +123,7 @@ public:
int GetSeed(void * ptr, int size);
int FlushSeed(const void * ptr, int size);
virtual ~CCryptRandom();
bool Get(void * ptr, int len);
bool Get(void * ptr, int len); // noexcept
};
class CMyExponent2
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать