Skip to content

Commit 4da0f13

Browse files
committed
extract key schedule logic to spdm_crypt_lib for FIPS test
Signed-off-by: Aaron Li <[email protected]>
1 parent 6ea62c2 commit 4da0f13

File tree

5 files changed

+526
-324
lines changed

5 files changed

+526
-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 shared_secret Pointer to the input shared secret used for key derivation.
1606+
* @param shared_secret_size Size of the input shared secret in bytes.
1607+
* @param shared_secret_use_psk Indicates whether to use PSK as shared secret for key generation.
1608+
* @param psk_hint Pointer to the PSK hint used for PSK key derivation.
1609+
* @param psk_hint_size Size of the PSK hint in bytes.
1610+
* @param use_psk_hint Indicates whether to use PSK hint for PSK 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+
*
1623+
* @retval true Handshake keys were generated successfully.
1624+
* @retval false An error occurred during key generation.
1625+
*/
1626+
bool libspdm_generate_handshake_key (
1627+
spdm_version_number_t spdm_version,
1628+
const uint8_t *shared_secret, size_t shared_secret_size,
1629+
bool shared_secret_use_psk,
1630+
const uint8_t *psk_hint, size_t psk_hint_size,
1631+
bool use_psk_hint,
1632+
uint32_t base_hash_algo,
1633+
const uint8_t *th1_hash_data,
1634+
uint8_t *handshake_secret, size_t *handshake_secret_size,
1635+
uint8_t *request_handshake_secret, size_t *request_handshake_secret_size,
1636+
uint8_t *response_handshake_secret, size_t *response_handshake_secret_size);
1637+
1638+
/**
1639+
* This function generates SPDM DataKey.
1640+
*
1641+
* @param spdm_version The SPDM version number.
1642+
* @param handshake_secret Pointer to the input handshake secret used for key derivation.
1643+
* @param handshake_secret_size Size of the input handshake secret in bytes.
1644+
* @param psk_hint Pointer to the PSK hint used for PSK key derivation.
1645+
* @param psk_hint_size Size of the PSK hint in bytes.
1646+
* @param use_psk_hint Indicates whether to use PSK hint for PSK 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+
*
1662+
* @retval true Handshake keys were generated successfully.
1663+
* @retval false An error occurred during key generation.
1664+
*/
1665+
bool libspdm_generate_data_key (
1666+
spdm_version_number_t spdm_version,
1667+
const uint8_t *handshake_secret, size_t handshake_secret_size,
1668+
const uint8_t *psk_hint, size_t psk_hint_size,
1669+
bool use_psk_hint,
1670+
uint32_t base_hash_algo,
1671+
const uint8_t *th2_hash_data,
1672+
uint8_t *master_secret, size_t *master_secret_size,
1673+
uint8_t *request_data_secret, size_t *request_data_secret_size,
1674+
uint8_t *response_data_secret, size_t *response_data_secret_size,
1675+
uint8_t *export_master_secret, size_t *export_master_secret_size);
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)