Skip to content

Commit

Permalink
Use constant for additional buffer size used to decrypt/encrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Dec 11, 2021
1 parent ff7dc8d commit 98a1178
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions io/passwordfile.cpp
Expand Up @@ -28,7 +28,9 @@ using namespace CppUtilities;

namespace Io {

const unsigned int aes256cbcIvSize = 16U;
constexpr unsigned int aes256cbcIvSize = 16U;
constexpr unsigned int aes256blockSize = 32U;
constexpr unsigned int aes256additionalBufferSize = aes256blockSize * 2;

/*!
* \class PasswordFile
Expand Down Expand Up @@ -272,7 +274,7 @@ void PasswordFile::load()

// initiate ctx, decrypt data
EVP_CIPHER_CTX *ctx = nullptr;
decryptedData.resize(remainingSize + 32);
decryptedData.resize(remainingSize + aes256additionalBufferSize);
int outlen1, outlen2;
if ((ctx = EVP_CIPHER_CTX_new()) == nullptr || EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, password.data, iv) != 1
|| EVP_DecryptUpdate(ctx, reinterpret_cast<unsigned char *>(decryptedData.data()), &outlen1,
Expand Down Expand Up @@ -528,7 +530,7 @@ void PasswordFile::write(PasswordFileSaveFlags options)
EVP_CIPHER_CTX *ctx = nullptr;
unsigned char iv[aes256cbcIvSize];
int outlen1, outlen2;
encryptedData.resize(size + 32);
encryptedData.resize(size + aes256additionalBufferSize);
if (RAND_bytes(iv, aes256cbcIvSize) != 1 || (ctx = EVP_CIPHER_CTX_new()) == nullptr
|| EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, password.data, iv) != 1
|| EVP_EncryptUpdate(ctx, reinterpret_cast<unsigned char *>(encryptedData.data()), &outlen1,
Expand Down

0 comments on commit 98a1178

Please sign in to comment.