Skip to content

Commit 8a86be7

Browse files
committed
Added ML-KEM support
1 parent 3ba566f commit 8a86be7

57 files changed

Lines changed: 4697 additions & 205 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888
LDFLAGS: "-Wl,-rpath,/usr/local/openssl-3.5/lib64 -L/usr/local/openssl-3.5/lib64"
8989
PKG_CONFIG_PATH: "/usr/local/openssl-3.5/lib64/pkgconfig"
9090
run: |
91+
set -x
9192
sudo apt-get update -qq
9293
sudo apt-get install -y libcppunit-dev p11-kit build-essential checkinstall zlib1g-dev sudo autoconf libtool git
9394
# Install OpenSSL 3.5
@@ -108,6 +109,7 @@ jobs:
108109
LDFLAGS: "-Wl,-rpath,/usr/local/openssl-3.5/lib64 -L/usr/local/openssl-3.5/lib64"
109110
PKG_CONFIG_PATH: "/usr/local/openssl-3.5/lib64/pkgconfig"
110111
run: |
112+
set -x
111113
./autogen.sh
112114
./configure --with-crypto-backend=openssl --with-openssl=${{ env.OPENSSL_INSTALL_DIR }}
113115
make -j$(nproc)
@@ -187,8 +189,9 @@ jobs:
187189
target-platform: x64
188190
ossl-version: "3.5.4"
189191
botan-version: ""
190-
build-options: "-DENABLE_MLDSA=ON"
192+
build-options: "-DENABLE_MLDSA=ON -DENABLE_MLKEM=ON"
191193
mldsa-test: "true"
194+
mlkem-test: "true"
192195
steps:
193196
- uses: actions/checkout@v4
194197
- uses: ilammy/msvc-dev-cmd@v1
@@ -223,5 +226,6 @@ jobs:
223226
env:
224227
CTEST_OUTPUT_ON_FAILURE: 1
225228
MLDSA_TEST: ${{ matrix.mldsa-test || '' }}
229+
MLKEM_TEST: ${{ matrix.mlkem-test || '' }}
226230
run: |
227231
cmake --build build --target RUN_TESTS

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Botan-*
5757
ROOT
5858
*.cmake
5959
CMakeFiles
60+
.idea/
61+
.vscode/
6062

6163
# Specifics
6264
softhsm2.module

CMAKE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Some options (more can be found in CMakeLists.txt):
1212
-DDISABLE_NON_PAGED_MEMORY=ON Disable non-paged memory for secure storage
1313
-DENABLE_EDDSA=ON Enable support for EDDSA
1414
-DENABLE_MLDSA=ON Enable support for ML-DSA
15+
-DENABLE_MLKEM=ON Enable support for ML-KEM
1516
-DWITH_MIGRATE=ON Build migration tool
1617
-DWITH_CRYPTO_BACKEND=openssl Select crypto backend (openssl|botan)
1718

CMAKE-WIN-NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ Some options (more can be found in CMakeLists.txt):
5252

5353
-DBUILD_TESTS=ON Compile tests along with libraries
5454
-DENABLE_EDDSA=ON Enable support for EDDSA
55-
-DENABLE_MLDSA=ON Enable support for ML-DSA
55+
-DENABLE_MLDSA=ON Enable support for ML-DSA
56+
-DENABLE_MLKEM=ON Enable support for ML-KEM
5657
-DWITH_MIGRATE=ON Build migration tool
5758
-DWITH_CRYPTO_BACKEND= Select crypto backend (openssl|botan)
5859
-DDISABLE_NON_PAGED_MEMORY=ON Disable non-paged memory for secure storage

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ option(ENABLE_64bit "Enable 64-bit compiling" OFF)
99
option(ENABLE_ECC "Enable support for ECC" ON)
1010
option(ENABLE_EDDSA "Enable support for EDDSA" ON)
1111
option(ENABLE_MLDSA "Enable support for ML-DSA" OFF)
12+
option(ENABLE_MLKEM "Enable support for ML-KEM" OFF)
1213
option(ENABLE_GOST "Enable support for GOST" OFF)
1314
option(ENABLE_FIPS "Enable support for FIPS 140-2 mode" OFF)
1415
option(ENABLE_P11_KIT "Enable p11-kit integration" ON)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ Options:
8282
--enable-ecc Enable support for ECC (default detect)
8383
--enable-gost Enable support for GOST (default detect)
8484
--enable-eddsa Enable support for EDDSA (default detect)
85-
--enable-mldsa Enable support for ML-DSA (default detect)
85+
--enable-mldsa Enable support for ML-DSA (default detect)
86+
--enable-mlkem Enable support for ML-KEM (default detect)
8687
--disable-visibility Disable hidden visibilty link mode [enabled]
8788
--with-crypto-backend Select crypto backend (openssl|botan)
8889
--with-openssl=PATH Specify prefix of path of OpenSSL

cmake/modules/CompilerOptions.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,27 @@ elseif(WITH_CRYPTO_BACKEND STREQUAL "openssl")
391391
message(STATUS "OpenSSL: Support for ML-DSA is disabled")
392392
endif(ENABLE_MLDSA)
393393

394+
# acx_openssl_mlkem.m4
395+
if(ENABLE_MLKEM)
396+
# ML-DSA
397+
set(testfile ${CMAKE_SOURCE_DIR}/cmake/modules/tests/test_openssl_mlkem.c)
398+
try_run(RUN_MLKEM COMPILE_RESULT
399+
"${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile}
400+
LINK_LIBRARIES ${CRYPTO_LIBS}
401+
CMAKE_FLAGS
402+
"-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}"
403+
)
404+
if(COMPILE_RESULT AND RUN_MLKEM EQUAL 0)
405+
set(WITH_ML_KEM 1)
406+
message(STATUS "OpenSSL: Found ML-KEM")
407+
else()
408+
set(error_msg "OpenSSL: Cannot find ML-KEM! OpenSSL library has no ML-KEM support!")
409+
message(FATAL_ERROR ${error_msg})
410+
endif()
411+
else(ENABLE_MLKEM)
412+
message(STATUS "OpenSSL: Support for ML-KEM is disabled")
413+
endif(ENABLE_MLKEM)
414+
394415
# acx_openssl_gost.m4
395416
if(ENABLE_GOST)
396417
set(testfile ${CMAKE_SOURCE_DIR}/cmake/modules/tests/test_openssl_gost.c)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <openssl/evp.h>
2+
#include <openssl/objects.h>
3+
int main()
4+
{
5+
EVP_PKEY_CTX *ctx;
6+
ctx = EVP_PKEY_CTX_new_from_name(NULL, "ML-KEM-512", NULL);
7+
8+
if (ctx == NULL)
9+
return 1;
10+
EVP_PKEY_CTX_free(ctx);
11+
return 0;
12+
}

config.h.in.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@
154154
/* Compile with ML-DSA support */
155155
#cmakedefine WITH_ML_DSA @WITH_ML_DSA@
156156

157+
/* Compile with ML-KEM support */
158+
#cmakedefine WITH_ML_KEM @WITH_ML_KEM@
159+
157160
/* Compile with FIPS 140-2 mode */
158161
#cmakedefine WITH_FIPS @WITH_FIPS@
159162

m4/acx_crypto_backend.m4

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[
3838
[enable_mldsa="detect"]
3939
)
4040
41+
# Add ML-KEM check
42+
43+
AC_ARG_ENABLE(mlkem,
44+
AS_HELP_STRING([--enable-mlkem],
45+
[Enable support for ML-KEM (default detect)]
46+
),
47+
[enable_mlkem="${enableval}"],
48+
[enable_mlkem="detect"]
49+
)
50+
4151
# Second check for the FIPS 140-2 mode
4252
4353
AC_ARG_ENABLE(fips,
@@ -119,6 +129,15 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[
119129
detect-no) enable_mldsa="no";;
120130
esac
121131
132+
case "${enable_mlkem}" in
133+
yes|detect) ACX_OPENSSL_MLKEM;;
134+
esac
135+
case "${enable_mlkem}-${have_lib_openssl_mlkem_support}" in
136+
yes-no) AC_MSG_ERROR([OpenSSL library has no ML-KEM support]);;
137+
detect-yes) enable_mlkem="yes";;
138+
detect-no) enable_mlkem="no";;
139+
esac
140+
122141
case "${enable_gost}-${enable_fips}" in
123142
yes-yes) AC_MSG_ERROR([GOST is not FIPS approved]);;
124143
yes-no|detect-no) ACX_OPENSSL_GOST;;
@@ -189,6 +208,10 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[
189208
AC_MSG_ERROR([Botan does not support ML-DSA])
190209
fi
191210
211+
if test "x${enable_mlkem}" = "xyes"; then
212+
AC_MSG_ERROR([Botan does not support ML-KEM])
213+
fi
214+
192215
case "${enable_gost}" in
193216
yes|detect) ACX_BOTAN_GOST;;
194217
esac
@@ -267,6 +290,19 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[
267290
fi
268291
AM_CONDITIONAL([WITH_ML_DSA], [test "x${enable_mldsa}" = "xyes"])
269292
293+
AC_MSG_CHECKING(for ML-KEM support)
294+
if test "x${enable_mlkem}" = "xyes"; then
295+
AC_MSG_RESULT(yes)
296+
AC_DEFINE_UNQUOTED(
297+
[WITH_ML_KEM],
298+
[],
299+
[Compile with ML-KEM support]
300+
)
301+
else
302+
AC_MSG_RESULT(no)
303+
fi
304+
AM_CONDITIONAL([WITH_ML_KEM], [test "x${enable_mlkem}" = "xyes"])
305+
270306
271307
AC_SUBST(CRYPTO_INCLUDES)
272308
AC_SUBST(CRYPTO_LIBS)

0 commit comments

Comments
 (0)