summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCrypto
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-05-14 09:22:56 +0430
committerLinus Groh <mail@linusgroh.de>2021-05-14 08:39:29 +0100
commitdf515e1d850339f408ab5eb7f4713d989ffb4534 (patch)
tree0f26bd76fba48a95cd29b841d2a80e99e1be0576 /Userland/Libraries/LibCrypto
parentbfd4c7a16cd35452bc5d1331f05d8bd713b37d14 (diff)
downloadserenity-df515e1d850339f408ab5eb7f4713d989ffb4534.zip
LibCrypto+LibTLS: Avoid unaligned reads and writes
This adds an `AK::ByteReader` to help with that so we don't duplicate the logic all over the place. No more `*(const u16*)` and `*(const u32*)` for anyone. This should help a little with #7060.
Diffstat (limited to 'Userland/Libraries/LibCrypto')
-rw-r--r--Userland/Libraries/LibCrypto/Authentication/GHash.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/Userland/Libraries/LibCrypto/Authentication/GHash.cpp b/Userland/Libraries/LibCrypto/Authentication/GHash.cpp
index 1b93c4c6cc..5afdaf7609 100644
--- a/Userland/Libraries/LibCrypto/Authentication/GHash.cpp
+++ b/Userland/Libraries/LibCrypto/Authentication/GHash.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/ByteReader.h>
#include <AK/Debug.h>
#include <AK/MemoryStream.h>
#include <AK/Types.h>
@@ -15,14 +16,13 @@ namespace {
static u32 to_u32(const u8* b)
{
- return AK::convert_between_host_and_big_endian(*(const u32*)b);
+ return AK::convert_between_host_and_big_endian(ByteReader::load32(b));
}
static void to_u8s(u8* b, const u32* w)
{
for (auto i = 0; i < 4; ++i) {
- auto& e = *((u32*)(b + i * 4));
- e = AK::convert_between_host_and_big_endian(w[i]);
+ ByteReader::store(b + i * 4, AK::convert_between_host_and_big_endian(w[i]));
}
}