Compare commits

...

2 Commits

Author SHA1 Message Date
9272b27a69 crypto fix padding size 2017-10-16 19:37:18 +03:00
ef57330a79 . 2017-10-16 19:20:28 +03:00
2 changed files with 7 additions and 7 deletions

View File

@ -219,7 +219,7 @@ public:
HCRYPTPROV hCryptProv = NULL;
bResult = CryptAcquireCertificatePrivateKey(m_context, 0, NULL, &hCryptProv, &dwKeySpec, NULL);
bResult = (NULL != m_context) ? CryptAcquireCertificatePrivateKey(m_context, 0, NULL, &hCryptProv, &dwKeySpec, NULL) : FALSE;
if (!bResult)
bResult = CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);

View File

@ -821,7 +821,7 @@ void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size)
cryptData.encryptedHmacKey = std::string((char*)pEncHmacKey.ptr, pEncHmacKey.size);
cryptData.encryptedHmacValue = std::string((char*)pEncHmacValue.ptr, pEncHmacValue.size);
}
#define PADDING_SIZE 16 // 8
int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*& data_out_ptr)
{
data_out_ptr = NULL;
@ -831,10 +831,10 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
_buf empty (NULL, 0, false);
int size_out = size;
if (size_out % 8 != 0)
size_out = (size_out / 8 + 1) * 8;
if (size_out % PADDING_SIZE != 0)
size_out = (size_out / PADDING_SIZE + 1) * PADDING_SIZE;
data_out_ptr = new unsigned char[size_out + 8]; // real size + padding + size for realsize
data_out_ptr = new unsigned char[size_out + PADDING_SIZE]; // real size + padding + size for realsize
_UINT64 nSize = size;
memcpy(data_out_ptr, (unsigned char*)&nSize, 8);
@ -886,8 +886,8 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
EncryptCipher(pDecryptedKey, iv, pInp, pOut, cryptData.cipherAlgorithm);
if (sz % 8 != 0)
sz = (sz / 8 + 1) * 8;
if (sz % PADDING_SIZE != 0)
sz = (sz / PADDING_SIZE + 1) * PADDING_SIZE;
memcpy(data_out, pOut.ptr, sz);