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

LibCrypto: Exclude class_name() methods from the Kernel

These are only used by Userland and contain infallible String
allocations, so let's just ifdef them out of the Kernel.
This commit is contained in:
Idan Horowitz 2022-02-15 21:36:46 +02:00 committed by Andreas Kling
parent 6959e7f778
commit c8db8d6152
16 changed files with 119 additions and 21 deletions

View file

@ -6,11 +6,14 @@
#pragma once
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <LibCrypto/Cipher/Mode/Mode.h>
#ifndef KERNEL
# include <AK/String.h>
#endif
namespace Crypto {
namespace Cipher {
@ -26,6 +29,7 @@ public:
{
}
#ifndef KERNEL
virtual String class_name() const override
{
StringBuilder builder;
@ -33,8 +37,12 @@ public:
builder.append("_CBC");
return builder.build();
}
#endif
virtual size_t IV_length() const override { return IVSizeInBits / 8; }
virtual size_t IV_length() const override
{
return IVSizeInBits / 8;
}
virtual void encrypt(ReadonlyBytes in, Bytes& out, ReadonlyBytes ivec = {}, Bytes* ivec_out = nullptr) override
{

View file

@ -6,11 +6,14 @@
#pragma once
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <LibCrypto/Cipher/Mode/Mode.h>
#ifndef KERNEL
# include <AK/String.h>
#endif
namespace Crypto {
namespace Cipher {
@ -101,6 +104,7 @@ public:
{
}
#ifndef KERNEL
virtual String class_name() const override
{
StringBuilder builder;
@ -108,8 +112,12 @@ public:
builder.append("_CTR");
return builder.build();
}
#endif
virtual size_t IV_length() const override { return IVSizeInBits / 8; }
virtual size_t IV_length() const override
{
return IVSizeInBits / 8;
}
virtual void encrypt(ReadonlyBytes in, Bytes& out, ReadonlyBytes ivec = {}, Bytes* ivec_out = nullptr) override
{

View file

@ -7,13 +7,16 @@
#pragma once
#include <AK/OwnPtr.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <LibCrypto/Authentication/GHash.h>
#include <LibCrypto/Cipher/Mode/CTR.h>
#include <LibCrypto/Verification.h>
#ifndef KERNEL
# include <AK/String.h>
#endif
namespace Crypto {
namespace Cipher {
@ -40,6 +43,7 @@ public:
m_ghash = Authentication::GHash(m_auth_key);
}
#ifndef KERNEL
virtual String class_name() const override
{
StringBuilder builder;
@ -47,8 +51,12 @@ public:
builder.append("_GCM");
return builder.build();
}
#endif
virtual size_t IV_length() const override { return IVSizeInBits / 8; }
virtual size_t IV_length() const override
{
return IVSizeInBits / 8;
}
// FIXME: This overload throws away the auth stuff, think up a better way to return more than a single bytebuffer.
virtual void encrypt(ReadonlyBytes in, Bytes& out, ReadonlyBytes ivec = {}, Bytes* = nullptr) override

View file

@ -35,8 +35,14 @@ public:
return ByteBuffer::create_uninitialized(input_size + T::block_size() - remainder);
}
#ifndef KERNEL
virtual String class_name() const = 0;
T& cipher() { return m_cipher; }
#endif
T& cipher()
{
return m_cipher;
}
protected:
virtual void prune_padding(Bytes& data)