1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 17:55:09 +00:00
serenity/Userland/Libraries/LibCrypto/Authentication/GHash.h
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00

68 lines
1.3 KiB
C++

/*
* Copyright (c) 2020, Ali Mohammad Pur <mpfard@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/ByteReader.h>
#include <AK/Endian.h>
#include <AK/Types.h>
#include <LibCrypto/Hash/HashFunction.h>
#ifndef KERNEL
# include <AK/DeprecatedString.h>
#endif
namespace Crypto {
namespace Authentication {
void galois_multiply(u32 (&z)[4], const u32 (&x)[4], const u32 (&y)[4]);
struct GHashDigest {
constexpr static size_t Size = 16;
u8 data[Size];
u8 const* immutable_data() const { return data; }
size_t data_length() { return Size; }
};
class GHash final {
public:
using TagType = GHashDigest;
template<size_t N>
explicit GHash(char const (&key)[N])
: GHash({ key, N })
{
}
explicit GHash(ReadonlyBytes key)
{
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; }
#ifndef KERNEL
DeprecatedString class_name() const
{
return "GHash";
}
#endif
TagType process(ReadonlyBytes aad, ReadonlyBytes cipher);
private:
inline void transform(ReadonlyBytes, ReadonlyBytes);
u32 m_key[4];
};
}
}