Skip to content

Commit b0d55f8

Browse files
committed
Add FIPS test for SPDM Key Schedule
fix #3082 Signed-off-by: Aaron Li <[email protected]>
1 parent a381c9c commit b0d55f8

File tree

9 files changed

+772
-0
lines changed

9 files changed

+772
-0
lines changed

include/hal/library/requester/psklib.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,56 @@ extern bool libspdm_psk_master_secret_hkdf_expand(
5353
const uint8_t *psk_hint, size_t psk_hint_size,
5454
const uint8_t *info, size_t info_size,
5555
uint8_t *out, size_t out_size);
56+
57+
#if LIBSPDM_FIPS_MODE
58+
/**
59+
* Derive HMAC-based Expand key Derivation Function (HKDF) Expand, based upon the negotiated HKDF
60+
* algorithm, this API is only used for FIPS test.
61+
*
62+
* @param base_hash_algo Indicates the hash algorithm.
63+
* @param psk Pointer to the input PSK.
64+
* @param psk_size PSK size in bytes.
65+
* @param info Pointer to the application specific info.
66+
* @param info_size Info size in bytes.
67+
* @param out Pointer to buffer to receive HKDF value.
68+
* @param out_size Size of HKDF bytes to generate.
69+
*
70+
* @retval true HKDF generated successfully.
71+
* @retval false HKDF generation failed.
72+
**/
73+
extern bool libspdm_psk_handshake_secret_hkdf_expand_ex(
74+
spdm_version_number_t spdm_version,
75+
uint32_t base_hash_algo,
76+
const uint8_t *psk,
77+
size_t psk_size,
78+
const uint8_t *info,
79+
size_t info_size,
80+
uint8_t *out, size_t out_size);
81+
82+
/**
83+
* Derive HMAC-based Expand key Derivation Function (HKDF) Expand, based upon the negotiated HKDF
84+
* algorithm, this API is only used for FIPS test.
85+
*
86+
* @param base_hash_algo Indicates the hash algorithm.
87+
* @param psk Pointer to the input PSK.
88+
* @param psk_size PSK size in bytes.
89+
* @param info Pointer to the application specific info.
90+
* @param info_size Info size in bytes.
91+
* @param out Pointer to buffer to receive HKDF value.
92+
* @param out_size Size of HKDF bytes to generate.
93+
*
94+
* @retval true HKDF generated successfully.
95+
* @retval false HKDF generation failed.
96+
**/
97+
extern bool libspdm_psk_master_secret_hkdf_expand_ex(
98+
spdm_version_number_t spdm_version,
99+
uint32_t base_hash_algo,
100+
const uint8_t *psk,
101+
size_t psk_size,
102+
const uint8_t *info,
103+
size_t info_size,
104+
uint8_t *out, size_t out_size);
105+
#endif /* LIBSPDM_FIPS_MODE */
56106
#endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
57107

58108
#endif /* REQUESTER_PSKLIB_H */

include/hal/library/responder/psklib.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,56 @@ extern bool libspdm_psk_master_secret_hkdf_expand(
5454
const uint8_t *psk_hint, size_t psk_hint_size,
5555
const uint8_t *info, size_t info_size,
5656
uint8_t *out, size_t out_size);
57+
58+
#if LIBSPDM_FIPS_MODE
59+
/**
60+
* Derive HMAC-based Expand key Derivation Function (HKDF) Expand, based upon the negotiated HKDF
61+
* algorithm, this API is only used for FIPS test.
62+
*
63+
* @param base_hash_algo Indicates the hash algorithm.
64+
* @param psk Pointer to the input PSK.
65+
* @param psk_size PSK size in bytes.
66+
* @param info Pointer to the application specific info.
67+
* @param info_size Info size in bytes.
68+
* @param out Pointer to buffer to receive HKDF value.
69+
* @param out_size Size of HKDF bytes to generate.
70+
*
71+
* @retval true HKDF generated successfully.
72+
* @retval false HKDF generation failed.
73+
**/
74+
extern bool libspdm_psk_handshake_secret_hkdf_expand_ex(
75+
spdm_version_number_t spdm_version,
76+
uint32_t base_hash_algo,
77+
const uint8_t *psk,
78+
size_t psk_size,
79+
const uint8_t *info,
80+
size_t info_size,
81+
uint8_t *out, size_t out_size);
82+
83+
/**
84+
* Derive HMAC-based Expand key Derivation Function (HKDF) Expand, based upon the negotiated HKDF
85+
* algorithm, this API is only used for FIPS test.
86+
*
87+
* @param base_hash_algo Indicates the hash algorithm.
88+
* @param psk Pointer to the input PSK.
89+
* @param psk_size PSK size in bytes.
90+
* @param info Pointer to the application specific info.
91+
* @param info_size Info size in bytes.
92+
* @param out Pointer to buffer to receive HKDF value.
93+
* @param out_size Size of HKDF bytes to generate.
94+
*
95+
* @retval true HKDF generated successfully.
96+
* @retval false HKDF generation failed.
97+
**/
98+
extern bool libspdm_psk_master_secret_hkdf_expand_ex(
99+
spdm_version_number_t spdm_version,
100+
uint32_t base_hash_algo,
101+
const uint8_t *psk,
102+
size_t psk_size,
103+
const uint8_t *info,
104+
size_t info_size,
105+
uint8_t *out, size_t out_size);
106+
#endif /* LIBSPDM_FIPS_MODE */
57107
#endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
58108

59109
#endif /* RESPONDER_PSKLIB_H */

include/internal/libspdm_fips_lib.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define LIBSPDM_FIPS_SELF_TEST_ML_KEM 0x00020000
2727
#define LIBSPDM_FIPS_SELF_TEST_ML_DSA 0x00040000
2828
#define LIBSPDM_FIPS_SELF_TEST_SLH_DSA 0x00080000
29+
#define LIBSPDM_FIPS_SELF_TEST_KEY_SCHEDULE 0x00100000
2930

3031
#if LIBSPDM_SLH_DSA_SUPPORT
3132
#define LIBSPDM_FIPS_REQUIRED_BUFFER_SIZE 7856 /* SLH_DSA_SHA2_128S_SIG_SIZE */
@@ -131,4 +132,9 @@ bool libspdm_fips_selftest_mldsa(void *fips_selftest_context);
131132
**/
132133
bool libspdm_fips_selftest_slhdsa(void *fips_selftest_context);
133134

135+
/**
136+
* SPDM KDF self_test
137+
*/
138+
bool libspdm_fips_selftest_key_schedule(void *fips_selftest_context);
139+
134140
#endif/*LIBSPDM_FIPS_MODE*/

library/spdm_crypt_lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ target_sources(spdm_crypt_lib
3939
fips/libspdm_selftest_mldsa_vec.c
4040
fips/libspdm_selftest_slhdsa.c
4141
fips/libspdm_selftest_slhdsa_vec.c
42+
fips/libspdm_selftest_key_schedule.c
4243
)

library/spdm_crypt_lib/fips/libspdm_selftest.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ bool libspdm_fips_run_selftest(void *fips_selftest_context)
5151

5252
libspdm_fips_selftest_slhdsa(context);
5353

54+
libspdm_fips_selftest_key_schedule(context);
55+
5456
return (context->tested_algo == context->self_test_result);
5557
}
5658

0 commit comments

Comments
 (0)