1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

LibCrypto+LibTLS: Generalize the elliptic curve interface

These changes generalize the interface with an elliptic curve
implementation. This allows LibTLS to support elliptic curves generally
without needing the specifics of elliptic curve implementations.

This should allow for easier addition of other elliptic curves.
This commit is contained in:
Michiel Visser 2022-03-05 18:13:39 +01:00 committed by Ali Mohammad Pur
parent 21bbff0349
commit c1b041e761
10 changed files with 133 additions and 122 deletions

View file

@ -6,6 +6,7 @@
#include <AK/ByteReader.h>
#include <AK/Endian.h>
#include <AK/Random.h>
#include <LibCrypto/Curves/X448.h>
namespace Crypto::Curves {
@ -282,6 +283,19 @@ void X448::modular_multiply_inverse(u32* state, u32* value)
modular_multiply(state, u, value);
}
ErrorOr<ByteBuffer> X448::generate_private_key()
{
auto buffer = TRY(ByteBuffer::create_uninitialized(BYTES));
fill_with_random(buffer.data(), buffer.size());
return buffer;
}
ErrorOr<ByteBuffer> X448::generate_public_key(ReadonlyBytes a)
{
u8 generator[BYTES] { 5 };
return compute_coordinate(a, { generator, BYTES });
}
// https://datatracker.ietf.org/doc/html/rfc7748#section-5
ErrorOr<ByteBuffer> X448::compute_coordinate(ReadonlyBytes input_k, ReadonlyBytes input_u)
{
@ -353,4 +367,12 @@ ErrorOr<ByteBuffer> X448::compute_coordinate(ReadonlyBytes input_k, ReadonlyByte
// Encode state for export
return export_state(u);
}
ErrorOr<ByteBuffer> X448::derive_premaster_key(ReadonlyBytes shared_point)
{
VERIFY(shared_point.size() == BYTES);
ByteBuffer premaster_key = TRY(ByteBuffer::copy(shared_point));
return premaster_key;
}
}