1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:07:36 +00:00

LibCrypto: Fix issues in the Crypto stack

This commit fixes up the following:
- HMAC should not reuse a single hasher when successively updating
- AES Key should not assume its user key is valid signed char*
- Mode should have a virtual destructor
And adds a RFC5246 padding mode, which is required for TLS
This commit is contained in:
AnotherTest 2020-04-29 19:17:47 +04:30 committed by Andreas Kling
parent 7adb93ede9
commit f1578d7e9e
10 changed files with 93 additions and 49 deletions

View file

@ -51,6 +51,8 @@ namespace Hash {
virtual DigestType peek() = 0;
virtual DigestType digest() = 0;
virtual void reset() = 0;
virtual String class_name() const = 0;
};
}

View file

@ -220,18 +220,5 @@ namespace Hash {
__builtin_memset(x, 0, sizeof(x));
}
void MD5::reset()
{
m_A = MD5Constants::init_A;
m_B = MD5Constants::init_B;
m_C = MD5Constants::init_C;
m_D = MD5Constants::init_D;
m_count[0] = 0;
m_count[1] = 0;
__builtin_memset(m_data_buffer, 0, sizeof(m_data_buffer));
}
}
}

View file

@ -92,10 +92,21 @@ namespace Hash {
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
inline static DigestType hash(const StringView& buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
inline virtual void reset() override
{
m_A = MD5Constants::init_A;
m_B = MD5Constants::init_B;
m_C = MD5Constants::init_C;
m_D = MD5Constants::init_D;
m_count[0] = 0;
m_count[1] = 0;
__builtin_memset(m_data_buffer, 0, sizeof(m_data_buffer));
}
private:
inline void transform(const u8*);
inline void reset();
static void encode(const u32* from, u8* to, size_t length);
static void decode(const u8* from, u32* to, size_t length);

View file

@ -123,10 +123,7 @@ namespace Hash {
builder.appendf("%zu", this->DigestSize * 8);
return builder.build();
};
private:
inline void transform(const u8*);
inline void reset()
inline virtual void reset() override
{
m_data_length = 0;
m_bit_length = 0;
@ -134,6 +131,9 @@ namespace Hash {
m_state[i] = SHA256Constants::InitializationHashes[i];
}
private:
inline void transform(const u8*);
u8 m_data_buffer[BlockSize];
size_t m_data_length { 0 };
@ -176,10 +176,7 @@ namespace Hash {
builder.appendf("%zu", this->DigestSize * 8);
return builder.build();
};
private:
inline void transform(const u8*);
inline void reset()
inline virtual void reset() override
{
m_data_length = 0;
m_bit_length = 0;
@ -187,6 +184,9 @@ namespace Hash {
m_state[i] = SHA512Constants::InitializationHashes[i];
}
private:
inline void transform(const u8*);
u8 m_data_buffer[BlockSize];
size_t m_data_length { 0 };