@@ -121,6 +121,8 @@ bool libspdm_verify_measurement_signature(libspdm_context_t *spdm_context,
121
121
* @param request_attribute The request attribute of the request message.
122
122
* @param measurement_operation The measurement operation of the request message.
123
123
* @param slot_id The number of slot for the certificate chain.
124
+ * @param requester_context If not NULL, a buffer to hold the requester context (8 bytes).
125
+ * It is used only if the negotiated version >= 1.3.
124
126
* @param content_changed The measurement content changed output param.
125
127
* @param number_of_blocks The number of blocks of the measurement record.
126
128
* @param measurement_record_length On input, indicate the size in bytes of the destination buffer
@@ -137,6 +139,7 @@ static libspdm_return_t libspdm_try_get_measurement(libspdm_context_t *spdm_cont
137
139
uint8_t request_attribute ,
138
140
uint8_t measurement_operation ,
139
141
uint8_t slot_id_param ,
142
+ const void * requester_context ,
140
143
uint8_t * content_changed ,
141
144
uint8_t * number_of_blocks ,
142
145
uint32_t * measurement_record_length ,
@@ -267,6 +270,19 @@ static libspdm_return_t libspdm_try_get_measurement(libspdm_context_t *spdm_cont
267
270
libspdm_zero_mem (requester_nonce , SPDM_NONCE_SIZE );
268
271
}
269
272
}
273
+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
274
+ if (requester_context == NULL ) {
275
+ libspdm_zero_mem ((uint8_t * )spdm_request + spdm_request_size , SPDM_REQ_CONTEXT_SIZE );
276
+ } else {
277
+ libspdm_copy_mem ((uint8_t * )spdm_request + spdm_request_size , SPDM_REQ_CONTEXT_SIZE ,
278
+ requester_context , SPDM_REQ_CONTEXT_SIZE );
279
+ }
280
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "RequesterContext - " ));
281
+ LIBSPDM_INTERNAL_DUMP_DATA ((uint8_t * )spdm_request + spdm_request_size ,
282
+ SPDM_REQ_CONTEXT_SIZE );
283
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "\n" ));
284
+ spdm_request_size += SPDM_REQ_CONTEXT_SIZE ;
285
+ }
270
286
271
287
/* -=[Send Request Phase]=- */
272
288
status = libspdm_send_spdm_request (spdm_context , session_id , spdm_request_size , spdm_request );
@@ -403,17 +419,53 @@ static libspdm_return_t libspdm_try_get_measurement(libspdm_context_t *spdm_cont
403
419
}
404
420
}
405
421
406
- if (spdm_response_size <
407
- sizeof (spdm_measurements_response_t ) +
408
- measurement_record_data_length + SPDM_NONCE_SIZE +
409
- sizeof (uint16_t ) + opaque_length + signature_size ) {
410
- status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
411
- goto receive_done ;
422
+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
423
+ if (spdm_response_size <
424
+ sizeof (spdm_measurements_response_t ) +
425
+ measurement_record_data_length + SPDM_NONCE_SIZE +
426
+ sizeof (uint16_t ) + opaque_length + SPDM_REQ_CONTEXT_SIZE + signature_size ) {
427
+ status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
428
+ goto receive_done ;
429
+ }
430
+ spdm_response_size = sizeof (spdm_measurements_response_t ) +
431
+ measurement_record_data_length +
432
+ SPDM_NONCE_SIZE + sizeof (uint16_t ) +
433
+ opaque_length + SPDM_REQ_CONTEXT_SIZE + signature_size ;
434
+ } else {
435
+ if (spdm_response_size <
436
+ sizeof (spdm_measurements_response_t ) +
437
+ measurement_record_data_length + SPDM_NONCE_SIZE +
438
+ sizeof (uint16_t ) + opaque_length + signature_size ) {
439
+ status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
440
+ goto receive_done ;
441
+ }
442
+ spdm_response_size = sizeof (spdm_measurements_response_t ) +
443
+ measurement_record_data_length +
444
+ SPDM_NONCE_SIZE + sizeof (uint16_t ) +
445
+ opaque_length + signature_size ;
446
+ }
447
+
448
+ if ((opaque_data != NULL ) && (opaque_data_size != NULL )) {
449
+ if (opaque_length >= * opaque_data_size ) {
450
+ status = LIBSPDM_STATUS_BUFFER_TOO_SMALL ;
451
+ goto receive_done ;
452
+ }
453
+ libspdm_copy_mem (opaque_data , * opaque_data_size , ptr , opaque_length );
454
+ * opaque_data_size = opaque_length ;
455
+ }
456
+ ptr += opaque_length ;
457
+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
458
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "RequesterContext - " ));
459
+ LIBSPDM_INTERNAL_DUMP_DATA (ptr , SPDM_REQ_CONTEXT_SIZE );
460
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "\n" ));
461
+ if (!libspdm_consttime_is_mem_equal ((uint8_t * )spdm_request +
462
+ spdm_request_size - SPDM_REQ_CONTEXT_SIZE ,
463
+ ptr , SPDM_REQ_CONTEXT_SIZE )) {
464
+ status = LIBSPDM_STATUS_INVALID_MSG_FIELD ;
465
+ goto receive_done ;
466
+ }
467
+ ptr += SPDM_REQ_CONTEXT_SIZE ;
412
468
}
413
- spdm_response_size = sizeof (spdm_measurements_response_t ) +
414
- measurement_record_data_length +
415
- SPDM_NONCE_SIZE + sizeof (uint16_t ) +
416
- opaque_length + signature_size ;
417
469
418
470
/* -=[Process Response Phase]=- */
419
471
status = libspdm_append_message_m (spdm_context , session_info , spdm_request ,
@@ -428,16 +480,6 @@ static libspdm_return_t libspdm_try_get_measurement(libspdm_context_t *spdm_cont
428
480
goto receive_done ;
429
481
}
430
482
431
- if ((opaque_data != NULL ) && (opaque_data_size != NULL )) {
432
- if (opaque_length >= * opaque_data_size ) {
433
- status = LIBSPDM_STATUS_BUFFER_TOO_SMALL ;
434
- goto receive_done ;
435
- }
436
- libspdm_copy_mem (opaque_data , * opaque_data_size , ptr , opaque_length );
437
- * opaque_data_size = opaque_length ;
438
- }
439
- ptr += opaque_length ;
440
-
441
483
signature = ptr ;
442
484
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "signature (0x%x):\n" , signature_size ));
443
485
LIBSPDM_INTERNAL_DUMP_HEX (signature , signature_size );
@@ -482,17 +524,53 @@ static libspdm_return_t libspdm_try_get_measurement(libspdm_context_t *spdm_cont
482
524
}
483
525
}
484
526
485
- if (spdm_response_size <
486
- sizeof (spdm_measurements_response_t ) +
487
- measurement_record_data_length + SPDM_NONCE_SIZE +
488
- sizeof (uint16_t ) + opaque_length ) {
489
- status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
490
- goto receive_done ;
527
+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
528
+ if (spdm_response_size <
529
+ sizeof (spdm_measurements_response_t ) +
530
+ measurement_record_data_length + SPDM_NONCE_SIZE +
531
+ sizeof (uint16_t ) + opaque_length + SPDM_REQ_CONTEXT_SIZE ) {
532
+ status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
533
+ goto receive_done ;
534
+ }
535
+ spdm_response_size = sizeof (spdm_measurements_response_t ) +
536
+ measurement_record_data_length +
537
+ SPDM_NONCE_SIZE + sizeof (uint16_t ) +
538
+ opaque_length + SPDM_REQ_CONTEXT_SIZE ;
539
+ } else {
540
+ if (spdm_response_size <
541
+ sizeof (spdm_measurements_response_t ) +
542
+ measurement_record_data_length + SPDM_NONCE_SIZE +
543
+ sizeof (uint16_t ) + opaque_length ) {
544
+ status = LIBSPDM_STATUS_INVALID_MSG_SIZE ;
545
+ goto receive_done ;
546
+ }
547
+ spdm_response_size = sizeof (spdm_measurements_response_t ) +
548
+ measurement_record_data_length +
549
+ SPDM_NONCE_SIZE + sizeof (uint16_t ) +
550
+ opaque_length ;
551
+ }
552
+
553
+ if ((opaque_data != NULL ) && (opaque_data_size != NULL )) {
554
+ if (opaque_length >= * opaque_data_size ) {
555
+ status = LIBSPDM_STATUS_BUFFER_TOO_SMALL ;
556
+ goto receive_done ;
557
+ }
558
+ libspdm_copy_mem (opaque_data , * opaque_data_size , ptr , opaque_length );
559
+ * opaque_data_size = opaque_length ;
560
+ }
561
+ ptr += opaque_length ;
562
+ if (spdm_request -> header .spdm_version >= SPDM_MESSAGE_VERSION_13 ) {
563
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "RequesterContext - " ));
564
+ LIBSPDM_INTERNAL_DUMP_DATA (ptr , SPDM_REQ_CONTEXT_SIZE );
565
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO , "\n" ));
566
+ if (!libspdm_consttime_is_mem_equal ((uint8_t * )spdm_request +
567
+ spdm_request_size - SPDM_REQ_CONTEXT_SIZE ,
568
+ ptr , SPDM_REQ_CONTEXT_SIZE )) {
569
+ status = LIBSPDM_STATUS_INVALID_MSG_FIELD ;
570
+ goto receive_done ;
571
+ }
572
+ ptr += SPDM_REQ_CONTEXT_SIZE ;
491
573
}
492
- spdm_response_size = sizeof (spdm_measurements_response_t ) +
493
- measurement_record_data_length +
494
- SPDM_NONCE_SIZE + sizeof (uint16_t ) +
495
- opaque_length ;
496
574
497
575
/* If a signature is not requested then content_changed must be 0. */
498
576
if (spdm_response -> header .spdm_version >= SPDM_MESSAGE_VERSION_12 ) {
@@ -639,7 +717,7 @@ libspdm_return_t libspdm_get_measurement(void *spdm_context, const uint32_t *ses
639
717
do {
640
718
status = libspdm_try_get_measurement (
641
719
context , session_id , request_attribute ,
642
- measurement_operation , slot_id_param , content_changed , number_of_blocks ,
720
+ measurement_operation , slot_id_param , NULL , content_changed , number_of_blocks ,
643
721
measurement_record_length , measurement_record ,
644
722
NULL , NULL , NULL , NULL , NULL );
645
723
if ((status != LIBSPDM_STATUS_BUSY_PEER ) || (retry == 0 )) {
@@ -678,7 +756,50 @@ libspdm_return_t libspdm_get_measurement_ex(void *spdm_context, const uint32_t *
678
756
do {
679
757
status = libspdm_try_get_measurement (
680
758
context , session_id , request_attribute ,
681
- measurement_operation , slot_id_param , content_changed , number_of_blocks ,
759
+ measurement_operation , slot_id_param , NULL , content_changed , number_of_blocks ,
760
+ measurement_record_length , measurement_record ,
761
+ requester_nonce_in ,
762
+ requester_nonce , responder_nonce ,
763
+ opaque_data , opaque_data_size );
764
+ if ((status != LIBSPDM_STATUS_BUSY_PEER ) || (retry == 0 )) {
765
+ return status ;
766
+ }
767
+
768
+ libspdm_sleep (retry_delay_time );
769
+ } while (retry -- != 0 );
770
+
771
+ return status ;
772
+ }
773
+
774
+ libspdm_return_t libspdm_get_measurement_ex2 (void * spdm_context , const uint32_t * session_id ,
775
+ uint8_t request_attribute ,
776
+ uint8_t measurement_operation ,
777
+ uint8_t slot_id_param ,
778
+ const void * requester_context ,
779
+ uint8_t * content_changed ,
780
+ uint8_t * number_of_blocks ,
781
+ uint32_t * measurement_record_length ,
782
+ void * measurement_record ,
783
+ const void * requester_nonce_in ,
784
+ void * requester_nonce ,
785
+ void * responder_nonce ,
786
+ void * opaque_data ,
787
+ size_t * opaque_data_size )
788
+ {
789
+ libspdm_context_t * context ;
790
+ size_t retry ;
791
+ uint64_t retry_delay_time ;
792
+ libspdm_return_t status ;
793
+
794
+ context = spdm_context ;
795
+ context -> crypto_request = true;
796
+ retry = context -> retry_times ;
797
+ retry_delay_time = context -> retry_delay_time ;
798
+ do {
799
+ status = libspdm_try_get_measurement (
800
+ context , session_id , request_attribute ,
801
+ measurement_operation , slot_id_param , requester_context ,
802
+ content_changed , number_of_blocks ,
682
803
measurement_record_length , measurement_record ,
683
804
requester_nonce_in ,
684
805
requester_nonce , responder_nonce ,
0 commit comments