Commit 549e3dc5 authored by Alexey Golubev's avatar Alexey Golubev Committed by GitHub

Merge pull request #46 from ONLYOFFICE/feature/crypt

crypto fix padding size
parents 470eddf2 8440b182
...@@ -813,7 +813,7 @@ void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size) ...@@ -813,7 +813,7 @@ void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size)
cryptData.encryptedHmacKey = std::string((char*)pEncHmacKey.ptr, pEncHmacKey.size); cryptData.encryptedHmacKey = std::string((char*)pEncHmacKey.ptr, pEncHmacKey.size);
cryptData.encryptedHmacValue = std::string((char*)pEncHmacValue.ptr, pEncHmacValue.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) int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*& data_out_ptr)
{ {
data_out_ptr = NULL; data_out_ptr = NULL;
...@@ -823,10 +823,10 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char* ...@@ -823,10 +823,10 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
_buf empty (NULL, 0, false); _buf empty (NULL, 0, false);
int size_out = size; int size_out = size;
if (size_out % 8 != 0) if (size_out % PADDING_SIZE != 0)
size_out = (size_out / 8 + 1) * 8; 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; _UINT64 nSize = size;
memcpy(data_out_ptr, (unsigned char*)&nSize, 8); memcpy(data_out_ptr, (unsigned char*)&nSize, 8);
...@@ -878,8 +878,8 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char* ...@@ -878,8 +878,8 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
EncryptCipher(pDecryptedKey, iv, pInp, pOut, cryptData.cipherAlgorithm); EncryptCipher(pDecryptedKey, iv, pInp, pOut, cryptData.cipherAlgorithm);
if (sz % 8 != 0) if (sz % PADDING_SIZE != 0)
sz = (sz / 8 + 1) * 8; sz = (sz / PADDING_SIZE + 1) * PADDING_SIZE;
memcpy(data_out, pOut.ptr, sz); memcpy(data_out, pOut.ptr, sz);
...@@ -903,4 +903,4 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char* ...@@ -903,4 +903,4 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment