Skip to content

Commit

Permalink
CXL TSP: Add support for 2nd session in secret sample lib.
Browse files Browse the repository at this point in the history
Signed-off-by: Jiewen Yao <[email protected]>
  • Loading branch information
jyao1 committed Oct 15, 2024
1 parent 6d092c5 commit 8a5463d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
45 changes: 41 additions & 4 deletions os_stub/spdm_device_secret_lib_sample/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,13 @@ uint8_t m_libspdm_bin_str0[0x11] = {
0x64, 0x65, 0x72, 0x69, 0x76, 0x65, 0x64,
};

uint8_t m_cxl_tsp_2nd_session_psk[4][0x20] = {
LIBSPDM_CXL_TSP_2ND_SESSION_0_PSK_DATA_STRING,
LIBSPDM_CXL_TSP_2ND_SESSION_1_PSK_DATA_STRING,
LIBSPDM_CXL_TSP_2ND_SESSION_2_PSK_DATA_STRING,
LIBSPDM_CXL_TSP_2ND_SESSION_3_PSK_DATA_STRING,
};

bool libspdm_psk_handshake_secret_hkdf_expand(
spdm_version_number_t spdm_version,
uint32_t base_hash_algo,
Expand All @@ -2063,11 +2070,26 @@ bool libspdm_psk_handshake_secret_hkdf_expand(
if (psk_hint_size == 0) {
psk = LIBSPDM_TEST_PSK_DATA_STRING;
psk_size = sizeof(LIBSPDM_TEST_PSK_DATA_STRING);
} else if ((strcmp((const char *)psk_hint, LIBSPDM_TEST_PSK_HINT_STRING) ==
0) &&
} else if ((strcmp((const char *)psk_hint, LIBSPDM_TEST_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(LIBSPDM_TEST_PSK_HINT_STRING))) {
psk = LIBSPDM_TEST_PSK_DATA_STRING;
psk_size = sizeof(LIBSPDM_TEST_PSK_DATA_STRING);
} else if ((strcmp((const char *)psk_hint, CXL_TSP_2ND_SESSION_0_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(CXL_TSP_2ND_SESSION_0_PSK_HINT_STRING))) {
psk = m_cxl_tsp_2nd_session_psk[0];
psk_size = sizeof(m_cxl_tsp_2nd_session_psk[0]);
} else if ((strcmp((const char *)psk_hint, CXL_TSP_2ND_SESSION_1_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(CXL_TSP_2ND_SESSION_1_PSK_HINT_STRING))) {
psk = m_cxl_tsp_2nd_session_psk[1];
psk_size = sizeof(m_cxl_tsp_2nd_session_psk[1]);
} else if ((strcmp((const char *)psk_hint, CXL_TSP_2ND_SESSION_2_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(CXL_TSP_2ND_SESSION_2_PSK_HINT_STRING))) {
psk = m_cxl_tsp_2nd_session_psk[2];
psk_size = sizeof(m_cxl_tsp_2nd_session_psk[2]);
} else if ((strcmp((const char *)psk_hint, CXL_TSP_2ND_SESSION_3_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(CXL_TSP_2ND_SESSION_3_PSK_HINT_STRING))) {
psk = m_cxl_tsp_2nd_session_psk[3];
psk_size = sizeof(m_cxl_tsp_2nd_session_psk[3]);
} else {
return false;
}
Expand Down Expand Up @@ -2110,11 +2132,26 @@ bool libspdm_psk_master_secret_hkdf_expand(
if (psk_hint_size == 0) {
psk = LIBSPDM_TEST_PSK_DATA_STRING;
psk_size = sizeof(LIBSPDM_TEST_PSK_DATA_STRING);
} else if ((strcmp((const char *)psk_hint, LIBSPDM_TEST_PSK_HINT_STRING) ==
0) &&
} else if ((strcmp((const char *)psk_hint, LIBSPDM_TEST_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(LIBSPDM_TEST_PSK_HINT_STRING))) {
psk = LIBSPDM_TEST_PSK_DATA_STRING;
psk_size = sizeof(LIBSPDM_TEST_PSK_DATA_STRING);
} else if ((strcmp((const char *)psk_hint, CXL_TSP_2ND_SESSION_0_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(CXL_TSP_2ND_SESSION_0_PSK_HINT_STRING))) {
psk = m_cxl_tsp_2nd_session_psk[0];
psk_size = sizeof(m_cxl_tsp_2nd_session_psk[0]);
} else if ((strcmp((const char *)psk_hint, CXL_TSP_2ND_SESSION_1_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(CXL_TSP_2ND_SESSION_1_PSK_HINT_STRING))) {
psk = m_cxl_tsp_2nd_session_psk[1];
psk_size = sizeof(m_cxl_tsp_2nd_session_psk[1]);
} else if ((strcmp((const char *)psk_hint, CXL_TSP_2ND_SESSION_2_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(CXL_TSP_2ND_SESSION_2_PSK_HINT_STRING))) {
psk = m_cxl_tsp_2nd_session_psk[2];
psk_size = sizeof(m_cxl_tsp_2nd_session_psk[2]);
} else if ((strcmp((const char *)psk_hint, CXL_TSP_2ND_SESSION_3_PSK_HINT_STRING) == 0) &&
(psk_hint_size == sizeof(CXL_TSP_2ND_SESSION_3_PSK_HINT_STRING))) {
psk = m_cxl_tsp_2nd_session_psk[3];
psk_size = sizeof(m_cxl_tsp_2nd_session_psk[3]);
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2022 DMTF. All rights reserved.
* Copyright 2021-2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand All @@ -25,6 +25,7 @@
#include "hal/library/requester/psklib.h"
#include "hal/library/debuglib.h"
#include "hal/library/cryptlib.h"
#include "industry_standard/cxl_tsp.h"

#define LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER 4
#define LIBSPDM_MEASUREMENT_BLOCK_NUMBER (LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER /*Index - 1~4*/ + \
Expand All @@ -39,6 +40,11 @@
#define LIBSPDM_TEST_PSK_DATA_STRING "TestPskData"
#define LIBSPDM_TEST_PSK_HINT_STRING "TestPskHint"

#define LIBSPDM_CXL_TSP_2ND_SESSION_0_PSK_DATA_STRING "CxlTsp_2ndSess0_Psk"
#define LIBSPDM_CXL_TSP_2ND_SESSION_1_PSK_DATA_STRING "CxlTsp_2ndSess1_Psk"
#define LIBSPDM_CXL_TSP_2ND_SESSION_2_PSK_DATA_STRING "CxlTsp_2ndSess2_Psk"
#define LIBSPDM_CXL_TSP_2ND_SESSION_3_PSK_DATA_STRING "CxlTsp_2ndSess3_Psk"

#define LIBSPDM_TEST_CERT_MAXINT16 1
#define LIBSPDM_TEST_CERT_MAXUINT16 2
#define LIBSPDM_LIBSPDM_TEST_CERT_MAXUINT16_LARGER 3
Expand Down

0 comments on commit 8a5463d

Please sign in to comment.