Skip to content

Commit 2004aab

Browse files
author
coder-sageres
committed
Remove deprecated interfaces and internal interfaces, and use modern OpenSSL interfaces
Signed-off-by: coder-sageres <[email protected]>
1 parent 22d10f4 commit 2004aab

Some content is hidden

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

74 files changed

+2138
-25494
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,11 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
693693
set(CMAKE_EXE_LINKER_FLAGS "")
694694

695695
set(CMAKE_C_LINK_EXECUTABLE "")
696+
elseif(TOOLCHAIN STREQUAL "NONE")
697+
# Use native toolchain with group linking for static libraries
698+
set(CMAKE_LINKER gcc)
699+
set(CMAKE_EXE_LINKER_FLAGS "-no-pie")
700+
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group")
696701
endif()
697702

698703
if(NOT TOOLCHAIN STREQUAL "NIOS2_GCC")

library/spdm_crypt_lib/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ target_sources(spdm_crypt_lib
3838
fips/libspdm_selftest_mldsa_vec.c
3939
fips/libspdm_selftest_slhdsa.c
4040
fips/libspdm_selftest_slhdsa_vec.c
41-
)
41+
)
42+
43+
# Link to cryptlib implementation
44+
if(TARGET cryptlib_openssl)
45+
target_link_libraries(spdm_crypt_lib INTERFACE cryptlib_openssl)
46+
elseif(TARGET cryptlib_mbedtls)
47+
target_link_libraries(spdm_crypt_lib INTERFACE cryptlib_mbedtls)
48+
endif()

os_stub/cryptlib_openssl/CMakeLists.txt

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ target_include_directories(cryptlib_openssl
99
${LIBSPDM_DIR}/os_stub/include
1010
${LIBSPDM_DIR}/os_stub/cryptlib_openssl
1111
${LIBSPDM_DIR}/os_stub/openssllib/include
12-
${LIBSPDM_DIR}/os_stub/openssllib/openssl_gen
13-
${LIBSPDM_DIR}/os_stub/openssllib/openssl/include
14-
${LIBSPDM_DIR}/os_stub/openssllib/openssl/crypto/include
15-
${LIBSPDM_DIR}/os_stub/openssllib/openssl
1612
)
1713

1814
target_sources(cryptlib_openssl
@@ -47,25 +43,33 @@ target_sources(cryptlib_openssl
4743
pk/x509.c
4844
pk/x509_pqc.c
4945
rand/rand.c
46+
rsa_context.c
47+
pqc_context.c
5048
sys_call/crt_wrapper_host.c
5149
)
5250

5351
target_compile_options(cryptlib_openssl PRIVATE ${OPENSSL_FLAGS})
5452

55-
if(ARCH STREQUAL "x64")
56-
target_compile_options(cryptlib_openssl PRIVATE -DLIBSPDM_CPU_X64)
57-
elseif(ARCH STREQUAL "ia32")
58-
target_compile_options(cryptlib_openssl PRIVATE -DLIBSPDM_CPU_IA32)
59-
elseif(ARCH STREQUAL "aarch64")
60-
target_compile_options(cryptlib_openssl PRIVATE -DLIBSPDM_CPU_AARCH64)
61-
elseif(ARCH STREQUAL "riscv32")
62-
target_compile_options(cryptlib_openssl PRIVATE -DLIBSPDM_CPU_RISCV32)
63-
elseif(ARCH STREQUAL "riscv64")
64-
target_compile_options(cryptlib_openssl PRIVATE -DLIBSPDM_CPU_RISCV64)
65-
elseif((ARCH STREQUAL "arm") OR (ARCH STREQUAL "aarch64"))
66-
target_compile_options(cryptlib_openssl PRIVATE -DLIBSPDM_CPU_ARM)
67-
elseif(ARCH STREQUAL "loongarch64")
68-
target_compile_options(cryptlib_openssl PRIVATE -DLIBSPDM_CPU_LOONGARCH64)
69-
else()
70-
message(FATAL_ERROR "Unknown ARCH")
71-
endif()
53+
# Suppress deprecated warnings for OpenSSL deprecated APIs
54+
#
55+
# Why suppress instead of fixing:
56+
# 1. EC Key Management: libspdm_ec_set_pub_key/libspdm_ec_set_priv_key use deprecated EC_KEY APIs
57+
# as fallback when modern EVP_PKEY_set* methods fail. This ensures compatibility when keys
58+
# are set separately (public first, then private).
59+
#
60+
# 2. SM2 Implementation: os_stub/cryptlib_openssl/pk/sm2.c uses deprecated EC_KEY APIs throughout.
61+
# Full migration to modern APIs requires significant refactoring.
62+
#
63+
# 3. FIPS Mode: libspdm_ecdsa_sign_ex uses deprecated APIs for custom random number injection,
64+
# which is required for FIPS testing (only compiled when LIBSPDM_FIPS_MODE is enabled).
65+
#
66+
# Cross-platform suppression:
67+
# - GCC/Clang (Linux/macOS): -Wno-deprecated-declarations
68+
# - MSVC (Windows): /wd4996
69+
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
70+
target_compile_options(cryptlib_openssl PRIVATE -Wno-deprecated-declarations)
71+
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
72+
target_compile_options(cryptlib_openssl PRIVATE /wd4996)
73+
endif()
74+
75+
target_link_libraries(cryptlib_openssl PUBLIC openssllib memlib)

os_stub/cryptlib_openssl/der/der.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#include <openssl/x509.h>
1313
#include <openssl/evp.h>
1414
#include <openssl/decoder.h>
15+
#include "rsa_context.h"
1516

1617
#if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
18+
1719
/**
1820
* Retrieve the RSA Public key from the DER key data.
1921
*
@@ -39,6 +41,7 @@ bool libspdm_rsa_get_public_key_from_der(const uint8_t *der_data,
3941
{
4042
bool status;
4143
BIO *der_bio;
44+
EVP_PKEY *pkey;
4245

4346
/* Check input parameters.*/
4447

@@ -47,6 +50,7 @@ bool libspdm_rsa_get_public_key_from_der(const uint8_t *der_data,
4750
}
4851

4952
status = false;
53+
pkey = NULL;
5054

5155
/* Read DER data.*/
5256

@@ -59,11 +63,25 @@ bool libspdm_rsa_get_public_key_from_der(const uint8_t *der_data,
5963
goto done;
6064
}
6165

62-
/* Retrieve RSA Public key from DER data.*/
63-
64-
*rsa_context = d2i_RSA_PUBKEY_bio(der_bio, NULL);
65-
if (*rsa_context != NULL) {
66+
/* Retrieve RSA Public key from DER data as EVP_PKEY.*/
67+
pkey = d2i_PUBKEY_bio(der_bio, NULL);
68+
if (pkey == NULL) {
69+
goto done;
70+
}
71+
if (EVP_PKEY_base_id(pkey) != EVP_PKEY_RSA) {
72+
goto done;
73+
}
74+
{
75+
libspdm_rsa_ctx_evp_t *ctx;
76+
ctx = (libspdm_rsa_ctx_evp_t *)allocate_pool(sizeof(libspdm_rsa_ctx_evp_t));
77+
if (ctx == NULL) {
78+
goto done;
79+
}
80+
libspdm_zero_mem(ctx, sizeof(*ctx));
81+
ctx->pkey = pkey;
82+
*rsa_context = (void *)ctx;
6683
status = true;
84+
pkey = NULL; /* ownership moved */
6785
}
6886

6987
done:
@@ -199,9 +217,18 @@ bool libspdm_ecd_get_public_key_from_der(const uint8_t *der_data,
199217
}
200218
type = EVP_PKEY_id(pkey);
201219
if ((type != EVP_PKEY_ED25519) && (type != EVP_PKEY_ED448)) {
220+
EVP_PKEY_free(pkey);
221+
goto done;
222+
}
223+
224+
/* Create double pointer structure for EdDSA context (compatible with libspdm_ecd_new_by_nid) */
225+
EVP_PKEY **ecd_context_ptr = malloc(sizeof(EVP_PKEY *));
226+
if (ecd_context_ptr == NULL) {
227+
EVP_PKEY_free(pkey);
202228
goto done;
203229
}
204-
*ecd_context = pkey;
230+
*ecd_context_ptr = pkey;
231+
*ecd_context = ecd_context_ptr;
205232
status = true;
206233

207234
done:

0 commit comments

Comments
 (0)