summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCrypto/Authentication
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2021-06-27 23:38:48 -0600
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-29 07:17:34 +0430
commit97444f0a25b2cb36a11493ab0e3ecdd38e610727 (patch)
tree295bb52f7c6dd17d95e84442e1b22f46d4b44131 /Userland/Libraries/LibCrypto/Authentication
parent3058ff1500458d02034d76abdfc6b0b1f9b40573 (diff)
downloadserenity-97444f0a25b2cb36a11493ab0e3ecdd38e610727.zip
LibCrypto: Avoid unaligned reads in GHash constructor
The fact that this always reads 16 bytes from the input byte stream for the key data is still a bit on the suspicious side, but at least it won't crash UBSAN anymore.
Diffstat (limited to 'Userland/Libraries/LibCrypto/Authentication')
-rw-r--r--Userland/Libraries/LibCrypto/Authentication/GHash.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibCrypto/Authentication/GHash.h b/Userland/Libraries/LibCrypto/Authentication/GHash.h
index 2101912da3..82a9dc573b 100644
--- a/Userland/Libraries/LibCrypto/Authentication/GHash.h
+++ b/Userland/Libraries/LibCrypto/Authentication/GHash.h
@@ -6,6 +6,7 @@
#pragma once
+#include <AK/ByteReader.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <LibCrypto/Hash/HashFunction.h>
@@ -35,8 +36,10 @@ public:
explicit GHash(const ReadonlyBytes& key)
{
- for (size_t i = 0; i < 16; i += 4)
- m_key[i / 4] = AK::convert_between_host_and_big_endian(*(const u32*)(key.offset(i)));
+ VERIFY(key.size() >= 16);
+ for (size_t i = 0; i < 16; i += 4) {
+ m_key[i / 4] = AK::convert_between_host_and_big_endian(ByteReader::load32(key.offset(i)));
+ }
}
constexpr static size_t digest_size() { return TagType::Size; }