Skip to content

Commit 4b1c73d

Browse files
Viktor Dukhovnit8m
Viktor Dukhovni
authored andcommitted
ML-KEM hybrids for TLS
- When used as KEMs in TLS the ECDHE algorithms are NOT subjected to HPKE Extract/Expand key derivation. Instead the TLS HKDF is used as usual. - Consequently these KEMs are just the usual ECDHE key exchange operations, be it with the encap ECDH private key unavoidably ephemeral. - A new "MLX" KEM provider is added that supports four hybrids of EC/ECX DH with ML-KEM: * ML-KEM-768 + X25519 * ML-KEM-1024 + X448 * P-256 + ML-KEM-768 * P-384 + ML-KEM-1024 - Support listing of implemented TLS groups. The SSL_CTX_get0_implemented_groups() function and new `openssl list -tls-groups` and `openssl list -all-tls-groups` commands make it possible to determine which groups are implemented by the SSL library for a particular TLS version or range of versions matching an SSL_CTX. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Tim Hudson <[email protected]> (Merged from openssl#26220)
1 parent 95d764a commit 4b1c73d

32 files changed

+1749
-227
lines changed

AUTHORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Groups
1212

1313
* OpenSSL Software Services, Inc.
1414
* OpenSSL Software Foundation, Inc.
15+
* Google LLC
1516

1617
Individuals
1718
-----------

apps/list.c

+93
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <openssl/store.h>
2424
#include <openssl/core_names.h>
2525
#include <openssl/rand.h>
26+
#include <openssl/safestack.h>
27+
#include <openssl/ssl.h>
2628
#include <openssl/tls1.h>
2729
#include "apps.h"
2830
#include "app_params.h"
@@ -776,6 +778,42 @@ static int list_tls_sigalg_caps(OSSL_PROVIDER *provider, void *cbdata)
776778
return 1;
777779
}
778780

781+
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
782+
static void list_tls_groups(int version, int all)
783+
{
784+
SSL_CTX *ctx = NULL;
785+
STACK_OF(OPENSSL_CSTRING) *groups;
786+
size_t i, num;
787+
788+
if ((groups = sk_OPENSSL_CSTRING_new_null()) == NULL) {
789+
BIO_printf(bio_err, "ERROR: Memory allocation\n");
790+
return;
791+
}
792+
if ((ctx = SSL_CTX_new(TLS_method())) == NULL) {
793+
BIO_printf(bio_err, "ERROR: Memory allocation\n");
794+
goto err;
795+
}
796+
if (!SSL_CTX_set_min_proto_version(ctx, version)
797+
|| !SSL_CTX_set_max_proto_version(ctx, version)) {
798+
BIO_printf(bio_err, "ERROR: setting TLS protocol version\n");
799+
goto err;
800+
}
801+
if (!SSL_CTX_get0_implemented_groups(ctx, all, groups)) {
802+
BIO_printf(bio_err, "ERROR: getting implemented TLS group list\n");
803+
goto err;
804+
}
805+
num = sk_OPENSSL_CSTRING_num(groups);
806+
for (i = 0; i < num; ++i) {
807+
BIO_printf(bio_out, "%s%c", sk_OPENSSL_CSTRING_value(groups, i),
808+
(i < num - 1) ? ':' : '\n');
809+
}
810+
err:
811+
SSL_CTX_free(ctx);
812+
sk_OPENSSL_CSTRING_free(groups);
813+
return;
814+
}
815+
#endif
816+
779817
static void list_tls_signatures(void)
780818
{
781819
int tls_sigalg_listed = 0;
@@ -1515,6 +1553,15 @@ typedef enum HELPLIST_CHOICE {
15151553
OPT_TLS_SIGNATURE_ALGORITHMS, OPT_ASYM_CIPHER_ALGORITHMS,
15161554
OPT_STORE_LOADERS, OPT_PROVIDER_INFO, OPT_OBJECTS,
15171555
OPT_SELECT_NAME,
1556+
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
1557+
OPT_ALL_TLS_GROUPS, OPT_TLS_GROUPS,
1558+
# if !defined(OPENSSL_NO_TLS1_2)
1559+
OPT_TLS1_2,
1560+
# endif
1561+
# if !defined(OPENSSL_NO_TLS1_3)
1562+
OPT_TLS1_3,
1563+
# endif
1564+
#endif
15181565
#ifndef OPENSSL_NO_DEPRECATED_3_0
15191566
OPT_ENGINES,
15201567
#endif
@@ -1572,6 +1619,20 @@ const OPTIONS list_options[] = {
15721619
"List of public key methods"},
15731620
{"store-loaders", OPT_STORE_LOADERS, '-',
15741621
"List of store loaders"},
1622+
#if !defined(OPENSSL_NO_TLS1_2) || !defined(OPENSSL_NO_TLS1_3)
1623+
{"tls-groups", OPT_TLS_GROUPS, '-',
1624+
"List implemented TLS key exchange 'groups'" },
1625+
{"all-tls-groups", OPT_ALL_TLS_GROUPS, '-',
1626+
"List implemented TLS key exchange 'groups' and all aliases" },
1627+
# ifndef OPENSSL_NO_TLS1_2
1628+
{"tls1_2", OPT_TLS1_2, '-',
1629+
"When listing 'groups', list those compatible with TLS1.2"},
1630+
# endif
1631+
# ifndef OPENSSL_NO_TLS1_3
1632+
{"tls1_3", OPT_TLS1_3, '-',
1633+
"When listing 'groups', list those compatible with TLS1.3"},
1634+
# endif
1635+
#endif
15751636
{"providers", OPT_PROVIDER_INFO, '-',
15761637
"List of provider information"},
15771638
#ifndef OPENSSL_NO_DEPRECATED_3_0
@@ -1594,6 +1655,14 @@ int list_main(int argc, char **argv)
15941655
HELPLIST_CHOICE o;
15951656
int one = 0, done = 0;
15961657
int print_newline = 0;
1658+
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
1659+
int all_tls_groups = 0;
1660+
# if !defined(OPENSSL_NO_TLS1_3)
1661+
unsigned int tls_version = TLS1_3_VERSION;
1662+
# else
1663+
unsigned int tls_version = TLS1_2_VERSION;
1664+
# endif
1665+
#endif
15971666
struct {
15981667
unsigned int commands:1;
15991668
unsigned int all_algorithms:1;
@@ -1612,6 +1681,7 @@ int list_main(int argc, char **argv)
16121681
unsigned int tls_signature_algorithms:1;
16131682
unsigned int keyexchange_algorithms:1;
16141683
unsigned int kem_algorithms:1;
1684+
unsigned int tls_groups:1;
16151685
unsigned int asym_cipher_algorithms:1;
16161686
unsigned int pk_algorithms:1;
16171687
unsigned int pk_method:1;
@@ -1692,6 +1762,25 @@ int list_main(int argc, char **argv)
16921762
case OPT_KEM_ALGORITHMS:
16931763
todo.kem_algorithms = 1;
16941764
break;
1765+
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
1766+
case OPT_TLS_GROUPS:
1767+
todo.tls_groups = 1;
1768+
break;
1769+
case OPT_ALL_TLS_GROUPS:
1770+
all_tls_groups = 1;
1771+
todo.tls_groups = 1;
1772+
break;
1773+
# if !defined(OPENSSL_NO_TLS1_2)
1774+
case OPT_TLS1_2:
1775+
tls_version = TLS1_2_VERSION;
1776+
break;
1777+
# endif
1778+
# if !defined(OPENSSL_NO_TLS1_3)
1779+
case OPT_TLS1_3:
1780+
tls_version = TLS1_3_VERSION;
1781+
break;
1782+
# endif
1783+
#endif
16951784
case OPT_ASYM_CIPHER_ALGORITHMS:
16961785
todo.asym_cipher_algorithms = 1;
16971786
break;
@@ -1811,6 +1900,10 @@ int list_main(int argc, char **argv)
18111900
MAYBE_ADD_NL(list_keyexchanges());
18121901
if (todo.kem_algorithms)
18131902
MAYBE_ADD_NL(list_kems());
1903+
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
1904+
if (todo.tls_groups)
1905+
MAYBE_ADD_NL(list_tls_groups(tls_version, all_tls_groups));
1906+
#endif
18141907
if (todo.pk_algorithms)
18151908
MAYBE_ADD_NL(list_pkey());
18161909
if (todo.pk_method)

crypto/err/openssl.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,8 @@ PROV_R_NOT_XOF_OR_INVALID_LENGTH:113:not xof or invalid length
11411141
PROV_R_NO_INSTANCE_ALLOWED:242:no instance allowed
11421142
PROV_R_NO_KEY_SET:114:no key set
11431143
PROV_R_NO_PARAMETERS_SET:177:no parameters set
1144+
PROV_R_NULL_LENGTH_POINTER:247:null length pointer
1145+
PROV_R_NULL_OUTPUT_BUFFER:245:null output buffer
11441146
PROV_R_ONESHOT_CALL_OUT_OF_ORDER:239:oneshot call out of order
11451147
PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE:178:\
11461148
operation not supported for this keytype
@@ -1176,9 +1178,11 @@ PROV_R_UNSUPPORTED_CEK_ALG:145:unsupported cek alg
11761178
PROV_R_UNSUPPORTED_KEY_SIZE:153:unsupported key size
11771179
PROV_R_UNSUPPORTED_MAC_TYPE:137:unsupported mac type
11781180
PROV_R_UNSUPPORTED_NUMBER_OF_ROUNDS:152:unsupported number of rounds
1181+
PROV_R_UNSUPPORTED_SELECTION:248:unsupported selection
11791182
PROV_R_UPDATE_CALL_OUT_OF_ORDER:240:update call out of order
11801183
PROV_R_URI_AUTHORITY_UNSUPPORTED:223:uri authority unsupported
11811184
PROV_R_VALUE_ERROR:138:value error
1185+
PROV_R_WRONG_CIPHERTEXT_SIZE:246:wrong ciphertext size
11821186
PROV_R_WRONG_FINAL_BLOCK_LENGTH:107:wrong final block length
11831187
PROV_R_WRONG_OUTPUT_BUFFER_SIZE:139:wrong output buffer size
11841188
PROV_R_XOF_DIGESTS_NOT_ALLOWED:183:xof digests not allowed

crypto/ml_kem/ml_kem.c

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* https://www.openssl.org/source/license.html
88
*/
99

10-
/* Copyright (c) 2024, Google Inc. */
11-
1210
#include <internal/common.h>
1311
#include <internal/constant_time.h>
1412
#include <internal/sha3.h>

doc/man1/openssl-list.pod.in

+27
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ B<openssl list>
3232
[B<-key-managers>]
3333
[B<-key-exchange-algorithms>]
3434
[B<-kem-algorithms>]
35+
[B<-tls-groups>]
36+
[B<-all-tls-groups>]
37+
[B<-tls1_2>]
38+
[B<-tls1_3>]
3539
[B<-signature-algorithms>]
3640
[B<-tls-signature-algorithms>]
3741
[B<-asymcipher-algorithms>]
@@ -191,6 +195,29 @@ Display a list of key exchange algorithms.
191195

192196
Display a list of key encapsulation algorithms.
193197

198+
=item B<-tls-groups>
199+
200+
Display a list of the IANA names of all available (implemented) TLS groups.
201+
By default the listed groups are those compatible with TLS 1.3.
202+
203+
=item B<-all-tls-groups>
204+
205+
Display a list of the names of all available (implemented) TLS groups,
206+
including any aliases.
207+
Some groups are known under multiple names, for example, B<secp256r1> is also
208+
known as B<P-256>.
209+
By default the listed groups are those compatible with TLS 1.3.
210+
211+
=item B<-tls1_2>
212+
213+
When listing TLS groups, list those compatible with TLS 1.2
214+
215+
=item B<-tls1_3>
216+
217+
When listing TLS groups, output those compatible with TLS 1.3.
218+
TLS 1.3 is the current default protocol version, but the default version is
219+
subject to change, so best to specify the version explicitly.
220+
194221
=item B<-signature-algorithms>
195222

196223
Display a list of signature algorithms.

doc/man1/openssl-s_client.pod.in

+8-5
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,14 @@ For example strings, see L<SSL_CTX_set1_sigalgs(3)>
669669
Specifies the list of supported curves to be sent by the client. The curve is
670670
ultimately selected by the server.
671671

672-
The list of all supported groups includes named EC parameters as well as X25519
673-
and X448 or FFDHE groups, and may also include groups implemented in 3rd-party
674-
providers. For a list of named EC parameters, use:
675-
676-
$ openssl ecparam -list_curves
672+
The list of available groups includes various built-in named EC curves, as well
673+
as X25519 and X448, FFDHE groups, and any additional groups implemented in the
674+
default or 3rd-party providers.
675+
The commands below list the available groups for TLS 1.2 and TLS 1.3,
676+
respectively:
677+
678+
$ openssl list -tls1_2 -tls-groups
679+
$ openssl list -tls1_3 -tls-groups
677680

678681
=item B<-cipher> I<cipherlist>
679682

doc/man1/openssl-s_server.pod.in

+8-5
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,14 @@ Signature algorithms to support for client certificate authentication
675675

676676
Specifies the elliptic curve to use. NOTE: this is single curve, not a list.
677677

678-
The list of all supported groups includes named EC parameters as well as X25519
679-
and X448 or FFDHE groups, and may also include groups implemented in 3rd-party
680-
providers. For a list of named EC parameters, use:
681-
682-
$ openssl ecparam -list_curves
678+
The list of available groups includes various built-in named EC curves, as well
679+
as X25519 and X448, FFDHE groups, and any additional groups implemented in the
680+
default or 3rd-party providers.
681+
The commands below list the available groups for TLS 1.2 and TLS 1.3,
682+
respectively.
683+
684+
$ openssl list -tls1_2 -tls-groups
685+
$ openssl list -tls1_3 -tls-groups
683686

684687
=item B<-cipher> I<val>
685688

0 commit comments

Comments
 (0)