Skip to content

Commit b7af44b

Browse files
committed
extract key schedule logic to spdm_crypt_lib for FIPS test
Signed-off-by: Aaron Li <aaron.li@intel.com>
1 parent 6ea62c2 commit b7af44b

File tree

5 files changed

+524
-324
lines changed

5 files changed

+524
-324
lines changed

include/library/spdm_crypt_lib.h

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2025 DMTF. All rights reserved.
3+
* Copyright 2021-2026 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

@@ -1581,6 +1581,99 @@ bool libspdm_kem_decapsulate(uint32_t kem_alg, void *context,
15811581
uint8_t *shared_secret,
15821582
size_t *shared_secret_size);
15831583

1584+
/**
1585+
* This function concatenates binary data, which is used as info in HKDF expand later.
1586+
*
1587+
* @param label An ascii string label for the libspdm_bin_concat.
1588+
* @param label_size The size in bytes of the ASCII string label, not including NULL terminator.
1589+
* @param context A pre-defined hash value as the context for the libspdm_bin_concat.
1590+
* @param length 16 bits length for the libspdm_bin_concat.
1591+
* @param hash_size The size in bytes of the context hash.
1592+
* @param out_bin The buffer to store the output binary.
1593+
* @param out_bin_size The size in bytes for the out_bin.
1594+
**/
1595+
void libspdm_bin_concat(spdm_version_number_t spdm_version,
1596+
const char *label, size_t label_size,
1597+
const uint8_t *context, uint16_t length,
1598+
size_t hash_size, uint8_t *out_bin,
1599+
size_t *out_bin_size);
1600+
1601+
/**
1602+
* This function generates SPDM HandshakeKey.
1603+
*
1604+
* @param spdm_version The SPDM version number.
1605+
* @param secret Pointer to the input secret used for key derivation.
1606+
* For DHE/KEM, input is shared_secret
1607+
* For PSK, input is psk_hint
1608+
* For PSK (FIPS test), input is psk
1609+
* @param secret_size Size of the input secret in bytes.
1610+
* @param use_psk Indicates whether to use PSK for key generation.
1611+
* @param base_hash_algo The base hash algorithm identifier to use for key derivation.
1612+
* @param th1_hash_data Pointer to the TH1 hash data used in the key derivation process.
1613+
* @param handshake_secret Pointer to the buffer that will receive the generated handshake secret.
1614+
* @param handshake_secret_size On input, the size of the handshake_secret buffer.
1615+
* On output, the actual size of the generated handshake secret.
1616+
* @param request_handshake_secret Pointer to the buffer that will receive the generated request handshake secret.
1617+
* @param request_handshake_secret_size On input, the size of the request_handshake_secret buffer.
1618+
* On output, the actual size of the generated handshake secret.
1619+
* @param response_handshake_secret Pointer to the buffer that will receive the generated response handshake secret.
1620+
* @param response_handshake_secret_size On input, the size of the response_handshake_secret buffer.
1621+
* On output, the actual size of the generated handshake secret.
1622+
* @param fips_test Indicates whether the function is being called for FIPS test purposes.
1623+
*
1624+
* @retval true Handshake keys were generated successfully.
1625+
* @retval false An error occurred during key generation.
1626+
*/
1627+
bool libspdm_generate_handshake_key (
1628+
spdm_version_number_t spdm_version,
1629+
const uint8_t *secret, size_t secret_size,
1630+
bool use_psk, uint32_t base_hash_algo,
1631+
const uint8_t *th1_hash_data,
1632+
uint8_t *handshake_secret, size_t *handshake_secret_size,
1633+
uint8_t *request_handshake_secret, size_t *request_handshake_secret_size,
1634+
uint8_t *response_handshake_secret, size_t *response_handshake_secret_size,
1635+
bool fips_test);
1636+
1637+
/**
1638+
* This function generates SPDM DataKey.
1639+
*
1640+
* @param spdm_version The SPDM version number.
1641+
* @param secret Pointer to the input secret used for key derivation.
1642+
* For DHE/KEM, input is handshake_secret
1643+
* For PSK, input is psk_hint
1644+
* For PSK (FIPS test), input is psk
1645+
* @param secret_size Size of the input secret in bytes.
1646+
* @param use_psk Indicates whether to use PSK for key generation.
1647+
* @param base_hash_algo The base hash algorithm identifier to use for key derivation.
1648+
* @param th2_hash_data Pointer to the TH2 hash data used in the key derivation process.
1649+
* @param master_secret Pointer to the buffer that will receive the generated master secret.
1650+
* @param master_secret_size On input, the size of the master_secret buffer.
1651+
* On output, the actual size of the generated master secret.
1652+
* @param request_data_secret Pointer to the buffer that will receive the generated request data secret.
1653+
* @param request_data_secret_size On input, the size of the request_data_secret buffer.
1654+
* On output, the actual size of the generated data secret.
1655+
* @param response_data_secret Pointer to the buffer that will receive the generated response data secret.
1656+
* @param response_data_secret_size On input, the size of the response_data_secret buffer.
1657+
* On output, the actual size of the generated data secret.
1658+
* @param export_master_secret Pointer to the buffer that will receive the generated export master secret.
1659+
* @param export_master_secret_size On input, the size of the export_master_secret buffer.
1660+
* On output, the actual size of the generated export master secret.
1661+
* @param fips_test Indicates whether the function is being called for FIPS test purposes.
1662+
*
1663+
* @retval true Handshake keys were generated successfully.
1664+
* @retval false An error occurred during key generation.
1665+
*/
1666+
bool libspdm_generate_data_key (
1667+
spdm_version_number_t spdm_version,
1668+
const uint8_t *secret, size_t secret_size,
1669+
bool use_psk, uint32_t base_hash_algo,
1670+
const uint8_t *th2_hash_data,
1671+
uint8_t *master_secret, size_t *master_secret_size,
1672+
uint8_t *request_data_secret, size_t *request_data_secret_size,
1673+
uint8_t *response_data_secret, size_t *response_data_secret_size,
1674+
uint8_t *export_master_secret, size_t *export_master_secret_size,
1675+
bool fips_test);
1676+
15841677
#if LIBSPDM_FIPS_MODE
15851678
/*run all of the self-tests and returns the results.*/
15861679
bool libspdm_fips_run_selftest(void *fips_selftest_context);

include/library/spdm_secured_message_lib.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2025 DMTF. All rights reserved.
3+
* Copyright 2021-2026 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

@@ -153,23 +153,6 @@ void libspdm_clear_handshake_secret(void *spdm_secured_message_context);
153153
**/
154154
void libspdm_clear_master_secret(void *spdm_secured_message_context);
155155

156-
/**
157-
* This function concatenates binary data, which is used as info in HKDF expand later.
158-
*
159-
* @param label An ascii string label for the libspdm_bin_concat.
160-
* @param label_size The size in bytes of the ASCII string label, not including NULL terminator.
161-
* @param context A pre-defined hash value as the context for the libspdm_bin_concat.
162-
* @param length 16 bits length for the libspdm_bin_concat.
163-
* @param hash_size The size in bytes of the context hash.
164-
* @param out_bin The buffer to store the output binary.
165-
* @param out_bin_size The size in bytes for the out_bin.
166-
**/
167-
void libspdm_bin_concat(spdm_version_number_t spdm_version,
168-
const char *label, size_t label_size,
169-
const uint8_t *context, uint16_t length,
170-
size_t hash_size, uint8_t *out_bin,
171-
size_t *out_bin_size);
172-
173156
typedef enum {
174157
LIBSPDM_KEY_UPDATE_OPERATION_CREATE_UPDATE,
175158
LIBSPDM_KEY_UPDATE_OPERATION_COMMIT_UPDATE,

library/spdm_crypt_lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ target_sources(spdm_crypt_lib
2020
libspdm_crypt_rng.c
2121
libspdm_crypt_pqc_asym.c
2222
libspdm_crypt_pqc_kem.c
23+
libspdm_crypt_key_schedule.c
2324
fips/libspdm_selftest.c
2425
fips/libspdm_selftest_hmac.c
2526
fips/libspdm_selftest_aes_gcm.c

0 commit comments

Comments
 (0)