Skip to content
Snippets Groups Projects
Commit 3e4a739d authored by Adrien Béraud's avatar Adrien Béraud
Browse files

crypto: check key size in aesEncrypt

parent fa0f1238
Branches
Tags
No related merge requests found
......@@ -79,9 +79,8 @@ static constexpr std::array<size_t, 3> AES_LENGTHS {{128/8, 192/8, 256/8}};
size_t aesKeySize(size_t max)
{
size_t aes_key_len = 0;
for (size_t s = 0; s < AES_LENGTHS.size(); s++) {
if (AES_LENGTHS[s] <= max)
aes_key_len = AES_LENGTHS[s];
for (size_t s : AES_LENGTHS) {
if (s <= max) aes_key_len = s;
else break;
}
return aes_key_len;
......@@ -102,6 +101,9 @@ bool aesKeySizeGood(size_t key_size)
Blob
aesEncrypt(const Blob& data, const Blob& key)
{
if (not aesKeySizeGood(key.size()))
throw DecryptError("Wrong key size");
Blob ret(data.size() + GCM_IV_SIZE + GCM_DIGEST_SIZE);
{
crypto::random_device rdev;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment