Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Options:
--enable-eddsa Enable support for EDDSA (default detect)
--enable-mldsa Enable support for ML-DSA (default detect)
--enable-mlkem Enable support for ML-KEM (default detect)
--enable-sha3 Enable support for SHA3 (default detect)
--disable-visibility Disable hidden visibilty link mode [enabled]
--with-crypto-backend Select crypto backend (openssl|botan)
--with-openssl=PATH Specify prefix of path of OpenSSL
Expand Down
21 changes: 21 additions & 0 deletions cmake/modules/CompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ if(WITH_CRYPTO_BACKEND STREQUAL "botan")
message(STATUS "Botan: Support for GOST is disabled")
endif(ENABLE_GOST)

# Botan has supported SHA3 since well before its minimum required
# version, so no version detection is needed.
set(WITH_SHA3 1)
message(STATUS "Botan: SHA3 is supported")

if(ENABLE_FIPS)
message(FATAL_ERROR "Botan does not support FIPS 140-2 mode")
endif(ENABLE_FIPS)
Expand Down Expand Up @@ -412,6 +417,22 @@ elseif(WITH_CRYPTO_BACKEND STREQUAL "openssl")
message(STATUS "OpenSSL: Support for ML-KEM is disabled")
endif(ENABLE_MLKEM)

# acx_openssl_sha3.m4
set(testfile ${CMAKE_SOURCE_DIR}/cmake/modules/tests/test_openssl_sha3.c)
try_run(RUN_SHA3 COMPILE_RESULT
"${CMAKE_BINARY_DIR}/prebuild_santity_tests" ${testfile}
LINK_LIBRARIES ${CRYPTO_LIBS}
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES=${CRYPTO_INCLUDES}"
)
if(COMPILE_RESULT AND RUN_SHA3 EQUAL 0)
set(WITH_SHA3 1)
message(STATUS "OpenSSL: Found SHA3")
else()
set(error_msg "OpenSSL: Cannot find SHA3! OpenSSL library has no SHA3 support (requires OpenSSL >= 1.1.1 or LibreSSL >= 3.8.0)!")
message(FATAL_ERROR ${error_msg})
endif()

# acx_openssl_gost.m4
if(ENABLE_GOST)
set(testfile ${CMAKE_SOURCE_DIR}/cmake/modules/tests/test_openssl_gost.c)
Expand Down
16 changes: 16 additions & 0 deletions cmake/modules/tests/test_openssl_sha3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2026 SoftHSMv2 contributors
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <openssl/evp.h>
int main()
{
const EVP_MD *md224 = EVP_sha3_224();
const EVP_MD *md256 = EVP_sha3_256();
const EVP_MD *md384 = EVP_sha3_384();
const EVP_MD *md512 = EVP_sha3_512();
if (md224 == NULL || md256 == NULL || md384 == NULL || md512 == NULL)
return 1;
return 0;
}
3 changes: 3 additions & 0 deletions config.h.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
/* Compile with ML-KEM support */
#cmakedefine WITH_ML_KEM @WITH_ML_KEM@

/* Compile with SHA3 support */
#cmakedefine WITH_SHA3 @WITH_SHA3@
Comment thread
bukka marked this conversation as resolved.

/* Compile with FIPS 140-2 mode */
#cmakedefine WITH_FIPS @WITH_FIPS@

Expand Down
37 changes: 37 additions & 0 deletions m4/acx_crypto_backend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[
[enable_mlkem="detect"]
)

# Add SHA3 check

AC_ARG_ENABLE(sha3,
AS_HELP_STRING([--enable-sha3],
[Enable support for SHA3 (default detect)]
),
[enable_sha3="${enableval}"],
[enable_sha3="detect"]
)

# Second check for the FIPS 140-2 mode

AC_ARG_ENABLE(fips,
Expand Down Expand Up @@ -138,6 +148,14 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[
detect-no) enable_mlkem="no";;
esac

case "${enable_sha3}" in
yes|detect) ACX_OPENSSL_SHA3;;
esac
case "${enable_sha3}-${have_lib_openssl_sha3_support}" in
yes-no) AC_MSG_ERROR([OpenSSL library has no SHA3 support (requires OpenSSL >= 1.1.1 or LibreSSL >= 3.8.0)]);;
detect-*) enable_sha3="${have_lib_openssl_sha3_support}";;
esac

case "${enable_gost}-${enable_fips}" in
yes-yes) AC_MSG_ERROR([GOST is not FIPS approved]);;
yes-no|detect-no) ACX_OPENSSL_GOST;;
Expand Down Expand Up @@ -212,6 +230,12 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[
AC_MSG_ERROR([Botan does not support ML-KEM])
fi

# Botan has supported SHA3 since well before its minimum required
# version, so no version detection is needed.
case "${enable_sha3}" in
detect) enable_sha3="yes";;
esac

case "${enable_gost}" in
yes|detect) ACX_BOTAN_GOST;;
esac
Expand Down Expand Up @@ -303,6 +327,19 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[
fi
AM_CONDITIONAL([WITH_ML_KEM], [test "x${enable_mlkem}" = "xyes"])

AC_MSG_CHECKING(for SHA3 support)
if test "x${enable_sha3}" = "xyes"; then
AC_MSG_RESULT(yes)
AC_DEFINE_UNQUOTED(
[WITH_SHA3],
[],
[Compile with SHA3 support]
)
else
AC_MSG_RESULT(no)
fi
AM_CONDITIONAL([WITH_SHA3], [test "x${enable_sha3}" = "xyes"])


AC_SUBST(CRYPTO_INCLUDES)
AC_SUBST(CRYPTO_LIBS)
Expand Down
36 changes: 36 additions & 0 deletions m4/acx_openssl_sha3.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
AC_DEFUN([ACX_OPENSSL_SHA3],[
tmp_CPPFLAGS=$CPPFLAGS
tmp_LIBS=$LIBS

CPPFLAGS="$CPPFLAGS $CRYPTO_INCLUDES"
LIBS="$CRYPTO_LIBS $LIBS"

AC_LANG_PUSH([C])
AC_CACHE_CHECK([for OpenSSL SHA3 support], [acx_cv_lib_openssl_sha3_support],[
acx_cv_lib_openssl_sha3_support=no
AC_LINK_IFELSE([
AC_LANG_SOURCE([[
#include <openssl/evp.h>
int main()
{
const EVP_MD *md224 = EVP_sha3_224();
const EVP_MD *md256 = EVP_sha3_256();
const EVP_MD *md384 = EVP_sha3_384();
const EVP_MD *md512 = EVP_sha3_512();
if (md224 == NULL || md256 == NULL || md384 == NULL || md512 == NULL)
return 1;
return 0;
}
]])
],[
acx_cv_lib_openssl_sha3_support=yes
],[
acx_cv_lib_openssl_sha3_support=no
])
])
AC_LANG_POP([C])

CPPFLAGS=$tmp_CPPFLAGS
LIBS=$tmp_LIBS
have_lib_openssl_sha3_support="${acx_cv_lib_openssl_sha3_support}"
])
24 changes: 24 additions & 0 deletions src/bin/dump/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ void fill_CKM_table(std::map<unsigned long, std::string> &t)
t[CKM_DSA_SHA256] = "CKM_DSA_SHA256";
t[CKM_DSA_SHA384] = "CKM_DSA_SHA384";
t[CKM_DSA_SHA512] = "CKM_DSA_SHA512";
t[CKM_DSA_SHA3_224] = "CKM_DSA_SHA3_224";
t[CKM_DSA_SHA3_256] = "CKM_DSA_SHA3_256";
t[CKM_DSA_SHA3_384] = "CKM_DSA_SHA3_384";
t[CKM_DSA_SHA3_512] = "CKM_DSA_SHA3_512";
t[CKM_DH_PKCS_KEY_PAIR_GEN] = "CKM_DH_PKCS_KEY_PAIR_GEN";
t[CKM_DH_PKCS_DERIVE] = "CKM_DH_PKCS_DERIVE";
t[CKM_X9_42_DH_KEY_PAIR_GEN] = "CKM_X9_42_DH_KEY_PAIR_GEN";
Expand All @@ -192,6 +196,14 @@ void fill_CKM_table(std::map<unsigned long, std::string> &t)
t[CKM_SHA512_RSA_PKCS_PSS] = "CKM_SHA512_RSA_PKCS_PSS";
t[CKM_SHA224_RSA_PKCS] = "CKM_SHA224_RSA_PKCS";
t[CKM_SHA224_RSA_PKCS_PSS] = "CKM_SHA224_RSA_PKCS_PSS";
t[CKM_SHA3_224_RSA_PKCS] = "CKM_SHA3_224_RSA_PKCS";
t[CKM_SHA3_256_RSA_PKCS] = "CKM_SHA3_256_RSA_PKCS";
t[CKM_SHA3_384_RSA_PKCS] = "CKM_SHA3_384_RSA_PKCS";
t[CKM_SHA3_512_RSA_PKCS] = "CKM_SHA3_512_RSA_PKCS";
t[CKM_SHA3_224_RSA_PKCS_PSS] = "CKM_SHA3_224_RSA_PKCS_PSS";
t[CKM_SHA3_256_RSA_PKCS_PSS] = "CKM_SHA3_256_RSA_PKCS_PSS";
t[CKM_SHA3_384_RSA_PKCS_PSS] = "CKM_SHA3_384_RSA_PKCS_PSS";
t[CKM_SHA3_512_RSA_PKCS_PSS] = "CKM_SHA3_512_RSA_PKCS_PSS";
t[CKM_SHA512_224] = "CKM_SHA512_224";
t[CKM_SHA512_224_HMAC] = "CKM_SHA512_224_HMAC";
t[CKM_SHA512_224_HMAC_GENERAL] = "CKM_SHA512_224_HMAC_GENERAL";
Expand Down Expand Up @@ -262,8 +274,16 @@ void fill_CKM_table(std::map<unsigned long, std::string> &t)
t[CKM_SHA384_HMAC] = "CKM_SHA384_HMAC";
t[CKM_SHA384_HMAC_GENERAL] = "CKM_SHA384_HMAC_GENERAL";
t[CKM_SHA512] = "CKM_SHA512";
t[CKM_SHA3_224] = "CKM_SHA3_224";
t[CKM_SHA3_256] = "CKM_SHA3_256";
t[CKM_SHA3_384] = "CKM_SHA3_384";
t[CKM_SHA3_512] = "CKM_SHA3_512";
t[CKM_SHA512_HMAC] = "CKM_SHA512_HMAC";
t[CKM_SHA512_HMAC_GENERAL] = "CKM_SHA512_HMAC_GENERAL";
t[CKM_SHA3_224_HMAC] = "CKM_SHA3_224_HMAC";
t[CKM_SHA3_256_HMAC] = "CKM_SHA3_256_HMAC";
t[CKM_SHA3_384_HMAC] = "CKM_SHA3_384_HMAC";
t[CKM_SHA3_512_HMAC] = "CKM_SHA3_512_HMAC";
t[CKM_SECURID_KEY_GEN] = "CKM_SECURID_KEY_GEN";
t[CKM_SECURID] = "CKM_SECURID";
t[CKM_HOTP_KEY_GEN] = "CKM_HOTP_KEY_GEN";
Expand Down Expand Up @@ -413,6 +433,10 @@ void fill_CKM_table(std::map<unsigned long, std::string> &t)
t[CKM_ECDSA_SHA256] = "CKM_ECDSA_SHA256";
t[CKM_ECDSA_SHA384] = "CKM_ECDSA_SHA384";
t[CKM_ECDSA_SHA512] = "CKM_ECDSA_SHA512";
t[CKM_ECDSA_SHA3_224] = "CKM_ECDSA_SHA3_224";
t[CKM_ECDSA_SHA3_256] = "CKM_ECDSA_SHA3_256";
t[CKM_ECDSA_SHA3_384] = "CKM_ECDSA_SHA3_384";
t[CKM_ECDSA_SHA3_512] = "CKM_ECDSA_SHA3_512";
t[CKM_ECDH1_DERIVE] = "CKM_ECDH1_DERIVE";
t[CKM_ECDH1_COFACTOR_DERIVE] = "CKM_ECDH1_COFACTOR_DERIVE";
t[CKM_ECMQV_DERIVE] = "CKM_ECMQV_DERIVE";
Expand Down
8 changes: 8 additions & 0 deletions src/lib/P11Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,10 @@ CK_RV P11AttrCheckValue::updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pV
case CKK_SHA256_HMAC:
case CKK_SHA384_HMAC:
case CKK_SHA512_HMAC:
case CKK_SHA3_224_HMAC:
case CKK_SHA3_256_HMAC:
case CKK_SHA3_384_HMAC:
case CKK_SHA3_512_HMAC:
key.setKeyBits(keybits);
key.setBitLen(keybits.size() * 8);
checkValue = key.getKeyCheckValue();
Expand Down Expand Up @@ -1031,6 +1035,10 @@ CK_RV P11AttrValue::updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue,
case CKK_SHA256_HMAC:
case CKK_SHA384_HMAC:
case CKK_SHA512_HMAC:
case CKK_SHA3_224_HMAC:
case CKK_SHA3_256_HMAC:
case CKK_SHA3_384_HMAC:
case CKK_SHA3_512_HMAC:
key.setKeyBits(plaintext);
key.setBitLen(plaintext.size() * 8);
checkValue = key.getKeyCheckValue();
Expand Down
Loading
Loading