summaryrefslogtreecommitdiff
path: root/src/core/stdcrypt
diff options
context:
space:
mode:
authorGoraf <22941576+Goraf@users.noreply.github.com>2017-11-13 15:03:31 +0100
committerGoraf <22941576+Goraf@users.noreply.github.com>2017-11-13 15:07:33 +0100
commita7c24ca48995cf2bf436156302f96b91bf135409 (patch)
tree953835509ff1b778833e78fd7b74b05e05e77c84 /src/core/stdcrypt
parent591ec17b1c99db7f120c22ca9fb20ae05fe78325 (diff)
Code modernize ...
* replace 0/NULL with nullptr [using clang-tidy]
Diffstat (limited to 'src/core/stdcrypt')
-rw-r--r--src/core/stdcrypt/src/Rijndael.cpp2
-rw-r--r--src/core/stdcrypt/src/encrypt.cpp20
-rw-r--r--src/core/stdcrypt/src/utils.cpp8
3 files changed, 15 insertions, 15 deletions
diff --git a/src/core/stdcrypt/src/Rijndael.cpp b/src/core/stdcrypt/src/Rijndael.cpp
index 3392d5022c..510af48871 100644
--- a/src/core/stdcrypt/src/Rijndael.cpp
+++ b/src/core/stdcrypt/src/Rijndael.cpp
@@ -933,7 +933,7 @@ CRijndael::~CRijndael()
// blockSize - The block size in bytes of this Rijndael (16, 24 or 32 bytes).
int CRijndael::MakeKey(BYTE const* key, char const* chain, int keylength, int blockSize)
{
- if (NULL == key)
+ if (nullptr == key)
return 1;
if (!(16 == keylength || 24 == keylength || 32 == keylength))
return 2;
diff --git a/src/core/stdcrypt/src/encrypt.cpp b/src/core/stdcrypt/src/encrypt.cpp
index 1ca04f4782..3439772592 100644
--- a/src/core/stdcrypt/src/encrypt.cpp
+++ b/src/core/stdcrypt/src/encrypt.cpp
@@ -119,10 +119,10 @@ void CStdCrypt::setPassword(const char *pszPassword)
// result must be freed using mir_free or assigned to mir_ptr<BYTE>
BYTE* CStdCrypt::encodeString(const char *src, size_t *cbResultLen)
{
- if (!m_valid || src == NULL) {
+ if (!m_valid || src == nullptr) {
if (cbResultLen)
*cbResultLen = 0;
- return NULL;
+ return nullptr;
}
return encodeBuffer(src, mir_strlen(src)+1, cbResultLen);
@@ -133,8 +133,8 @@ BYTE* CStdCrypt::encodeBuffer(const void *src, size_t cbLen, size_t *cbResultLen
if (cbResultLen)
*cbResultLen = 0;
- if (!m_valid || src == NULL || cbLen >= 0xFFFE)
- return NULL;
+ if (!m_valid || src == nullptr || cbLen >= 0xFFFE)
+ return nullptr;
BYTE *tmpBuf = (BYTE*)_alloca(cbLen + 2);
*(PWORD)tmpBuf = (WORD)cbLen;
@@ -148,7 +148,7 @@ BYTE* CStdCrypt::encodeBuffer(const void *src, size_t cbLen, size_t *cbResultLen
m_aes.ResetChain();
if (m_aes.Encrypt(tmpBuf, LPSTR(result), cbLen)) {
mir_free(result);
- return NULL;
+ return nullptr;
}
if (cbResultLen)
@@ -163,7 +163,7 @@ char* CStdCrypt::decodeString(const BYTE *pBuf, size_t bufLen, size_t *cbResultL
if (result) {
if (result[resLen-1] != 0) { // smth went wrong
mir_free(result);
- return NULL;
+ return nullptr;
}
}
@@ -177,21 +177,21 @@ void* CStdCrypt::decodeBuffer(const BYTE *pBuf, size_t bufLen, size_t *cbResultL
if (cbResultLen)
*cbResultLen = 0;
- if (!m_valid || pBuf == NULL || (bufLen % BLOCK_SIZE) != 0)
- return NULL;
+ if (!m_valid || pBuf == nullptr || (bufLen % BLOCK_SIZE) != 0)
+ return nullptr;
char *result = (char*)mir_alloc(bufLen + 1);
m_aes.ResetChain();
if (m_aes.Decrypt(LPCSTR(pBuf), result, bufLen)) {
mir_free(result);
- return NULL;
+ return nullptr;
}
result[bufLen] = 0;
WORD cbLen = *(PWORD)result;
if (cbLen > bufLen) {
mir_free(result);
- return NULL;
+ return nullptr;
}
memmove(result, result + 2, cbLen);
diff --git a/src/core/stdcrypt/src/utils.cpp b/src/core/stdcrypt/src/utils.cpp
index c7bf59fbfd..27e641d1cd 100644
--- a/src/core/stdcrypt/src/utils.cpp
+++ b/src/core/stdcrypt/src/utils.cpp
@@ -27,9 +27,9 @@ bool getRandomBytes(BYTE *buf, size_t bufLen)
{
// try to use Intel hardware randomizer first
HCRYPTPROV hProvider = NULL;
- if (::CryptAcquireContext(&hProvider, NULL, L"Intel Hardware Cryptographic Service Provider", PROV_INTEL_SEC, 0) ||
- ::CryptAcquireContext(&hProvider, NULL, MS_STRONG_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) ||
- ::CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
+ if (::CryptAcquireContext(&hProvider, nullptr, L"Intel Hardware Cryptographic Service Provider", PROV_INTEL_SEC, 0) ||
+ ::CryptAcquireContext(&hProvider, nullptr, MS_STRONG_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) ||
+ ::CryptAcquireContext(&hProvider, nullptr, nullptr, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
::CryptGenRandom(hProvider, DWORD(bufLen), buf);
::CryptReleaseContext(hProvider, 0);
@@ -38,7 +38,7 @@ bool getRandomBytes(BYTE *buf, size_t bufLen)
else {
typedef BOOL(WINAPI *pfnGetRandom)(PVOID RandomBuffer, ULONG RandomBufferLength);
pfnGetRandom fnGetRandom = (pfnGetRandom)GetProcAddress(GetModuleHandleA("advapi32.dll"), "SystemFunction036");
- if (fnGetRandom == NULL)
+ if (fnGetRandom == nullptr)
return false;
fnGetRandom(buf, DWORD(bufLen));