Skip to content

Commit 9c0deab

Browse files
Xiaohanjllljyao1
Xiaohanjlll
authored andcommitted
Add unit test for SPDM 1.3 algorithms
Signed-off-by: Xiaohanjlll <[email protected]>
1 parent c5f9ca7 commit 9c0deab

File tree

2 files changed

+369
-0
lines changed

2 files changed

+369
-0
lines changed

unit_test/test_spdm_requester/negotiate_algorithms.c

+171
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ typedef struct {
2727
static size_t m_libspdm_local_buffer_size;
2828
static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
2929

30+
static uint8_t m_connection_other_params_support;
31+
3032
static libspdm_return_t libspdm_requester_negotiate_algorithms_test_send_message(
3133
void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
3234
{
@@ -108,6 +110,7 @@ static libspdm_return_t libspdm_requester_negotiate_algorithms_test_send_message
108110
case 0x21:
109111
return LIBSPDM_STATUS_SUCCESS;
110112
case 0x22:
113+
case 0x23:
111114
return LIBSPDM_STATUS_SUCCESS;
112115
default:
113116
return LIBSPDM_STATUS_SEND_FAIL;
@@ -1315,6 +1318,40 @@ static libspdm_return_t libspdm_requester_negotiate_algorithm_test_receive_messa
13151318
spdm_response, response_size, response);
13161319
}
13171320
return LIBSPDM_STATUS_SUCCESS;
1321+
1322+
case 0x23:
1323+
{
1324+
spdm_algorithms_response_t *spdm_response;
1325+
size_t spdm_response_size;
1326+
size_t transport_header_size;
1327+
1328+
spdm_response_size = sizeof(spdm_algorithms_response_t);
1329+
transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1330+
spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1331+
1332+
libspdm_zero_mem(spdm_response, spdm_response_size);
1333+
spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
1334+
spdm_response->header.request_response_code = SPDM_ALGORITHMS;
1335+
spdm_response->header.param1 = 0;
1336+
spdm_response->header.param2 = 0;
1337+
spdm_response->length = sizeof(spdm_algorithms_response_t);
1338+
spdm_response->measurement_specification_sel =
1339+
SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1340+
spdm_response->measurement_hash_algo =
1341+
m_libspdm_use_measurement_hash_algo;
1342+
spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
1343+
spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
1344+
spdm_response->ext_asym_sel_count = 0;
1345+
spdm_response->ext_hash_sel_count = 0;
1346+
spdm_response->other_params_selection = m_connection_other_params_support;
1347+
1348+
libspdm_transport_test_encode_message(spdm_context, NULL, false,
1349+
false, spdm_response_size,
1350+
spdm_response,
1351+
response_size, response);
1352+
}
1353+
return LIBSPDM_STATUS_SUCCESS;
1354+
13181355
default:
13191356
return LIBSPDM_STATUS_RECEIVE_FAIL;
13201357
}
@@ -1670,6 +1707,139 @@ static void libspdm_test_requester_negotiate_algorithms_case34(void **state)
16701707
{
16711708
}
16721709

1710+
/**
1711+
* Test 35: MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP value calculation
1712+
* +---------------+--------------------------+--------------------+
1713+
* | MULTI_KEY_CAP | RequesterMultiKeyConnSel | MULTI_KEY_CONN_REQ |
1714+
* +---------------+--------------------------+--------------------+
1715+
* | 00b | 0 | false |
1716+
* ----------------------------------------------------------------
1717+
* | 00b | 1 | invalid |
1718+
* ----------------------------------------------------------------
1719+
* | 01b | 0 | invalid |
1720+
* ----------------------------------------------------------------
1721+
* | 01b | 1 | true |
1722+
* ----------------------------------------------------------------
1723+
* | 10b | 0 | false |
1724+
* ----------------------------------------------------------------
1725+
* | 10b | 1 | true |
1726+
* +---------------+--------------------------+--------------------+
1727+
* | MULTI_KEY_CAP | ResponderMultiKeyConn | MULTI_KEY_CONN_RSP |
1728+
* +---------------+--------------------------+--------------------+
1729+
* | 00b | 0 | false |
1730+
* ----------------------------------------------------------------
1731+
* | 00b | 1 | invalid |
1732+
* ----------------------------------------------------------------
1733+
* | 01b | 0 | invalid |
1734+
* ----------------------------------------------------------------
1735+
* | 01b | 1 | true |
1736+
* ----------------------------------------------------------------
1737+
* | 10b | 0 | false |
1738+
* ----------------------------------------------------------------
1739+
* | 10b | 1 | true |
1740+
* ----------------------------------------------------------------
1741+
**/
1742+
static void libspdm_test_requester_negotiate_algorithms_case35(void **state)
1743+
{
1744+
libspdm_return_t status;
1745+
libspdm_test_context_t *spdm_test_context;
1746+
libspdm_context_t *spdm_context;
1747+
1748+
spdm_test_context = *state;
1749+
spdm_context = spdm_test_context->spdm_context;
1750+
spdm_test_context->case_id = 0x23;
1751+
spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1752+
SPDM_VERSION_NUMBER_SHIFT_BIT;
1753+
spdm_context->local_context.algorithm.measurement_hash_algo =
1754+
m_libspdm_use_measurement_hash_algo;
1755+
spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1756+
spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1757+
1758+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
1759+
libspdm_reset_message_a(spdm_context);
1760+
1761+
spdm_context->connection_info.capability.flags = 0;
1762+
spdm_context->local_context.capability.flags = 0;
1763+
spdm_context->local_context.algorithm.other_params_support = 0;
1764+
m_connection_other_params_support = 0;
1765+
1766+
status = libspdm_negotiate_algorithms(spdm_context);
1767+
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1768+
assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, false);
1769+
assert_int_equal(spdm_context->connection_info.multi_key_conn_req, false);
1770+
1771+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
1772+
libspdm_reset_message_a(spdm_context);
1773+
1774+
spdm_context->connection_info.capability.flags = 0;
1775+
spdm_context->local_context.capability.flags = 0;
1776+
spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
1777+
m_connection_other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
1778+
1779+
status = libspdm_negotiate_algorithms(spdm_context);
1780+
/* MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP invalid */
1781+
assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
1782+
1783+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
1784+
libspdm_reset_message_a(spdm_context);
1785+
1786+
spdm_context->connection_info.capability.flags =
1787+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY;
1788+
spdm_context->local_context.capability.flags =
1789+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY;
1790+
spdm_context->local_context.algorithm.other_params_support = 0;
1791+
m_connection_other_params_support = 0;
1792+
1793+
status = libspdm_negotiate_algorithms(spdm_context);
1794+
/* MULTI_KEY_CONN_REQ and MULTI_KEY_CONN_RSP invalid */
1795+
assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
1796+
1797+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
1798+
libspdm_reset_message_a(spdm_context);
1799+
1800+
spdm_context->connection_info.capability.flags =
1801+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY;
1802+
spdm_context->local_context.capability.flags =
1803+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY;
1804+
spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
1805+
m_connection_other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
1806+
1807+
status = libspdm_negotiate_algorithms(spdm_context);
1808+
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1809+
assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, true);
1810+
assert_int_equal(spdm_context->connection_info.multi_key_conn_req, true);
1811+
1812+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
1813+
libspdm_reset_message_a(spdm_context);
1814+
1815+
spdm_context->connection_info.capability.flags =
1816+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG;
1817+
spdm_context->local_context.capability.flags =
1818+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG;
1819+
spdm_context->local_context.algorithm.other_params_support = 0;
1820+
m_connection_other_params_support = 0;
1821+
1822+
status = libspdm_negotiate_algorithms(spdm_context);
1823+
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1824+
assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, false);
1825+
assert_int_equal(spdm_context->connection_info.multi_key_conn_req, false);
1826+
1827+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
1828+
libspdm_reset_message_a(spdm_context);
1829+
1830+
spdm_context->connection_info.capability.flags =
1831+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG;
1832+
spdm_context->local_context.capability.flags =
1833+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG;
1834+
spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
1835+
m_connection_other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN;
1836+
1837+
status = libspdm_negotiate_algorithms(spdm_context);
1838+
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1839+
assert_int_equal(spdm_context->connection_info.multi_key_conn_rsp, true);
1840+
assert_int_equal(spdm_context->connection_info.multi_key_conn_req, true);
1841+
}
1842+
16731843
static libspdm_test_context_t m_libspdm_requester_negotiate_algorithms_test_context = {
16741844
LIBSPDM_TEST_CONTEXT_VERSION,
16751845
true,
@@ -1717,6 +1887,7 @@ int libspdm_requester_negotiate_algorithms_test_main(void)
17171887
cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case32),
17181888
cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case33),
17191889
cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case34),
1890+
cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_case35),
17201891
};
17211892

17221893
libspdm_setup_test_context(&m_libspdm_requester_negotiate_algorithms_test_context);

0 commit comments

Comments
 (0)