Skip to content

Commit fa7fbbd

Browse files
steven-bellockjyao1
authored andcommitted
Add algorithm masks and helper functions
These helper functions will be used to mask algorithms based on the negotiated SPDM version. Signed-off-by: Steven Bellock <[email protected]>
1 parent 9cf032b commit fa7fbbd

File tree

3 files changed

+162
-2
lines changed

3 files changed

+162
-2
lines changed

include/industry_standard/spdm.h

+25
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ typedef struct {
348348
#define SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG 4
349349
#define SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE 5
350350

351+
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_DHE_11_MASK 0x003f
352+
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_AEAD_11_MASK 0x0007
353+
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_REQ_BASE_ASYM_ALG_11_MASK 0x01ff
354+
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_KEY_SCHEDULE_11_MASK 0x0001
355+
356+
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_DHE_12_MASK 0x007f
357+
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_AEAD_12_MASK 0x000f
358+
#define SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_REQ_BASE_ASYM_ALG_12_MASK 0x0fff
359+
351360
typedef struct {
352361
uint8_t alg_type;
353362
uint8_t alg_count;
@@ -366,11 +375,15 @@ typedef struct {
366375
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
367376
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
368377

378+
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_10_MASK 0x000001FF
379+
369380
/* SPDM NEGOTIATE_ALGORITHMS request base_asym_algo/REQ_BASE_ASYM_ALG (1.2) */
370381
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256 0x00000200
371382
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
372383
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
373384

385+
#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_12_MASK 0x00000FFF
386+
374387
/* SPDM NEGOTIATE_ALGORITHMS request base_hash_algo */
375388
#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
376389
#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 0x00000002
@@ -379,9 +392,13 @@ typedef struct {
379392
#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384 0x00000010
380393
#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512 0x00000020
381394

395+
#define SPDM_ALGORITHMS_BASE_HASH_ALGO_10_MASK 0x0000003F
396+
382397
/* SPDM NEGOTIATE_ALGORITHMS request base_hash_algo (1.2) */
383398
#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256 0x00000040
384399

400+
#define SPDM_ALGORITHMS_BASE_HASH_ALGO_12_MASK 0x0000007F
401+
385402
/* SPDM NEGOTIATE_ALGORITHMS request DHE */
386403
#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048 0x00000001
387404
#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072 0x00000002
@@ -442,9 +459,13 @@ typedef struct {
442459
#define SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_384 0x00000020
443460
#define SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SHA3_512 0x00000040
444461

462+
#define SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_10_MASK 0x0000007F
463+
445464
/* SPDM NEGOTIATE_ALGORITHMS response measurement_hash_algo (1.2) */
446465
#define SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_TPM_ALG_SM3_256 0x00000080
447466

467+
#define SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_12_MASK 0x000000FF
468+
448469
/* SPDM Opaque Data Format (1.2) */
449470
#define SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_NONE 0x0
450471
#define SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0 0x1
@@ -715,6 +736,8 @@ typedef struct {
715736

716737
#define SPDM_MEASUREMENT_SPECIFICATION_DMTF 0x01
717738

739+
#define SPDM_MEASUREMENT_SPECIFICATION_10_MASK 0x01
740+
718741
/* SPDM MEASUREMENTS block DMTF header */
719742
typedef struct {
720743
uint8_t dmtf_spec_measurement_value_type;
@@ -813,6 +836,8 @@ typedef struct {
813836

814837
#define SPDM_MEL_SPECIFICATION_DMTF 0x01
815838

839+
#define SPDM_MEL_SPECIFICATION_13_MASK 0x01
840+
816841
/* SPDM ERROR response */
817842
typedef struct {
818843
spdm_message_header_t header;

include/internal/libspdm_common_lib.h

+53-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2024 DMTF. All rights reserved.
3+
* Copyright 2021-2025 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -1728,4 +1728,56 @@ static inline uint64_t libspdm_le_to_be_64(uint64_t value)
17281728
uint32_t libspdm_mask_capability_flags(libspdm_context_t *spdm_context,
17291729
bool is_request_flags, uint32_t flags);
17301730

1731+
/**
1732+
* Return BaseHashAlgo that is masked by the negotiated SPDM version.
1733+
*
1734+
* @param spdm_context A pointer to the SPDM context.
1735+
* @param base_hash_algo Unmasked BaseHashAlgo.
1736+
*
1737+
* @return The masked BaseHashAlgo.
1738+
*/
1739+
uint32_t libspdm_mask_base_hash_algo(libspdm_context_t *spdm_context, uint32_t base_hash_algo);
1740+
1741+
/**
1742+
* Return MeasurementHashAlgo that is masked by the negotiated SPDM version.
1743+
*
1744+
* @param spdm_context A pointer to the SPDM context.
1745+
* @param measurement_hash_algo Unmasked MeasurementHashAlgo.
1746+
*
1747+
* @return The masked MeasurementHashAlgo.
1748+
*/
1749+
uint32_t libspdm_mask_measurement_hash_algo(libspdm_context_t *spdm_context,
1750+
uint32_t measurement_hash_algo);
1751+
1752+
/**
1753+
* Return MeasurementSpecification that is masked by the negotiated SPDM version.
1754+
*
1755+
* @param spdm_context A pointer to the SPDM context.
1756+
* @param measurement_specification Unmasked MeasurementSpecification.
1757+
*
1758+
* @return The masked MeasurementSpecification.
1759+
*/
1760+
uint8_t libspdm_mask_measurement_specification(libspdm_context_t *spdm_context,
1761+
uint8_t measurement_specification);
1762+
1763+
/**
1764+
* Return MELspecification that is masked by the negotiated SPDM version.
1765+
*
1766+
* @param spdm_context A pointer to the SPDM context.
1767+
* @param mel_specification Unmasked MELspecification.
1768+
*
1769+
* @return The masked MELspecification.
1770+
*/
1771+
uint8_t libspdm_mask_mel_specification(libspdm_context_t *spdm_context, uint8_t mel_specification);
1772+
1773+
/**
1774+
* Return BaseAsymAlgo that is masked by the negotiated SPDM version.
1775+
*
1776+
* @param spdm_context A pointer to the SPDM context.
1777+
* @param base_asym_algo Unmasked BaseAsymAlgo.
1778+
*
1779+
* @return The masked BaseAsymAlgo.
1780+
*/
1781+
uint32_t libspdm_mask_base_asym_algo(libspdm_context_t *spdm_context, uint32_t base_asym_algo);
1782+
17311783
#endif /* SPDM_COMMON_LIB_INTERNAL_H */

library/spdm_common_lib/libspdm_com_support.c

+84-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2024 DMTF. All rights reserved.
3+
* Copyright 2021-2025 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -374,3 +374,86 @@ uint32_t libspdm_mask_capability_flags(libspdm_context_t *spdm_context,
374374
return 0;
375375
}
376376
}
377+
378+
uint32_t libspdm_mask_base_hash_algo(libspdm_context_t *spdm_context, uint32_t base_hash_algo)
379+
{
380+
const uint8_t spdm_version = libspdm_get_connection_version(spdm_context);
381+
382+
if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
383+
return (base_hash_algo & SPDM_ALGORITHMS_BASE_HASH_ALGO_12_MASK);
384+
} else {
385+
return (base_hash_algo & SPDM_ALGORITHMS_BASE_HASH_ALGO_10_MASK);
386+
}
387+
}
388+
389+
uint32_t libspdm_mask_measurement_hash_algo(libspdm_context_t *spdm_context,
390+
uint32_t measurement_hash_algo)
391+
{
392+
const uint8_t spdm_version = libspdm_get_connection_version(spdm_context);
393+
394+
if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
395+
return (measurement_hash_algo & SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_12_MASK);
396+
} else {
397+
return (measurement_hash_algo & SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_10_MASK);
398+
}
399+
}
400+
401+
uint8_t libspdm_mask_measurement_specification(libspdm_context_t *spdm_context,
402+
uint8_t measurement_specification)
403+
{
404+
return (measurement_specification & SPDM_MEASUREMENT_SPECIFICATION_10_MASK);
405+
}
406+
407+
uint8_t libspdm_mask_mel_specification(libspdm_context_t *spdm_context, uint8_t mel_specification)
408+
{
409+
LIBSPDM_ASSERT(libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13);
410+
411+
return (mel_specification & SPDM_MEL_SPECIFICATION_13_MASK);
412+
}
413+
414+
uint32_t libspdm_mask_base_asym_algo(libspdm_context_t *spdm_context, uint32_t base_asym_algo)
415+
{
416+
const uint8_t spdm_version = libspdm_get_connection_version(spdm_context);
417+
418+
if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
419+
return (base_asym_algo & SPDM_ALGORITHMS_BASE_ASYM_ALGO_12_MASK);
420+
} else {
421+
return (base_asym_algo & SPDM_ALGORITHMS_BASE_ASYM_ALGO_10_MASK);
422+
}
423+
}
424+
425+
uint16_t libspdm_mask_alg_supported(libspdm_context_t *spdm_context, uint8_t alg_type,
426+
uint16_t alg_supported)
427+
{
428+
const uint8_t spdm_version = libspdm_get_connection_version(spdm_context);
429+
430+
LIBSPDM_ASSERT(spdm_version >= SPDM_MESSAGE_VERSION_11);
431+
432+
switch (alg_type) {
433+
case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE:
434+
if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
435+
return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_DHE_12_MASK);
436+
} else {
437+
return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_DHE_11_MASK);
438+
}
439+
case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD:
440+
if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
441+
return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_AEAD_12_MASK);
442+
} else {
443+
return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_AEAD_11_MASK);
444+
}
445+
case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG:
446+
if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
447+
return (alg_supported &
448+
SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_REQ_BASE_ASYM_ALG_12_MASK);
449+
} else {
450+
return (alg_supported &
451+
SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_REQ_BASE_ASYM_ALG_11_MASK);
452+
}
453+
case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE:
454+
return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_KEY_SCHEDULE_11_MASK);
455+
default:
456+
LIBSPDM_ASSERT(false);
457+
return 0;
458+
}
459+
}

0 commit comments

Comments
 (0)