Skip to content

Commit 7e5b28a

Browse files
authored
BoringSSL: Add support for MLKEM768 and MLKEM1024 (#140)
Motivation: BoringSSL supports MLKEM768 and MLKEM1024 these days so we can also support it Modifications: - Add MLKEM768 and MLKEM1024 to our KEM enum - Add support for these to our BoringSSL based implementation - Update BoringSSL to the latest sha so it supports MLKEM* Result: Support more PQC KEMs when using BoringSSL
1 parent fbf53d6 commit 7e5b28a

6 files changed

Lines changed: 29 additions & 3 deletions

File tree

codec-ohttp-hpke-classes-boringssl/src/main/java/io/netty/incubator/codec/hpke/boringssl/BoringSSL.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ private static void loadNativeLibrary() {
6363
BoringSSLNativeStaticallyReferencedJniMethods.EVP_hpke_x25519_hkdf_sha256();
6464
static final long EVP_hpke_xwing =
6565
BoringSSLNativeStaticallyReferencedJniMethods.EVP_hpke_xwing();
66+
static final long EVP_hpke_mlkem768 =
67+
BoringSSLNativeStaticallyReferencedJniMethods.EVP_hpke_mlkem768();
68+
static final long EVP_hpke_mlkem1024 =
69+
BoringSSLNativeStaticallyReferencedJniMethods.EVP_hpke_mlkem1024();
6670
static final long EVP_hpke_hkdf_sha256 =
6771
BoringSSLNativeStaticallyReferencedJniMethods.EVP_hpke_hkdf_sha256();
6872
static final long EVP_hpke_aes_128_gcm =

codec-ohttp-hpke-classes-boringssl/src/main/java/io/netty/incubator/codec/hpke/boringssl/BoringSSLNativeStaticallyReferencedJniMethods.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
final class BoringSSLNativeStaticallyReferencedJniMethods {
1919
static native long EVP_hpke_x25519_hkdf_sha256();
2020
static native long EVP_hpke_xwing();
21+
static native long EVP_hpke_mlkem768();
22+
static native long EVP_hpke_mlkem1024();
23+
2124
static native long EVP_hpke_hkdf_sha256();
2225
static native long EVP_hpke_aes_128_gcm();
2326
static native long EVP_hpke_aes_256_gcm();

codec-ohttp-hpke-classes-boringssl/src/main/java/io/netty/incubator/codec/hpke/boringssl/BoringSSLOHttpCryptoProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ private static long boringSSLKEM(KEM kem) {
9292
switch (kem) {
9393
case XWING:
9494
return BoringSSL.EVP_hpke_xwing;
95+
case MLKEM786:
96+
return BoringSSL.EVP_hpke_mlkem768;
97+
case MLKEM1024:
98+
return BoringSSL.EVP_hpke_mlkem1024;
9599
case X25519_SHA256:
96100
return BoringSSL.EVP_hpke_x25519_hkdf_sha256;
97101
default:
@@ -271,6 +275,8 @@ public boolean isSupported(KEM kem) {
271275
switch (kem) {
272276
case X25519_SHA256:
273277
case XWING:
278+
case MLKEM786:
279+
case MLKEM1024:
274280
return true;
275281
default:
276282
return false;

codec-ohttp-hpke-native-boringssl/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@
4646
<boringsslHomeBuildDir>${boringsslHomeDir}/build</boringsslHomeBuildDir>
4747
<boringsslHomeIncludeDir>${boringsslHomeDir}/include</boringsslHomeIncludeDir>
4848
<boringsslRepository>https://boringssl.googlesource.com/boringssl</boringsslRepository>
49-
<!-- Lets use what we use in netty-tcnative-boringssl-static -->
5049
<boringsslBranch>main</boringsslBranch>
51-
<boringsslCommitSha>0226f30467f540a3f62ef48d453f93927da199b6</boringsslCommitSha>
50+
<boringsslCommitSha>5ac7567c234514157a504ff3fbedc0f5eddbf678</boringsslCommitSha>
5251

5352
<generatedSourcesDir>${project.build.directory}/generated-sources</generatedSourcesDir>
5453
<templateDir>${project.build.directory}/template</templateDir>

codec-ohttp-hpke-native-boringssl/src/main/c/netty_incubator_codec_ohttp_hpke_boringssl.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ static jlong netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_xwing(JNIEnv* e
5757
return (jlong) EVP_hpke_xwing();
5858
}
5959

60+
static jlong netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_mlkem768(JNIEnv* env, jclass clazz) {
61+
return (jlong) EVP_hpke_mlkem768();
62+
}
63+
64+
static jlong netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_mlkem1024(JNIEnv* env, jclass clazz) {
65+
return (jlong) EVP_hpke_mlkem1024();
66+
}
67+
6068
static jlong netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_hkdf_sha256(JNIEnv* env, jclass clazz) {
6169
return (jlong) EVP_hpke_hkdf_sha256();
6270
}
@@ -502,6 +510,9 @@ static jbyteArray netty_incubator_codec_ohttp_hpke_boringssl_HKDF_expand(JNIEnv*
502510
static const JNINativeMethod statically_referenced_fixed_method_table[] = {
503511
{ "EVP_hpke_x25519_hkdf_sha256", "()J", (void *) netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_x25519_hkdf_sha256 },
504512
{ "EVP_hpke_xwing", "()J", (void *) netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_xwing },
513+
{ "EVP_hpke_mlkem768", "()J", (void *) netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_mlkem768 },
514+
{ "EVP_hpke_mlkem1024", "()J", (void *) netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_mlkem1024 },
515+
505516
{ "EVP_hpke_hkdf_sha256", "()J", (void *) netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_hkdf_sha256 },
506517
{ "EVP_hpke_aes_128_gcm", "()J", (void *) netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_aes_128_gcm },
507518
{ "EVP_hpke_aes_256_gcm", "()J", (void *) netty_incubator_codec_ohttp_hpke_boringssl_EVP_hpke_aes_256_gcm },

codec-ohttp-hpke/src/main/java/io/netty/incubator/codec/hpke/KEM.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public enum KEM {
2525
X25519_SHA256((short) 32, 32, 32),
2626
X448_SHA512((short) 33, 56, 56),
2727
// See https://datatracker.ietf.org/doc/draft-connolly-cfrg-xwing-kem/
28-
XWING((short) 0x647a, 1120, 1216);
28+
XWING((short) 0x647a, 1120, 1216),
29+
// https://datatracker.ietf.org/doc/html/draft-ietf-hpke-pq-05#ml-kem-iana-table
30+
MLKEM786((short) 0x0041, 1088, 1184),
31+
MLKEM1024((short) 0x0042, 1568, 1568);
2932

3033
public static KEM forId(short id) {
3134
for (KEM val : values()) {

0 commit comments

Comments
 (0)