Skip to content
Snippets Groups Projects
Commit 889350dd authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Fix potential buffer overrun in AES_CTR functions

parent 0c1b84ed
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,8 @@ AES_CTR_256_Encrypt(const std::string plaintext, const BinaryBuf aes256Key, Bina
int ciphertext_len;
BinaryBuf encrypted = create_buffer(plaintext.size());
// The ciphertext expand up to block size, which is 128 for AES256
BinaryBuf encrypted = create_buffer(plaintext.size() + 128);
uint8_t *iv_data = iv.data();
// need to set bit 63 to 0
......@@ -67,6 +68,7 @@ AES_CTR_256_Encrypt(const std::string plaintext, const BinaryBuf aes256Key, Bina
}
ciphertext_len += len;
encrypted.resize(ciphertext_len);
/* Clean up */
EVP_CIPHER_CTX_free(ctx);
......@@ -118,6 +120,7 @@ AES_CTR_256_Decrypt(const std::string ciphertext, const BinaryBuf aes256Key, Bin
// handleErrors();
}
plaintext_len += len;
decrypted.resize(plaintext_len);
/* Clean up */
EVP_CIPHER_CTX_free(ctx);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment