chore(Core/Authserver): restyle authserver library with astyle (#3464)
This commit is contained in:
@@ -26,27 +26,27 @@ int base32_decode(const char* encoded, char* result, int bufSize)
|
||||
int buffer = 0;
|
||||
int bitsLeft = 0;
|
||||
int count = 0;
|
||||
for (const char *ptr = encoded; count < bufSize && *ptr; ++ptr)
|
||||
for (const char* ptr = encoded; count < bufSize && *ptr; ++ptr)
|
||||
{
|
||||
char ch = *ptr;
|
||||
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-')
|
||||
continue;
|
||||
buffer <<= 5;
|
||||
// Deal with commonly mistyped characters
|
||||
// Deal with commonly mistyped characters
|
||||
if (ch == '0')
|
||||
ch = 'O';
|
||||
else if (ch == '1')
|
||||
ch = 'L';
|
||||
else if (ch == '8')
|
||||
ch = 'B';
|
||||
// Look up one base32 digit
|
||||
// Look up one base32 digit
|
||||
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
|
||||
ch = (ch & 0x1F) - 1;
|
||||
else if (ch >= '2' && ch <= '7')
|
||||
ch -= '2' - 26;
|
||||
else
|
||||
return -1;
|
||||
buffer |= ch;
|
||||
buffer |= ch;
|
||||
bitsLeft += 5;
|
||||
if (bitsLeft >= 8)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ int base32_decode(const char* encoded, char* result, int bufSize)
|
||||
bitsLeft -= 8;
|
||||
}
|
||||
}
|
||||
if (count < bufSize)
|
||||
if (count < bufSize)
|
||||
result[count] = '\000';
|
||||
return count;
|
||||
}
|
||||
@@ -66,21 +66,21 @@ namespace TOTP
|
||||
unsigned int GenerateToken(const char* b32key)
|
||||
{
|
||||
size_t keySize = strlen(b32key);
|
||||
int bufsize = (keySize + 7)/8*5;
|
||||
int bufsize = (keySize + 7) / 8 * 5;
|
||||
char* encoded = new char[bufsize];
|
||||
memset(encoded, 0, bufsize);
|
||||
unsigned int hmacResSize = HMAC_RES_SIZE;
|
||||
unsigned char hmacRes[HMAC_RES_SIZE];
|
||||
unsigned long timestamp = time(nullptr)/30;
|
||||
unsigned long timestamp = time(nullptr) / 30;
|
||||
unsigned char challenge[8];
|
||||
for (int i = 8; i--;timestamp >>= 8)
|
||||
for (int i = 8; i--; timestamp >>= 8)
|
||||
challenge[i] = timestamp;
|
||||
base32_decode(b32key, encoded, bufsize);
|
||||
base32_decode(b32key, encoded, bufsize);
|
||||
HMAC(EVP_sha1(), encoded, bufsize, challenge, 8, hmacRes, &hmacResSize);
|
||||
unsigned int offset = hmacRes[19] & 0xF;
|
||||
unsigned int truncHash = (hmacRes[offset] << 24) | (hmacRes[offset+1] << 16 )| (hmacRes[offset+2] << 8) | (hmacRes[offset+3]);
|
||||
unsigned int truncHash = (hmacRes[offset] << 24) | (hmacRes[offset + 1] << 16 ) | (hmacRes[offset + 2] << 8) | (hmacRes[offset + 3]);
|
||||
truncHash &= 0x7FFFFFFF;
|
||||
delete[] encoded;
|
||||
return truncHash % 1000000;
|
||||
delete[] encoded;
|
||||
return truncHash % 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user