1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:47:35 +00:00

LibTLS: Add Elliptic Curve Diffie-Hellman Ephemeral (ECDHE) support

This adds support for the Elliptic Curve Diffie-Hellman Ephemeral key
exchange, using the X25519 elliptic curve. This means that the
ECDHE_RSA_WITH_AES_128_GCM_SHA256 and ECDHE_RSA_WITH_AES_256_GCM_SHA384
cipher suites are now supported.

Currently, only the X25519 elliptic curve is supported in combination
with the uncompressed elliptic curve point format. However, since the
X25519 is the recommended curve, basically every server supports this.
Furthermore, the uncompressed point format is required by the TLS
specification, which means any server with EC support will support the
uncompressed format.

Like the implementation of the normal Diffie-Hellman Ephemeral key
exchange, this implementation does not currently validate the signature
of the public key sent by the server.
This commit is contained in:
Michiel Visser 2022-02-17 19:43:42 +01:00 committed by Ali Mohammad Pur
parent be07892fea
commit 7ab4337721
5 changed files with 176 additions and 10 deletions

View file

@ -31,6 +31,10 @@ enum class CipherSuite {
DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x009E,
DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x009F,
// RFC 5289 - ECDHE for AES-GCM
ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC02F,
ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC030,
// All recommended cipher suites (according to https://ciphersuite.info/cs/)
// RFC 5288 - DH, DHE and RSA for AES-GCM
@ -185,4 +189,33 @@ constexpr size_t cipher_key_size(CipherAlgorithm algorithm)
}
}
enum class NamedCurve : u16 {
secp256r1 = 23,
secp384r1 = 24,
secp521r1 = 25,
x25519 = 29,
x448 = 30,
};
constexpr size_t named_curve_key_size(NamedCurve group)
{
switch (group) {
case NamedCurve::secp256r1:
case NamedCurve::secp384r1:
case NamedCurve::secp521r1:
// FIXME: Add the correct key size for these elliptic curves
return 0;
case NamedCurve::x25519:
return 256;
case NamedCurve::x448:
return 448;
default:
return 0;
}
}
enum class ECPointFormat : u8 {
Uncompressed = 0,
};
}