LibCrypto: Remove unused EllipticCurve abstract class

This was required only to support our custom TLS implementation, but
does not serve any purpose other than forcing improper APIs.
This commit is contained in:
devgianlu 2025-02-16 11:49:11 +01:00 committed by Alexander Kalenik
commit 7180c5f13b
Notes: github-actions[bot] 2025-02-17 23:03:41 +00:00
4 changed files with 18 additions and 45 deletions

View file

@ -1,24 +0,0 @@
/*
* Copyright (c) 2022, Michiel Visser <opensource@webmichiel.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/ByteBuffer.h>
namespace Crypto::Curves {
class EllipticCurve {
public:
virtual size_t key_size() = 0;
virtual ErrorOr<ByteBuffer> generate_private_key() = 0;
virtual ErrorOr<ByteBuffer> generate_public_key(ReadonlyBytes a) = 0;
virtual ErrorOr<ByteBuffer> compute_coordinate(ReadonlyBytes scalar_bytes, ReadonlyBytes point_bytes) = 0;
virtual ErrorOr<ByteBuffer> derive_premaster_key(ReadonlyBytes shared_point) = 0;
virtual ~EllipticCurve() = default;
};
}

View file

@ -11,7 +11,6 @@
#include <AK/StringView.h> #include <AK/StringView.h>
#include <LibCrypto/ASN1/Constants.h> #include <LibCrypto/ASN1/Constants.h>
#include <LibCrypto/ASN1/DER.h> #include <LibCrypto/ASN1/DER.h>
#include <LibCrypto/Curves/EllipticCurve.h>
#include <LibCrypto/OpenSSL.h> #include <LibCrypto/OpenSSL.h>
namespace { namespace {
@ -134,9 +133,9 @@ struct SECPxxxr1Signature {
} }
}; };
class SECPxxxr1 : public EllipticCurve { class SECPxxxr1 {
public: public:
size_t key_size() override { return 1 + (2 * m_scalar_size); } size_t key_size() { return 1 + (2 * m_scalar_size); }
ErrorOr<UnsignedBigInteger> generate_private_key_scalar(); ErrorOr<UnsignedBigInteger> generate_private_key_scalar();
ErrorOr<SECPxxxr1Point> generate_public_key_point(UnsignedBigInteger scalar); ErrorOr<SECPxxxr1Point> generate_public_key_point(UnsignedBigInteger scalar);
@ -149,7 +148,7 @@ public:
return shared_point; return shared_point;
} }
ErrorOr<ByteBuffer> generate_private_key() override ErrorOr<ByteBuffer> generate_private_key()
{ {
auto key = TRY(generate_private_key_scalar()); auto key = TRY(generate_private_key_scalar());
@ -159,14 +158,14 @@ public:
return buffer.slice(0, size); return buffer.slice(0, size);
} }
ErrorOr<ByteBuffer> generate_public_key(ReadonlyBytes a) override ErrorOr<ByteBuffer> generate_public_key(ReadonlyBytes a)
{ {
auto a_int = UnsignedBigInteger::import_data(a); auto a_int = UnsignedBigInteger::import_data(a);
auto point = TRY(generate_public_key_point(a_int)); auto point = TRY(generate_public_key_point(a_int));
return point.to_uncompressed(); return point.to_uncompressed();
} }
ErrorOr<ByteBuffer> compute_coordinate(ReadonlyBytes scalar_bytes, ReadonlyBytes point_bytes) override ErrorOr<ByteBuffer> compute_coordinate(ReadonlyBytes scalar_bytes, ReadonlyBytes point_bytes)
{ {
auto scalar = UnsignedBigInteger::import_data(scalar_bytes); auto scalar = UnsignedBigInteger::import_data(scalar_bytes);
auto point = TRY(SECPxxxr1Point::from_uncompressed(point_bytes)); auto point = TRY(SECPxxxr1Point::from_uncompressed(point_bytes));
@ -174,7 +173,7 @@ public:
return result.to_uncompressed(); return result.to_uncompressed();
} }
ErrorOr<ByteBuffer> derive_premaster_key(ReadonlyBytes shared_point_bytes) override ErrorOr<ByteBuffer> derive_premaster_key(ReadonlyBytes shared_point_bytes)
{ {
auto shared_point = TRY(SECPxxxr1Point::from_uncompressed(shared_point_bytes)); auto shared_point = TRY(SECPxxxr1Point::from_uncompressed(shared_point_bytes));
auto premaster_key_point = TRY(derive_premaster_key_point(shared_point)); auto premaster_key_point = TRY(derive_premaster_key_point(shared_point));

View file

@ -7,17 +7,16 @@
#pragma once #pragma once
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <LibCrypto/Curves/EllipticCurve.h>
namespace Crypto::Curves { namespace Crypto::Curves {
class X25519 : public EllipticCurve { class X25519 {
public: public:
size_t key_size() override { return 32; } size_t key_size() { return 32; }
ErrorOr<ByteBuffer> generate_private_key() override; ErrorOr<ByteBuffer> generate_private_key();
ErrorOr<ByteBuffer> generate_public_key(ReadonlyBytes a) override; ErrorOr<ByteBuffer> generate_public_key(ReadonlyBytes a);
ErrorOr<ByteBuffer> compute_coordinate(ReadonlyBytes a, ReadonlyBytes b) override; ErrorOr<ByteBuffer> compute_coordinate(ReadonlyBytes a, ReadonlyBytes b);
ErrorOr<ByteBuffer> derive_premaster_key(ReadonlyBytes shared_point) override; ErrorOr<ByteBuffer> derive_premaster_key(ReadonlyBytes shared_point);
}; };
} }

View file

@ -7,17 +7,16 @@
#pragma once #pragma once
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <LibCrypto/Curves/EllipticCurve.h>
namespace Crypto::Curves { namespace Crypto::Curves {
class X448 : public EllipticCurve { class X448 {
public: public:
size_t key_size() override { return 56; } size_t key_size() { return 56; }
ErrorOr<ByteBuffer> generate_private_key() override; ErrorOr<ByteBuffer> generate_private_key();
ErrorOr<ByteBuffer> generate_public_key(ReadonlyBytes a) override; ErrorOr<ByteBuffer> generate_public_key(ReadonlyBytes a);
ErrorOr<ByteBuffer> compute_coordinate(ReadonlyBytes a, ReadonlyBytes b) override; ErrorOr<ByteBuffer> compute_coordinate(ReadonlyBytes a, ReadonlyBytes b);
ErrorOr<ByteBuffer> derive_premaster_key(ReadonlyBytes shared_point) override; ErrorOr<ByteBuffer> derive_premaster_key(ReadonlyBytes shared_point);
}; };
} }