1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 10:07:35 +00:00

LibCrypto: Remove all uses of VLAs

This removes all uses of VLAs with either Vectors with inline capacity
for the expected soft upper bound, or the occasional heap allocation.
This commit is contained in:
Ali Mohammad Pur 2021-05-13 12:13:11 +04:30 committed by Andreas Kling
parent 0d50d3ed1e
commit b05beb79d4
7 changed files with 41 additions and 36 deletions

View file

@ -25,7 +25,7 @@ public:
using HashType = HashT;
using TagType = typename HashType::DigestType;
size_t digest_size() const { return m_inner_hasher.digest_size(); }
constexpr size_t digest_size() const { return m_inner_hasher.digest_size(); }
template<typename KeyBufferType, typename... Args>
HMAC(KeyBufferType key, Args... args)
@ -82,9 +82,11 @@ private:
void derive_key(const u8* key, size_t length)
{
auto block_size = m_inner_hasher.block_size();
u8 v_key[block_size];
__builtin_memset(v_key, 0, block_size);
auto key_buffer = Bytes { v_key, block_size };
// Note: The block size of all the current hash functions is 512 bits.
Vector<u8, 64> v_key;
v_key.resize(block_size);
__builtin_memset(v_key.data(), 0, block_size);
auto key_buffer = v_key.span();
// m_key_data is zero'd, so copying the data in
// the first few bytes leaves the rest zero, which
// is exactly what we want (zero padding)