1
1
/**
2
2
* Copyright Notice:
3
- * Copyright 2021-2024 DMTF. All rights reserved.
3
+ * Copyright 2021-2025 DMTF. All rights reserved.
4
4
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5
5
**/
6
6
@@ -23,7 +23,7 @@ bool libspdm_generate_key_exchange_rsp_hmac(libspdm_context_t *spdm_context,
23
23
size_t th_curr_data_size ;
24
24
libspdm_th_managed_buffer_t th_curr ;
25
25
uint8_t hash_data [LIBSPDM_MAX_HASH_SIZE ];
26
- #endif
26
+ #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
27
27
bool result ;
28
28
29
29
hash_size = libspdm_get_hash_size (spdm_context -> connection_info .algorithm .base_hash_algo );
@@ -43,8 +43,7 @@ bool libspdm_generate_key_exchange_rsp_hmac(libspdm_context_t *spdm_context,
43
43
}
44
44
45
45
result = libspdm_calculate_th_for_exchange (
46
- spdm_context , session_info , cert_chain_buffer ,
47
- cert_chain_buffer_size , & th_curr );
46
+ spdm_context , session_info , cert_chain_buffer , cert_chain_buffer_size , & th_curr );
48
47
if (!result ) {
49
48
return false;
50
49
}
@@ -58,8 +57,7 @@ bool libspdm_generate_key_exchange_rsp_hmac(libspdm_context_t *spdm_context,
58
57
}
59
58
60
59
result = libspdm_hmac_all_with_response_finished_key (
61
- session_info -> secured_message_context , hash_data ,
62
- hash_size , hmac_data );
60
+ session_info -> secured_message_context , hash_data , hash_size , hmac_data );
63
61
if (!result ) {
64
62
return false;
65
63
}
@@ -69,7 +67,7 @@ bool libspdm_generate_key_exchange_rsp_hmac(libspdm_context_t *spdm_context,
69
67
if (!result ) {
70
68
return false;
71
69
}
72
- #endif
70
+ #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
73
71
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "th_curr hmac - " ));
74
72
LIBSPDM_INTERNAL_DUMP_DATA (hmac_data , hash_size );
75
73
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "\n" ));
@@ -91,7 +89,7 @@ bool libspdm_generate_key_exchange_rsp_signature(libspdm_context_t *spdm_context
91
89
libspdm_th_managed_buffer_t th_curr ;
92
90
const uint8_t * cert_chain_buffer ;
93
91
size_t cert_chain_buffer_size ;
94
- #endif
92
+ #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
95
93
#if ((LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT ) && (LIBSPDM_DEBUG_BLOCK_ENABLE )) || \
96
94
!(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT )
97
95
uint8_t hash_data [LIBSPDM_MAX_HASH_SIZE ];
@@ -120,8 +118,7 @@ bool libspdm_generate_key_exchange_rsp_signature(libspdm_context_t *spdm_context
120
118
}
121
119
122
120
result = libspdm_calculate_th_for_exchange (
123
- spdm_context , session_info , cert_chain_buffer ,
124
- cert_chain_buffer_size , & th_curr );
121
+ spdm_context , session_info , cert_chain_buffer , cert_chain_buffer_size , & th_curr );
125
122
if (!result ) {
126
123
return false;
127
124
}
@@ -142,7 +139,7 @@ bool libspdm_generate_key_exchange_rsp_signature(libspdm_context_t *spdm_context
142
139
if (!result ) {
143
140
return false;
144
141
}
145
- #endif
142
+ #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
146
143
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "th_curr hash - " ));
147
144
LIBSPDM_INTERNAL_DUMP_DATA (hash_data , hash_size );
148
145
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "\n" ));
@@ -151,7 +148,7 @@ bool libspdm_generate_key_exchange_rsp_signature(libspdm_context_t *spdm_context
151
148
result = libspdm_responder_data_sign (
152
149
#if LIBSPDM_HAL_PASS_SPDM_CONTEXT
153
150
spdm_context ,
154
- #endif
151
+ #endif /* LIBSPDM_HAL_PASS_SPDM_CONTEXT */
155
152
spdm_context -> connection_info .version , SPDM_KEY_EXCHANGE_RSP ,
156
153
spdm_context -> connection_info .algorithm .base_asym_algo ,
157
154
spdm_context -> connection_info .algorithm .base_hash_algo ,
@@ -160,12 +157,12 @@ bool libspdm_generate_key_exchange_rsp_signature(libspdm_context_t *spdm_context
160
157
result = libspdm_responder_data_sign (
161
158
#if LIBSPDM_HAL_PASS_SPDM_CONTEXT
162
159
spdm_context ,
163
- #endif
160
+ #endif /* LIBSPDM_HAL_PASS_SPDM_CONTEXT */
164
161
spdm_context -> connection_info .version , SPDM_KEY_EXCHANGE_RSP ,
165
162
spdm_context -> connection_info .algorithm .base_asym_algo ,
166
163
spdm_context -> connection_info .algorithm .base_hash_algo ,
167
164
true, hash_data , hash_size , signature , & signature_size );
168
- #endif
165
+ #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
169
166
if (result ) {
170
167
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "signature - " ));
171
168
LIBSPDM_INTERNAL_DUMP_DATA (signature , signature_size );
@@ -340,8 +337,7 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
340
337
SPDM_ERROR_CODE_INVALID_REQUEST ,
341
338
0 , response_size , response );
342
339
}
343
- if (request_size < sizeof (spdm_key_exchange_request_t ) + dhe_key_size +
344
- sizeof (uint16_t )) {
340
+ if (request_size < sizeof (spdm_key_exchange_request_t ) + dhe_key_size + sizeof (uint16_t )) {
345
341
return libspdm_generate_error_response (spdm_context ,
346
342
SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
347
343
response_size , response );
@@ -354,12 +350,12 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
354
350
SPDM_ERROR_CODE_INVALID_REQUEST , 0 ,
355
351
response_size , response );
356
352
}
357
- request_size = sizeof (spdm_key_exchange_request_t ) + dhe_key_size +
358
- sizeof ( uint16_t ) + opaque_data_length ;
353
+ request_size = sizeof (spdm_key_exchange_request_t ) + dhe_key_size + sizeof ( uint16_t ) +
354
+ opaque_data_length ;
359
355
360
356
if (opaque_data_length != 0 ) {
361
- cptr = (const uint8_t * )request + sizeof (spdm_key_exchange_request_t ) +
362
- dhe_key_size + sizeof (uint16_t );
357
+ cptr = (const uint8_t * )request + sizeof (spdm_key_exchange_request_t ) + dhe_key_size +
358
+ sizeof (uint16_t );
363
359
result = libspdm_process_general_opaque_data_check (spdm_context , opaque_data_length , cptr );
364
360
if (!result ) {
365
361
return libspdm_generate_error_response (spdm_context ,
@@ -434,8 +430,8 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
434
430
}
435
431
436
432
spdm_response -> rsp_session_id = rsp_session_id ;
437
-
438
433
spdm_response -> mut_auth_requested = 0 ;
434
+
439
435
if (libspdm_is_capabilities_flag_supported (
440
436
spdm_context , false,
441
437
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP ,
@@ -447,12 +443,10 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
447
443
#if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
448
444
spdm_context -> connection_info .peer_used_cert_chain_slot_id =
449
445
spdm_context -> encap_context .req_slot_id ;
450
- libspdm_init_mut_auth_encap_state (
451
- spdm_context , spdm_response -> mut_auth_requested );
446
+ libspdm_init_mut_auth_encap_state (spdm_context , spdm_response -> mut_auth_requested );
452
447
if (spdm_response -> mut_auth_requested == SPDM_KEY_EXCHANGE_RESPONSE_MUT_AUTH_REQUESTED ) {
453
448
/* no need to libspdm_init_mut_auth_encap_state() because of no ENCAP message */
454
- spdm_response -> req_slot_id_param =
455
- (spdm_context -> encap_context .req_slot_id & 0xF );
449
+ spdm_response -> req_slot_id_param = spdm_context -> encap_context .req_slot_id & 0xF ;
456
450
} else {
457
451
/* req_slot_id is always 0 if ENCAP message is needed */
458
452
spdm_response -> req_slot_id_param = 0 ;
@@ -484,12 +478,10 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
484
478
}
485
479
486
480
result = libspdm_secured_message_dhe_generate_key (
487
- spdm_context -> connection_info .algorithm .dhe_named_group ,
488
- dhe_context , ptr , & dhe_key_size );
481
+ spdm_context -> connection_info .algorithm .dhe_named_group , dhe_context , ptr , & dhe_key_size );
489
482
if (!result ) {
490
483
libspdm_secured_message_dhe_free (
491
- spdm_context -> connection_info .algorithm .dhe_named_group ,
492
- dhe_context );
484
+ spdm_context -> connection_info .algorithm .dhe_named_group , dhe_context );
493
485
libspdm_free_session_id (spdm_context , session_id );
494
486
return libspdm_generate_error_response (spdm_context ,
495
487
SPDM_ERROR_CODE_UNSPECIFIED , 0 ,
@@ -509,8 +501,7 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
509
501
(const uint8_t * )request + sizeof (spdm_key_exchange_request_t ),
510
502
dhe_key_size , session_info -> secured_message_context );
511
503
libspdm_secured_message_dhe_free (
512
- spdm_context -> connection_info .algorithm .dhe_named_group ,
513
- dhe_context );
504
+ spdm_context -> connection_info .algorithm .dhe_named_group , dhe_context );
514
505
if (!result ) {
515
506
libspdm_free_session_id (spdm_context , session_id );
516
507
return libspdm_generate_error_response (spdm_context ,
@@ -523,11 +514,10 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
523
514
#if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
524
515
if (libspdm_is_capabilities_flag_supported (
525
516
spdm_context , false, 0 , SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP )) {
526
-
527
517
result = libspdm_generate_measurement_summary_hash (
528
518
#if LIBSPDM_HAL_PASS_SPDM_CONTEXT
529
519
spdm_context ,
530
- #endif
520
+ #endif /* LIBSPDM_HAL_PASS_SPDM_CONTEXT */
531
521
spdm_context -> connection_info .version ,
532
522
spdm_context -> connection_info .algorithm .base_hash_algo ,
533
523
spdm_context -> connection_info .algorithm .measurement_spec ,
@@ -559,8 +549,7 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
559
549
spdm_context -> connection_info .local_used_cert_chain_buffer =
560
550
spdm_context -> local_context .local_cert_chain_provision [slot_id ];
561
551
spdm_context -> connection_info .local_used_cert_chain_buffer_size =
562
- spdm_context -> local_context
563
- .local_cert_chain_provision_size [slot_id ];
552
+ spdm_context -> local_context .local_cert_chain_provision_size [slot_id ];
564
553
}
565
554
566
555
status = libspdm_append_message_k (spdm_context , session_info , false, request , request_size );
@@ -579,8 +568,7 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
579
568
SPDM_ERROR_CODE_UNSPECIFIED , 0 ,
580
569
response_size , response );
581
570
}
582
- result = libspdm_generate_key_exchange_rsp_signature (spdm_context ,
583
- session_info , ptr );
571
+ result = libspdm_generate_key_exchange_rsp_signature (spdm_context , session_info , ptr );
584
572
if (!result ) {
585
573
libspdm_free_session_id (spdm_context , session_id );
586
574
return libspdm_generate_error_response (
@@ -596,10 +584,8 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
596
584
response_size , response );
597
585
}
598
586
599
- LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "libspdm_generate_session_handshake_key[%x]\n" ,
600
- session_id ));
601
- result = libspdm_calculate_th1_hash (spdm_context , session_info , false,
602
- th1_hash_data );
587
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "libspdm_generate_session_handshake_key[%x]\n" , session_id ));
588
+ result = libspdm_calculate_th1_hash (spdm_context , session_info , false, th1_hash_data );
603
589
if (!result ) {
604
590
libspdm_free_session_id (spdm_context , session_id );
605
591
return libspdm_generate_error_response (spdm_context ,
@@ -621,8 +607,7 @@ libspdm_return_t libspdm_get_response_key_exchange(libspdm_context_t *spdm_conte
621
607
spdm_context , false,
622
608
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP ,
623
609
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP )) {
624
- result = libspdm_generate_key_exchange_rsp_hmac (spdm_context ,
625
- session_info , ptr );
610
+ result = libspdm_generate_key_exchange_rsp_hmac (spdm_context , session_info , ptr );
626
611
if (!result ) {
627
612
libspdm_free_session_id (spdm_context , session_id );
628
613
return libspdm_generate_error_response (
0 commit comments