Skip to content

Commit cb7b7fd

Browse files
committed
Add Mbed-TLS crypto backend
Mbed-TLS is a tiny TLS implementation designed for embedded environment which can greatly reduce the disk space requirement compared to OpenSSL. While we already have crypto_kernel for this purpose and Mbed-TLS lacking hash/cipher support can cause reduced functionality, there're situations where AF_ALG is not available but we're fine with limited scenarios like LUKS2 only.
1 parent 4daf8ef commit cb7b7fd

File tree

7 files changed

+568
-6
lines changed

7 files changed

+568
-6
lines changed

.gitlab/ci/compilation-clang.gitlab-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ test-scan-build-backends:
3939
"gcrypt",
4040
"nss",
4141
"kernel",
42-
"nettle"
42+
"nettle",
43+
"mbedtls"
4344
]
4445
rules:
4546
- changes:
4647
- lib/crypto_backend/*
4748
script:
48-
- DEBIAN_FRONTEND=noninteractive apt-get -yq install libgcrypt20-dev libnss3-dev nettle-dev
49+
- DEBIAN_FRONTEND=noninteractive apt-get -yq install libgcrypt20-dev libnss3-dev nettle-dev libmbedtls-dev
4950
- ./autogen.sh
5051
- echo "Configuring with crypto backend $BACKENDS"
5152
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} -V ./configure CFLAGS="-g -O0" --with-crypto_backend=$BACKENDS

.gitlab/ci/compilation-gcc.gitlab-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ test-gcc-fanalyzer-backends:
3939
"gcrypt",
4040
"nss",
4141
"kernel",
42-
"nettle"
42+
"nettle",
43+
"mbedtls"
4344
]
4445
rules:
4546
- changes:
4647
- lib/crypto_backend/*
4748
script:
48-
- DEBIAN_FRONTEND=noninteractive apt-get -yq install libgcrypt20-dev libnss3-dev nettle-dev
49+
- DEBIAN_FRONTEND=noninteractive apt-get -yq install libgcrypt20-dev libnss3-dev nettle-dev libmbedtls-dev
4950
- export CFLAGS="-Wall -Werror -g -O0 -fanalyzer -fdiagnostics-path-format=separate-events"
5051
- ./autogen.sh
5152
- echo "Configuring with crypto backend $BACKENDS"

configure.ac

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,22 @@ AC_DEFUN([CONFIGURE_NETTLE], [
399399
NO_FIPS([])
400400
])
401401
402+
AC_DEFUN([CONFIGURE_MBEDTLS], [
403+
AC_CHECK_HEADERS(mbedtls/version.h,,
404+
[AC_MSG_ERROR([You need mbedTLS cryptographic library.])])
405+
406+
saved_LIBS=$LIBS
407+
AC_CHECK_LIB(mbedcrypto, mbedtls_md_init,,
408+
[AC_MSG_ERROR([You need mbedTLS cryptographic library.])])
409+
CRYPTO_LIBS=$LIBS
410+
LIBS=$saved_LIBS
411+
412+
CRYPTO_STATIC_LIBS=$CRYPTO_LIBS
413+
use_internal_pbkdf2=1
414+
use_internal_argon2=1
415+
NO_FIPS([])
416+
])
417+
402418
dnl ==========================================================================
403419
saved_LIBS=$LIBS
404420
@@ -481,7 +497,7 @@ fi
481497
482498
dnl Crypto backend configuration.
483499
AC_ARG_WITH([crypto_backend],
484-
AS_HELP_STRING([--with-crypto_backend=BACKEND], [crypto backend (gcrypt/openssl/nss/kernel/nettle) [openssl]]),
500+
AS_HELP_STRING([--with-crypto_backend=BACKEND], [crypto backend (gcrypt/openssl/nss/kernel/nettle/mbedtls) [openssl]]),
485501
[], [with_crypto_backend=openssl])
486502
487503
dnl Kernel crypto API backend needed for benchmark and tcrypt
@@ -501,13 +517,15 @@ case $with_crypto_backend in
501517
nss) CONFIGURE_NSS([]) ;;
502518
kernel) CONFIGURE_KERNEL([]) ;;
503519
nettle) CONFIGURE_NETTLE([]) ;;
520+
mbedtls) CONFIGURE_MBEDTLS([]) ;;
504521
*) AC_MSG_ERROR([Unknown crypto backend.]) ;;
505522
esac
506523
AM_CONDITIONAL(CRYPTO_BACKEND_GCRYPT, test "$with_crypto_backend" = "gcrypt")
507524
AM_CONDITIONAL(CRYPTO_BACKEND_OPENSSL, test "$with_crypto_backend" = "openssl")
508525
AM_CONDITIONAL(CRYPTO_BACKEND_NSS, test "$with_crypto_backend" = "nss")
509526
AM_CONDITIONAL(CRYPTO_BACKEND_KERNEL, test "$with_crypto_backend" = "kernel")
510527
AM_CONDITIONAL(CRYPTO_BACKEND_NETTLE, test "$with_crypto_backend" = "nettle")
528+
AM_CONDITIONAL(CRYPTO_BACKEND_MBEDTLS, test "$with_crypto_backend" = "mbedtls")
511529
512530
AM_CONDITIONAL(CRYPTO_INTERNAL_PBKDF2, test $use_internal_pbkdf2 = 1)
513531
AC_DEFINE_UNQUOTED(USE_INTERNAL_PBKDF2, [$use_internal_pbkdf2], [Use internal PBKDF2])

lib/crypto_backend/Makemodule.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ endif
3131
if CRYPTO_BACKEND_NETTLE
3232
libcrypto_backend_la_SOURCES += lib/crypto_backend/crypto_nettle.c
3333
endif
34+
if CRYPTO_BACKEND_MBEDTLS
35+
libcrypto_backend_la_SOURCES += lib/crypto_backend/crypto_mbedtls.c
36+
endif
3437

3538
if CRYPTO_INTERNAL_PBKDF2
3639
libcrypto_backend_la_SOURCES += lib/crypto_backend/pbkdf2_generic.c

0 commit comments

Comments
 (0)