libspdm_get_scratch_buffer_secure_message_capacity:
   17|    360|uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
   18|    360|    return spdm_context->local_context.capability.max_spdm_msg_size +
   19|    360|           spdm_context->local_context.capability.transport_header_size +
   20|    360|           spdm_context->local_context.capability.transport_tail_size;
   21|    360|}
libspdm_get_scratch_buffer_large_message_capacity:
   28|    360|uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
   29|    360|    return spdm_context->local_context.capability.max_spdm_msg_size;
   30|    360|}
libspdm_get_scratch_buffer_sender_receiver_capacity:
   43|    360|uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
   44|    360|    return spdm_context->local_context.capability.max_spdm_msg_size +
   45|    360|           spdm_context->local_context.capability.transport_header_size +
   46|    360|           spdm_context->local_context.capability.transport_tail_size;
   47|    360|}
libspdm_get_scratch_buffer_large_sender_receiver_capacity:
   58|    360|{
   59|    360|    return spdm_context->local_context.capability.max_spdm_msg_size +
   60|    360|           spdm_context->local_context.capability.transport_header_size +
   61|    360|           spdm_context->local_context.capability.transport_tail_size;
   62|    360|}
libspdm_get_scratch_buffer_last_spdm_request_offset:
   66|    120|uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
   67|    120|    return 0 +
   68|    120|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   69|    120|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   70|    120|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   71|    120|#endif
   72|    120|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   73|    120|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   74|    120|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   75|    120|#endif
   76|    120|           0;
   77|    120|}
libspdm_get_scratch_buffer_last_spdm_request_capacity:
   79|    240|uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
   80|    240|    return spdm_context->local_context.capability.max_spdm_msg_size;
   81|    240|}
libspdm_get_scratch_buffer_cache_spdm_request_offset:
   85|    120|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
   86|    120|    return 0 +
   87|    120|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   88|    120|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   89|    120|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   90|    120|#endif
   91|    120|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   92|    120|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   93|    120|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   94|    120|#endif
   95|    120|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
   96|    120|           0;
   97|    120|}
libspdm_get_scratch_buffer_cache_spdm_request_capacity:
   99|    120|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
  100|    120|    return spdm_context->local_context.capability.max_spdm_msg_size;
  101|    120|}
libspdm_get_scratch_buffer_capacity:
  105|    120|uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
  106|    120|    return 0 +
  107|    120|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  108|    120|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
  109|    120|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
  110|    120|#endif
  111|    120|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
  112|    120|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  113|    120|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
  114|    120|#endif
  115|    120|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
  116|    120|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
  117|    120|           libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
  118|    120|#endif
  119|    120|           0;
  120|    120|}
libspdm_get_connection_version:
 2632|    360|{
 2633|    360|    return (uint8_t)(spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
  ------------------
  |  |  140|    360|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 2634|    360|}
libspdm_is_capabilities_flag_supported:
 2651|     38|{
 2652|     38|    uint32_t negotiated_requester_capabilities_flag;
 2653|     38|    uint32_t negotiated_responder_capabilities_flag;
 2654|       |
 2655|     38|    if (is_requester) {
  ------------------
  |  Branch (2655:9): [True: 0, False: 38]
  ------------------
 2656|      0|        negotiated_requester_capabilities_flag = spdm_context->local_context.capability.flags;
 2657|      0|        negotiated_responder_capabilities_flag = spdm_context->connection_info.capability.flags;
 2658|     38|    } else {
 2659|     38|        negotiated_requester_capabilities_flag = spdm_context->connection_info.capability.flags;
 2660|     38|        negotiated_responder_capabilities_flag = spdm_context->local_context.capability.flags;
 2661|     38|    }
 2662|       |
 2663|     38|    if (((requester_capabilities_flag == 0) ||
  ------------------
  |  Branch (2663:10): [True: 38, False: 0]
  ------------------
 2664|     38|         ((negotiated_requester_capabilities_flag &
  ------------------
  |  Branch (2664:10): [True: 0, False: 0]
  ------------------
 2665|      0|           requester_capabilities_flag) != 0)) &&
 2666|     38|        ((responder_capabilities_flag == 0) ||
  ------------------
  |  Branch (2666:10): [True: 0, False: 38]
  ------------------
 2667|     38|         ((negotiated_responder_capabilities_flag &
  ------------------
  |  Branch (2667:10): [True: 38, False: 0]
  ------------------
 2668|     38|           responder_capabilities_flag) != 0))) {
 2669|     38|        return true;
 2670|     38|    } else {
 2671|      0|        return false;
 2672|      0|    }
 2673|     38|}
libspdm_register_device_io_func:
 2720|    120|{
 2721|    120|    libspdm_context_t *context;
 2722|       |
 2723|    120|    context = spdm_context;
 2724|    120|    context->send_message = send_message;
 2725|    120|    context->receive_message = receive_message;
 2726|    120|}
libspdm_register_device_buffer_func:
 2779|    120|{
 2780|    120|    libspdm_context_t *context;
 2781|       |
 2782|    120|    context = spdm_context;
 2783|    120|    context->sender_buffer_size = sender_buffer_size;
 2784|    120|    context->receiver_buffer_size = receiver_buffer_size;
 2785|    120|    context->acquire_sender_buffer = acquire_sender_buffer;
 2786|    120|    context->release_sender_buffer = release_sender_buffer;
 2787|    120|    context->acquire_receiver_buffer = acquire_receiver_buffer;
 2788|    120|    context->release_receiver_buffer = release_receiver_buffer;
 2789|       |
 2790|    120|    LIBSPDM_ASSERT (sender_buffer_size >=
 2791|    120|                    context->local_context.capability.transport_header_size +
 2792|    120|                    context->local_context.capability.transport_tail_size);
 2793|    120|    sender_buffer_size -= (context->local_context.capability.transport_header_size +
 2794|    120|                           context->local_context.capability.transport_tail_size);
 2795|    120|    LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2796|    120|    context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
 2797|       |
 2798|    120|    LIBSPDM_ASSERT(receiver_buffer_size >=
 2799|    120|                   context->local_context.capability.transport_header_size +
 2800|    120|                   context->local_context.capability.transport_tail_size);
 2801|    120|    receiver_buffer_size -= (context->local_context.capability.transport_header_size +
 2802|    120|                             context->local_context.capability.transport_tail_size);
 2803|    120|    LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2804|    120|    context->local_context.capability.data_transfer_size = receiver_buffer_size;
 2805|    120|}
libspdm_register_transport_layer_func:
 2823|    120|{
 2824|    120|    libspdm_context_t *context;
 2825|       |
 2826|    120|    context = spdm_context;
 2827|       |
 2828|       |    /* fix the data_transfer_size if it is set before */
 2829|    120|    if ((context->local_context.capability.data_transfer_size != 0) &&
  ------------------
  |  Branch (2829:9): [True: 0, False: 120]
  ------------------
 2830|    120|        (context->local_context.capability.data_transfer_size ==
  ------------------
  |  Branch (2830:9): [True: 0, False: 0]
  ------------------
 2831|      0|         context->receiver_buffer_size)) {
 2832|      0|        context->local_context.capability.data_transfer_size =
 2833|      0|            (uint32_t)(context->receiver_buffer_size -
 2834|      0|                       (transport_header_size + transport_tail_size));
 2835|      0|    }
 2836|    120|    if ((context->local_context.capability.sender_data_transfer_size != 0) &&
  ------------------
  |  Branch (2836:9): [True: 0, False: 120]
  ------------------
 2837|    120|        (context->local_context.capability.sender_data_transfer_size ==
  ------------------
  |  Branch (2837:9): [True: 0, False: 0]
  ------------------
 2838|      0|         context->sender_buffer_size)) {
 2839|      0|        context->local_context.capability.sender_data_transfer_size =
 2840|      0|            (uint32_t)(context->sender_buffer_size -
 2841|      0|                       (transport_header_size + transport_tail_size));
 2842|      0|    }
 2843|       |
 2844|    120|    context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
 2845|    120|    context->local_context.capability.transport_header_size = transport_header_size;
 2846|    120|    context->local_context.capability.transport_tail_size = transport_tail_size;
 2847|    120|    context->transport_encode_message = transport_encode_message;
 2848|    120|    context->transport_decode_message = transport_decode_message;
 2849|    120|}
libspdm_get_sizeof_required_scratch_buffer:
 2886|    120|{
 2887|    120|    libspdm_context_t *context;
 2888|    120|    size_t scratch_buffer_size;
 2889|       |
 2890|    120|    context = spdm_context;
 2891|    120|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2892|       |
 2893|    120|    scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
 2894|    120|    return scratch_buffer_size;
 2895|    120|}
libspdm_set_scratch_buffer:
 2911|    120|{
 2912|    120|    libspdm_context_t *context;
 2913|       |
 2914|    120|    context = spdm_context;
 2915|    120|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2916|    120|    LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
 2917|    120|    context->scratch_buffer = scratch_buffer;
 2918|    120|    context->scratch_buffer_size = scratch_buffer_size;
 2919|    120|    context->last_spdm_request = (uint8_t *)scratch_buffer +
 2920|    120|                                 libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
 2921|    120|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2922|    120|    context->cache_spdm_request = (uint8_t *)scratch_buffer +
 2923|    120|                                  libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
 2924|    120|#endif
 2925|    120|}
libspdm_init_context_with_secured_context:
 3240|    120|{
 3241|    120|    libspdm_context_t *context;
 3242|    120|    size_t index;
 3243|       |
 3244|    120|    LIBSPDM_ASSERT(spdm_context != NULL);
 3245|    120|    LIBSPDM_ASSERT(secured_contexts != NULL);
 3246|    120|    LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
 3247|       |
 3248|    120|    context = spdm_context;
 3249|    120|    libspdm_zero_mem(context, sizeof(libspdm_context_t));
 3250|    120|    context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
  ------------------
  |  |  527|    120|#define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
  ------------------
 3251|    120|    context->transcript.message_a.max_buffer_size =
 3252|    120|        sizeof(context->transcript.message_a.buffer);
 3253|    120|    context->transcript.message_d.max_buffer_size =
 3254|    120|        sizeof(context->transcript.message_d.buffer);
 3255|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 3256|       |    context->transcript.message_b.max_buffer_size =
 3257|       |        sizeof(context->transcript.message_b.buffer);
 3258|       |    context->transcript.message_c.max_buffer_size =
 3259|       |        sizeof(context->transcript.message_c.buffer);
 3260|       |    context->transcript.message_mut_b.max_buffer_size =
 3261|       |        sizeof(context->transcript.message_mut_b.buffer);
 3262|       |    context->transcript.message_mut_c.max_buffer_size =
 3263|       |        sizeof(context->transcript.message_mut_c.buffer);
 3264|       |    context->transcript.message_m.max_buffer_size =
 3265|       |        sizeof(context->transcript.message_m.buffer);
 3266|       |    context->transcript.message_e.max_buffer_size =
 3267|       |        sizeof(context->transcript.message_e.buffer);
 3268|       |    context->transcript.message_encap_e.max_buffer_size =
 3269|       |        sizeof(context->transcript.message_encap_e.buffer);
 3270|       |#endif
 3271|    120|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3272|    120|    context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   17|    120|#define SPDM_MAX_VERSION_COUNT 4
  ------------------
 3273|    120|    context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|    120|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
 3274|    120|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    120|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3275|    120|    context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    120|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 3276|    120|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    120|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3277|    120|    context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    120|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
 3278|    120|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    120|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3279|    120|    context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|    120|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
 3280|    120|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    120|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3281|    120|    context->local_context.secured_message_version.spdm_version_count =
 3282|    120|        SECURED_SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   55|    120|#define SECURED_SPDM_MAX_VERSION_COUNT 3
  ------------------
 3283|    120|    context->local_context.secured_message_version.spdm_version[0] =
 3284|    120|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|    120|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    120|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3285|    120|    context->local_context.secured_message_version.spdm_version[1] =
 3286|    120|        SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   58|    120|#define SECURED_SPDM_VERSION_11 0x11
  ------------------
                      SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    120|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3287|    120|    context->local_context.secured_message_version.spdm_version[2] =
 3288|    120|        SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   59|    120|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
                      SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    120|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3289|    120|    context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
  ------------------
  |  | 1514|    120|#define SPDM_ST1_VALUE_US 100000
  ------------------
 3290|       |
 3291|    120|    context->mut_auth_cert_chain_buffer_size = 0;
 3292|       |
 3293|    120|    context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
  ------------------
  |  |   39|    120|#define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
  ------------------
 3294|       |
 3295|    120|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    120|#define INVALID_SESSION_ID 0
  ------------------
 3296|    120|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    120|#define INVALID_SESSION_ID 0
  ------------------
 3297|    120|    context->last_spdm_request_session_id_valid = false;
 3298|    120|    context->last_spdm_request_size = 0;
 3299|       |
 3300|       |    /* To be updated in libspdm_register_device_buffer_func */
 3301|    120|    context->local_context.capability.data_transfer_size = 0;
 3302|    120|    context->local_context.capability.sender_data_transfer_size = 0;
 3303|    120|    context->local_context.capability.max_spdm_msg_size = 0;
 3304|       |
 3305|    600|    for (index = 0; index < num_secured_contexts; index++) {
  ------------------
  |  Branch (3305:21): [True: 480, False: 120]
  ------------------
 3306|    480|        if (secured_contexts[index] == NULL) {
  ------------------
  |  Branch (3306:13): [True: 0, False: 480]
  ------------------
 3307|      0|            return LIBSPDM_STATUS_INVALID_PARAMETER;
  ------------------
  |  |   73|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0001)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3308|      0|        }
 3309|       |
 3310|    480|        context->session_info[index].secured_message_context = secured_contexts[index];
 3311|    480|        libspdm_secured_message_init_context(
 3312|    480|            context->session_info[index].secured_message_context);
 3313|    480|    }
 3314|       |
 3315|    120|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    120|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    120|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3316|    120|}
libspdm_init_context:
 3331|    120|{
 3332|    120|    libspdm_context_t *context;
 3333|    120|    void *secured_context;
 3334|    120|    void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
 3335|    120|    size_t secured_context_size;
 3336|    120|    size_t index;
 3337|       |
 3338|    120|    LIBSPDM_ASSERT(spdm_context != NULL);
 3339|       |
 3340|       |    /* libspdm_get_context_size() allocates space for all secured message
 3341|       |     * contexts. They are appended to the general SPDM context. */
 3342|    120|    context = spdm_context;
 3343|    120|    secured_context = (void *)((size_t)(context + 1));
 3344|    120|    secured_context_size = libspdm_secured_message_get_context_size();
 3345|       |
 3346|    600|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|    600|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3346:21): [True: 480, False: 120]
  ------------------
 3347|    480|    {
 3348|    480|        secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
 3349|    480|    }
 3350|       |
 3351|    120|    return libspdm_init_context_with_secured_context(spdm_context,
 3352|    120|                                                     secured_contexts,
 3353|    120|                                                     LIBSPDM_MAX_SESSION_COUNT);
  ------------------
  |  |  198|    120|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3354|    120|}
libspdm_get_context_size:
 3467|    120|{
 3468|    120|    size_t size;
 3469|       |
 3470|    120|    size = sizeof(libspdm_context_t) +
 3471|    120|           libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
  ------------------
  |  |  198|    120|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3472|    120|    LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
 3473|    120|    return size;
 3474|    120|}

libspdm_generate_error_response:
   14|    120|{
   15|    120|    spdm_error_response_t *spdm_response;
   16|       |
   17|    120|    LIBSPDM_ASSERT(*response_size >= sizeof(spdm_error_response_t));
   18|    120|    *response_size = sizeof(spdm_error_response_t);
   19|    120|    spdm_response = response;
   20|       |
   21|    120|    spdm_response->header.spdm_version = libspdm_get_connection_version (spdm_context);
   22|    120|    if (spdm_response->header.spdm_version == 0) {
  ------------------
  |  Branch (22:9): [True: 0, False: 120]
  ------------------
   23|       |        /* if version is not negotiated, then use default version 1.0 */
   24|      0|        spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
  ------------------
  |  |  110|      0|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
   25|      0|    }
   26|    120|    spdm_response->header.request_response_code = SPDM_ERROR;
  ------------------
  |  |   37|    120|#define SPDM_ERROR 0x7F
  ------------------
   27|    120|    spdm_response->header.param1 = error_code;
   28|    120|    spdm_response->header.param2 = error_data;
   29|       |
   30|    120|    if (spdm_response->header.spdm_version <= SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|    120|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  |  Branch (30:9): [True: 0, False: 120]
  ------------------
   31|      0|        LIBSPDM_ASSERT ((error_code != SPDM_ERROR_CODE_RESPONSE_TOO_LARGE) &&
   32|      0|                        (error_code != SPDM_ERROR_CODE_LARGE_RESPONSE));
   33|      0|    }
   34|       |
   35|    120|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    120|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    120|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   36|    120|}

libspdm_get_response_key_pair_info:
   14|    120|{
   15|    120|    const spdm_get_key_pair_info_request_t *spdm_request;
   16|    120|    spdm_key_pair_info_response_t *spdm_response;
   17|       |
   18|    120|    libspdm_session_info_t *session_info;
   19|    120|    libspdm_session_state_t session_state;
   20|       |
   21|    120|    uint8_t total_key_pairs;
   22|    120|    uint16_t capabilities;
   23|    120|    uint16_t key_usage_capabilities;
   24|    120|    uint16_t current_key_usage;
   25|    120|    uint32_t asym_algo_capabilities;
   26|    120|    uint32_t current_asym_algo;
   27|    120|    uint16_t public_key_info_len;
   28|    120|    uint8_t assoc_cert_slot_mask;
   29|    120|    uint8_t key_pair_id;
   30|    120|    bool result;
   31|    120|    uint8_t *public_key_info;
   32|       |
   33|    120|    spdm_request = request;
   34|       |
   35|       |    /* -=[Check Parameters Phase]=- */
   36|    120|    LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_KEY_PAIR_INFO);
   37|       |
   38|    120|    if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
  ------------------
  |  |  113|    120|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
  |  Branch (38:9): [True: 0, False: 120]
  ------------------
   39|      0|        return libspdm_generate_error_response(spdm_context,
   40|      0|                                               SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
  ------------------
  |  |  859|      0|#define SPDM_ERROR_CODE_UNSUPPORTED_REQUEST 0x07
  ------------------
   41|      0|                                               SPDM_GET_KEY_PAIR_INFO,
  ------------------
  |  |   99|      0|#define SPDM_GET_KEY_PAIR_INFO 0xFC
  ------------------
   42|      0|                                               response_size, response);
   43|      0|    }
   44|       |
   45|    120|    if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
  ------------------
  |  Branch (45:9): [True: 79, False: 41]
  ------------------
   46|     79|        return libspdm_generate_error_response(spdm_context,
   47|     79|                                               SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
  ------------------
  |  |  860|     79|#define SPDM_ERROR_CODE_VERSION_MISMATCH 0x41
  ------------------
   48|     79|                                               response_size, response);
   49|     79|    }
   50|       |
   51|     41|    if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
  ------------------
  |  Branch (51:9): [True: 0, False: 41]
  ------------------
   52|      0|        return libspdm_responder_handle_response_state(spdm_context,
   53|      0|                                                       spdm_request->header.request_response_code,
   54|      0|                                                       response_size, response);
   55|      0|    }
   56|       |
   57|     41|    if (request_size < sizeof(spdm_get_key_pair_info_request_t)) {
  ------------------
  |  Branch (57:9): [True: 3, False: 38]
  ------------------
   58|      3|        return libspdm_generate_error_response(spdm_context,
   59|      3|                                               SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|      3|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
   60|      3|                                               response_size, response);
   61|      3|    }
   62|       |
   63|     38|    if (spdm_context->connection_info.connection_state <
  ------------------
  |  Branch (63:9): [True: 0, False: 38]
  ------------------
   64|     38|        LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
   65|      0|        return libspdm_generate_error_response(
   66|      0|            spdm_context,
   67|      0|            SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   68|      0|            response_size, response);
   69|      0|    }
   70|       |
   71|     38|    if (spdm_context->last_spdm_request_session_id_valid) {
  ------------------
  |  Branch (71:9): [True: 0, False: 38]
  ------------------
   72|      0|        session_info = libspdm_get_session_info_via_session_id(
   73|      0|            spdm_context,
   74|      0|            spdm_context->last_spdm_request_session_id);
   75|      0|        if (session_info == NULL) {
  ------------------
  |  Branch (75:13): [True: 0, False: 0]
  ------------------
   76|      0|            return libspdm_generate_error_response(
   77|      0|                spdm_context,
   78|      0|                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   79|      0|                response_size, response);
   80|      0|        }
   81|      0|        session_state = libspdm_secured_message_get_session_state(
   82|      0|            session_info->secured_message_context);
   83|      0|        if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
  ------------------
  |  Branch (83:13): [True: 0, False: 0]
  ------------------
   84|      0|            return libspdm_generate_error_response(
   85|      0|                spdm_context,
   86|      0|                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   87|      0|                response_size, response);
   88|      0|        }
   89|      0|    }
   90|       |
   91|     38|    if (!libspdm_is_capabilities_flag_supported(
  ------------------
  |  Branch (91:9): [True: 0, False: 38]
  ------------------
   92|     38|            spdm_context, false, 0,
   93|     38|            SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP)) {
  ------------------
  |  |  298|     38|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP 0x10000000
  ------------------
   94|      0|        return libspdm_generate_error_response(
   95|      0|            spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
  ------------------
  |  |  859|      0|#define SPDM_ERROR_CODE_UNSUPPORTED_REQUEST 0x07
  ------------------
   96|      0|            SPDM_GET_KEY_PAIR_INFO, response_size, response);
  ------------------
  |  |   99|      0|#define SPDM_GET_KEY_PAIR_INFO 0xFC
  ------------------
   97|      0|    }
   98|       |
   99|     38|    total_key_pairs = spdm_context->local_context.total_key_pairs;
  100|     38|    key_pair_id = spdm_request->key_pair_id;
  101|     38|    if ((key_pair_id == 0) || (key_pair_id > total_key_pairs)) {
  ------------------
  |  Branch (101:9): [True: 1, False: 37]
  |  Branch (101:31): [True: 37, False: 0]
  ------------------
  102|     38|        return libspdm_generate_error_response(spdm_context,
  103|     38|                                               SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|     38|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
  104|     38|                                               response_size, response);
  105|     38|    }
  106|       |
  107|      0|    LIBSPDM_ASSERT(*response_size >= sizeof(spdm_key_pair_info_response_t));
  108|      0|    public_key_info_len = (uint16_t)(*response_size - sizeof(spdm_key_pair_info_response_t));
  109|      0|    libspdm_zero_mem(response, *response_size);
  110|       |
  111|      0|    public_key_info = (uint8_t*)response + sizeof(spdm_key_pair_info_response_t);
  112|      0|    result = libspdm_read_key_pair_info(
  113|      0|        spdm_context,
  114|      0|        key_pair_id,
  115|      0|        &capabilities,
  116|      0|        &key_usage_capabilities,
  117|      0|        &current_key_usage,
  118|      0|        &asym_algo_capabilities,
  119|      0|        &current_asym_algo,
  120|      0|        &assoc_cert_slot_mask,
  121|      0|        &public_key_info_len,
  122|      0|        public_key_info);
  123|      0|    if (!result) {
  ------------------
  |  Branch (123:9): [True: 0, False: 0]
  ------------------
  124|      0|        return libspdm_generate_error_response(spdm_context,
  125|      0|                                               SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|      0|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
  126|      0|                                               response_size, response);
  127|      0|    }
  128|       |
  129|       |    /*If responder doesn't support SET_KEY_PAIR_INFO_CAP,the capabilities should be 0*/
  130|      0|    if (!libspdm_is_capabilities_flag_supported(
  ------------------
  |  Branch (130:9): [True: 0, False: 0]
  ------------------
  131|      0|            spdm_context, false, 0,
  132|      0|            SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP)) {
  ------------------
  |  |  299|      0|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP 0x20000000
  ------------------
  133|      0|        capabilities = 0;
  134|      0|    }
  135|       |
  136|      0|    spdm_response = response;
  137|      0|    *response_size = sizeof(spdm_key_pair_info_response_t) + public_key_info_len;
  138|       |
  139|      0|    spdm_response->header.spdm_version = spdm_request->header.spdm_version;
  140|      0|    spdm_response->header.request_response_code = SPDM_KEY_PAIR_INFO;
  ------------------
  |  |   62|      0|#define SPDM_KEY_PAIR_INFO 0x7C
  ------------------
  141|      0|    spdm_response->header.param1 = 0;
  142|      0|    spdm_response->header.param2 = 0;
  143|      0|    spdm_response->total_key_pairs = total_key_pairs;
  144|      0|    spdm_response->key_pair_id = key_pair_id;
  145|      0|    spdm_response->capabilities = capabilities & SPDM_KEY_PAIR_CAP_MASK;
  ------------------
  |  | 1412|      0|#define SPDM_KEY_PAIR_CAP_MASK ( \
  |  | 1413|      0|        SPDM_KEY_PAIR_CAP_GEN_KEY_CAP | \
  |  |  ------------------
  |  |  |  | 1406|      0|#define SPDM_KEY_PAIR_CAP_GEN_KEY_CAP 0x00000001
  |  |  ------------------
  |  | 1414|      0|        SPDM_KEY_PAIR_CAP_ERASABLE_CAP | \
  |  |  ------------------
  |  |  |  | 1407|      0|#define SPDM_KEY_PAIR_CAP_ERASABLE_CAP 0x00000002
  |  |  ------------------
  |  | 1415|      0|        SPDM_KEY_PAIR_CAP_CERT_ASSOC_CAP | \
  |  |  ------------------
  |  |  |  | 1408|      0|#define SPDM_KEY_PAIR_CAP_CERT_ASSOC_CAP 0x00000004
  |  |  ------------------
  |  | 1416|      0|        SPDM_KEY_PAIR_CAP_KEY_USAGE_CAP | \
  |  |  ------------------
  |  |  |  | 1409|      0|#define SPDM_KEY_PAIR_CAP_KEY_USAGE_CAP 0x00000008
  |  |  ------------------
  |  | 1417|      0|        SPDM_KEY_PAIR_CAP_ASYM_ALGO_CAP | \
  |  |  ------------------
  |  |  |  | 1410|      0|#define SPDM_KEY_PAIR_CAP_ASYM_ALGO_CAP 0x00000010
  |  |  ------------------
  |  | 1418|      0|        SPDM_KEY_PAIR_CAP_SHAREABLE_CAP)
  |  |  ------------------
  |  |  |  | 1411|      0|#define SPDM_KEY_PAIR_CAP_SHAREABLE_CAP 0x00000020
  |  |  ------------------
  ------------------
  146|      0|    spdm_response->key_usage_capabilities = key_usage_capabilities & SPDM_KEY_USAGE_BIT_MASK;
  ------------------
  |  |  610|      0|#define SPDM_KEY_USAGE_BIT_MASK ( \
  |  |  611|      0|        SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE | \
  |  |  ------------------
  |  |  |  |  603|      0|#define SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE 0x0001
  |  |  ------------------
  |  |  612|      0|        SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE | \
  |  |  ------------------
  |  |  |  |  604|      0|#define SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE 0x0002
  |  |  ------------------
  |  |  613|      0|        SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE | \
  |  |  ------------------
  |  |  |  |  605|      0|#define SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE 0x0004
  |  |  ------------------
  |  |  614|      0|        SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE | \
  |  |  ------------------
  |  |  |  |  606|      0|#define SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE 0x0008
  |  |  ------------------
  |  |  615|      0|        SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE | \
  |  |  ------------------
  |  |  |  |  607|      0|#define SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE 0x4000
  |  |  ------------------
  |  |  616|      0|        SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE)
  |  |  ------------------
  |  |  |  |  608|      0|#define SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE 0x8000
  |  |  ------------------
  ------------------
  147|      0|    spdm_response->current_key_usage = current_key_usage & SPDM_KEY_USAGE_BIT_MASK;
  ------------------
  |  |  610|      0|#define SPDM_KEY_USAGE_BIT_MASK ( \
  |  |  611|      0|        SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE | \
  |  |  ------------------
  |  |  |  |  603|      0|#define SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE 0x0001
  |  |  ------------------
  |  |  612|      0|        SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE | \
  |  |  ------------------
  |  |  |  |  604|      0|#define SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE 0x0002
  |  |  ------------------
  |  |  613|      0|        SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE | \
  |  |  ------------------
  |  |  |  |  605|      0|#define SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE 0x0004
  |  |  ------------------
  |  |  614|      0|        SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE | \
  |  |  ------------------
  |  |  |  |  606|      0|#define SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE 0x0008
  |  |  ------------------
  |  |  615|      0|        SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE | \
  |  |  ------------------
  |  |  |  |  607|      0|#define SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE 0x4000
  |  |  ------------------
  |  |  616|      0|        SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE)
  |  |  ------------------
  |  |  |  |  608|      0|#define SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE 0x8000
  |  |  ------------------
  ------------------
  148|      0|    spdm_response->asym_algo_capabilities = asym_algo_capabilities &
  149|      0|                                            SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
  ------------------
  |  | 1430|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK ( \
  |  | 1431|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 | \
  |  |  ------------------
  |  |  |  | 1421|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 0x00000001
  |  |  ------------------
  |  | 1432|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072 | \
  |  |  ------------------
  |  |  |  | 1422|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072 0x00000002
  |  |  ------------------
  |  | 1433|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA4096 | \
  |  |  ------------------
  |  |  |  | 1423|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA4096 0x00000004
  |  |  ------------------
  |  | 1434|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256 | \
  |  |  ------------------
  |  |  |  | 1424|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256 0x00000008
  |  |  ------------------
  |  | 1435|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC384 | \
  |  |  ------------------
  |  |  |  | 1425|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC384 0x00000010
  |  |  ------------------
  |  | 1436|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC521 | \
  |  |  ------------------
  |  |  |  | 1426|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC521 0x00000020
  |  |  ------------------
  |  | 1437|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_SM2 | \
  |  |  ------------------
  |  |  |  | 1427|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_SM2 0x00000040
  |  |  ------------------
  |  | 1438|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED25519 | \
  |  |  ------------------
  |  |  |  | 1428|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED25519 0x00000080
  |  |  ------------------
  |  | 1439|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448)
  |  |  ------------------
  |  |  |  | 1429|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448 0x00000100
  |  |  ------------------
  ------------------
  150|      0|    spdm_response->current_asym_algo = current_asym_algo & SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK;
  ------------------
  |  | 1430|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_MASK ( \
  |  | 1431|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 | \
  |  |  ------------------
  |  |  |  | 1421|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA2048 0x00000001
  |  |  ------------------
  |  | 1432|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072 | \
  |  |  ------------------
  |  |  |  | 1422|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA3072 0x00000002
  |  |  ------------------
  |  | 1433|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA4096 | \
  |  |  ------------------
  |  |  |  | 1423|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_RSA4096 0x00000004
  |  |  ------------------
  |  | 1434|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256 | \
  |  |  ------------------
  |  |  |  | 1424|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC256 0x00000008
  |  |  ------------------
  |  | 1435|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC384 | \
  |  |  ------------------
  |  |  |  | 1425|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC384 0x00000010
  |  |  ------------------
  |  | 1436|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC521 | \
  |  |  ------------------
  |  |  |  | 1426|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ECC521 0x00000020
  |  |  ------------------
  |  | 1437|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_SM2 | \
  |  |  ------------------
  |  |  |  | 1427|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_SM2 0x00000040
  |  |  ------------------
  |  | 1438|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED25519 | \
  |  |  ------------------
  |  |  |  | 1428|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED25519 0x00000080
  |  |  ------------------
  |  | 1439|      0|        SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448)
  |  |  ------------------
  |  |  |  | 1429|      0|#define SPDM_KEY_PAIR_ASYM_ALGO_CAP_ED448 0x00000100
  |  |  ------------------
  ------------------
  151|      0|    spdm_response->public_key_info_len = public_key_info_len;
  152|      0|    spdm_response->assoc_cert_slot_mask = assoc_cert_slot_mask;
  153|       |
  154|      0|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  155|      0|}

libspdm_secured_message_get_context_size:
   15|    240|{
   16|    240|    return sizeof(libspdm_secured_message_context_t);
   17|    240|}
libspdm_secured_message_init_context:
   27|    480|{
   28|    480|    libspdm_secured_message_context_t *secured_message_context;
   29|       |
   30|    480|    secured_message_context = spdm_secured_message_context;
   31|    480|    libspdm_zero_mem(secured_message_context, sizeof(libspdm_secured_message_context_t));
   32|    480|}

allocate_zero_pool:
   20|    120|{
   21|    120|    void *buffer;
   22|    120|    buffer = malloc(AllocationSize);
   23|    120|    if (buffer == NULL) {
  ------------------
  |  Branch (23:9): [True: 0, False: 120]
  ------------------
   24|      0|        return NULL;
   25|      0|    }
   26|    120|    memset(buffer, 0, AllocationSize);
   27|    120|    return buffer;
   28|    120|}

libspdm_copy_mem:
   12|     81|{
   13|     81|    volatile uint8_t* dst;
   14|     81|    const volatile uint8_t* src;
   15|       |
   16|     81|    dst = (volatile uint8_t*) dst_buf;
   17|     81|    src = (const volatile uint8_t*) src_buf;
   18|       |
   19|     81|    if ((dst == NULL) || (src == NULL)) {
  ------------------
  |  Branch (19:9): [True: 0, False: 81]
  |  Branch (19:26): [True: 0, False: 81]
  ------------------
   20|      0|        LIBSPDM_ASSERT(0);
   21|      0|    }
   22|     81|    if (((src < dst) && ((src + src_len) > dst)) || ((dst < src) && ((dst + src_len) > src))) {
  ------------------
  |  Branch (22:10): [True: 81, False: 0]
  |  Branch (22:25): [True: 0, False: 81]
  |  Branch (22:54): [True: 0, False: 81]
  |  Branch (22:69): [True: 0, False: 0]
  ------------------
   23|      0|        LIBSPDM_ASSERT(0);
   24|      0|    }
   25|     81|    if (src_len > dst_len) {
  ------------------
  |  Branch (25:9): [True: 0, False: 81]
  ------------------
   26|      0|        LIBSPDM_ASSERT(0);
   27|      0|    }
   28|       |
   29|  52.4k|    while (src_len-- != 0) {
  ------------------
  |  Branch (29:12): [True: 52.3k, False: 81]
  ------------------
   30|  52.3k|        *(dst++) = *(src++);
   31|  52.3k|    }
   32|     81|}

libspdm_zero_mem:
   17|    600|{
   18|       |
   19|       |#if defined(__STDC_LIB_EXT1__)
   20|       |    memset_s(buffer, length, 0, length);
   21|       |#elif defined(_WIN32)
   22|       |    SecureZeroMemory(buffer, length);
   23|       |#elif defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
   24|       |    explicit_bzero(buffer, length);
   25|       |#else
   26|    600|    volatile uint8_t *pointer;
   27|       |
   28|    600|    pointer = (uint8_t *)buffer;
   29|  1.50M|    while (length-- != 0) {
  ------------------
  |  Branch (29:12): [True: 1.50M, False: 600]
  ------------------
   30|  1.50M|        *(pointer++) = 0;
   31|  1.50M|    }
   32|       |
   33|       |#if defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
   34|       |    _ReadWriteBarrier();
   35|       |#elif defined(__GNUC__)
   36|       |    __asm__ __volatile__ ("" : : : "memory");
   37|    600|#endif
   38|       |
   39|    600|#endif
   40|    600|}

libspdm_setup_test_context:
   59|    120|{
   60|    120|    m_libspdm_test_context = spdm_test_context;
   61|    120|}
libspdm_unit_test_group_setup:
   64|    120|{
   65|    120|    libspdm_test_context_t *spdm_test_context;
   66|    120|    void *spdm_context;
   67|       |
   68|    120|    spdm_test_context = m_libspdm_test_context;
   69|    120|    spdm_test_context->spdm_context =
   70|    120|        (void *)malloc(libspdm_get_context_size());
   71|    120|    if (spdm_test_context->spdm_context == NULL) {
  ------------------
  |  Branch (71:9): [True: 0, False: 120]
  ------------------
   72|      0|        return (size_t)-1;
   73|      0|    }
   74|    120|    spdm_context = spdm_test_context->spdm_context;
   75|       |
   76|    120|    libspdm_init_context(spdm_context);
   77|       |
   78|    120|    libspdm_register_device_io_func(spdm_context,
   79|    120|                                    spdm_test_context->send_message,
   80|    120|                                    spdm_test_context->receive_message);
   81|    120|    libspdm_register_transport_layer_func(spdm_context,
   82|    120|                                          LIBSPDM_MAX_SPDM_MSG_SIZE,
  ------------------
  |  |  101|    120|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   83|    120|                                          LIBSPDM_TEST_TRANSPORT_HEADER_SIZE,
  ------------------
  |  |   27|    120|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |   28|    120|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  ------------------
  |  |  |  |   16|    120|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  ------------------
  ------------------
   84|    120|                                          LIBSPDM_TEST_TRANSPORT_TAIL_SIZE,
  ------------------
  |  |   30|    120|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  ------------------
  |  |  |  |   17|    120|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  ------------------
  |  |   31|    120|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  ------------------
  |  |  |  |   75|    120|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  ------------------
  |  |   32|    120|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  ------------------
  |  |  |  |   15|    120|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  ------------------
  ------------------
   85|    120|                                          libspdm_transport_test_encode_message,
   86|    120|                                          libspdm_transport_test_decode_message);
   87|    120|    libspdm_register_device_buffer_func(spdm_context,
   88|    120|                                        LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
  ------------------
  |  |   93|    120|#define LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE LIBSPDM_RECEIVER_BUFFER_SIZE
  |  |  ------------------
  |  |  |  |   78|    120|#define LIBSPDM_RECEIVER_BUFFER_SIZE (0x1200 + \
  |  |  |  |   79|    120|                                      LIBSPDM_TRANSPORT_ADDITIONAL_SIZE)
  |  |  |  |  ------------------
  |  |  |  |  |  |   70|    120|#define LIBSPDM_TRANSPORT_ADDITIONAL_SIZE    (LIBSPDM_TEST_TRANSPORT_HEADER_SIZE + \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   27|    120|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |  |  |  |  |  |  |   28|    120|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   16|    120|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   71|    120|                                              LIBSPDM_TEST_TRANSPORT_TAIL_SIZE)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   30|    120|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   17|    120|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|    120|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   75|    120|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    120|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   15|    120|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|    120|                                        LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
  ------------------
  |  |   93|    120|#define LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE LIBSPDM_RECEIVER_BUFFER_SIZE
  |  |  ------------------
  |  |  |  |   78|    120|#define LIBSPDM_RECEIVER_BUFFER_SIZE (0x1200 + \
  |  |  |  |   79|    120|                                      LIBSPDM_TRANSPORT_ADDITIONAL_SIZE)
  |  |  |  |  ------------------
  |  |  |  |  |  |   70|    120|#define LIBSPDM_TRANSPORT_ADDITIONAL_SIZE    (LIBSPDM_TEST_TRANSPORT_HEADER_SIZE + \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   27|    120|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |  |  |  |  |  |  |   28|    120|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   16|    120|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   71|    120|                                              LIBSPDM_TEST_TRANSPORT_TAIL_SIZE)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   30|    120|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   17|    120|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|    120|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   75|    120|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    120|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   15|    120|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|    120|                                        spdm_device_acquire_sender_buffer,
   91|    120|                                        spdm_device_release_sender_buffer,
   92|    120|                                        spdm_device_acquire_receiver_buffer,
   93|    120|                                        spdm_device_release_receiver_buffer);
   94|       |
   95|    120|    spdm_test_context->scratch_buffer_size =
   96|    120|        libspdm_get_sizeof_required_scratch_buffer(spdm_context);
   97|    120|    spdm_test_context->scratch_buffer = (void *)malloc(spdm_test_context->scratch_buffer_size);
   98|    120|    libspdm_set_scratch_buffer (spdm_context,
   99|    120|                                spdm_test_context->scratch_buffer,
  100|    120|                                spdm_test_context->scratch_buffer_size);
  101|       |
  102|    120|    *State = spdm_test_context;
  103|    120|    return 0;
  104|    120|}
libspdm_unit_test_group_teardown:
  107|    120|{
  108|    120|    libspdm_test_context_t *spdm_test_context;
  109|       |
  110|    120|    spdm_test_context = *State;
  111|    120|    free(spdm_test_context->spdm_context);
  112|    120|    free(spdm_test_context->scratch_buffer);
  113|    120|    spdm_test_context->spdm_context = NULL;
  114|    120|    return 0;
  115|    120|}

libspdm_alignment_size:
   21|    120|{
   22|    120|    size_t alignment;
   23|    120|    size_t max_buffer_size;
   24|       |
   25|    120|    alignment = LIBSPDM_TEST_ALIGNMENT;
  ------------------
  |  |   15|    120|#define LIBSPDM_TEST_ALIGNMENT 4
  ------------------
   26|    120|    max_buffer_size = libspdm_get_max_buffer_size();
   27|       |
   28|       |    /* In the situation where max_buffer_size is not four-byte aligned, reserve sufficient size for the buffer_size */
   29|    120|    if ((size > max_buffer_size - alignment) && (size & (alignment - 1)) != 0) {
  ------------------
  |  Branch (29:9): [True: 43, False: 77]
  |  Branch (29:49): [True: 3, False: 40]
  ------------------
   30|      3|        size -= alignment;
   31|      3|    }
   32|       |
   33|    120|    if (((size) & (alignment - 1)) == 3) {
  ------------------
  |  Branch (33:9): [True: 17, False: 103]
  ------------------
   34|     17|        size += 1;
   35|     17|    }
   36|    120|    if (((size) & (alignment - 1)) == 2) {
  ------------------
  |  Branch (36:9): [True: 14, False: 106]
  ------------------
   37|     14|        size += 2;
   38|     14|    }
   39|    120|    if (((size) & (alignment - 1)) == 1) {
  ------------------
  |  Branch (39:9): [True: 36, False: 84]
  ------------------
   40|     36|        size += 3;
   41|     36|    }
   42|    120|    return size;
   43|    120|}
LLVMFuzzerTestOneInput:
  112|    120|{
  113|    120|    void *test_buffer;
  114|    120|    size_t max_buffer_size;
  115|       |
  116|       |    /* 1. Initialize test_buffer*/
  117|    120|    max_buffer_size = libspdm_get_max_buffer_size();
  118|    120|    test_buffer = allocate_zero_pool(max_buffer_size);
  119|    120|    if (test_buffer == NULL) {
  ------------------
  |  Branch (119:9): [True: 0, False: 120]
  ------------------
  120|      0|        return 0;
  121|      0|    }
  122|    120|    if (size == 0) {
  ------------------
  |  Branch (122:9): [True: 0, False: 120]
  ------------------
  123|      0|        printf("\033[1;33m file_size of the seed file is 0, so exit.\033[0m \n");
  124|      0|        free(test_buffer);
  125|      0|        return 0;
  126|      0|    }
  127|    120|    if (size > max_buffer_size) {
  ------------------
  |  Branch (127:9): [True: 39, False: 81]
  ------------------
  128|     39|        size = max_buffer_size;
  129|     81|    } else {
  130|     81|        libspdm_copy_mem(test_buffer, max_buffer_size, data, size);
  131|     81|    }
  132|    120|    size = libspdm_alignment_size(size);
  133|       |    /* 2. Run test*/
  134|    120|    libspdm_run_test_harness(test_buffer, size);
  135|       |    /* 3. Clean up*/
  136|    120|    free(test_buffer);
  137|    120|    return 0;
  138|    120|}

libspdm_get_max_buffer_size:
   14|    240|{
   15|    240|    return LIBSPDM_MAX_SPDM_MSG_SIZE;
  ------------------
  |  |  101|    240|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   16|    240|}
libspdm_test_responder_key_pair_info:
   19|    120|{
   20|    120|    libspdm_test_context_t *spdm_test_context;
   21|    120|    libspdm_context_t *spdm_context;
   22|    120|    size_t response_size;
   23|    120|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
   24|       |
   25|    120|    spdm_test_context = *State;
   26|    120|    spdm_context = spdm_test_context->spdm_context;
   27|       |
   28|    120|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|    120|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
   29|    120|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    120|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   30|    120|    spdm_context->connection_info.connection_state =
   31|    120|        LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
   32|    120|    spdm_context->local_context.capability.flags |=
   33|    120|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP;
  ------------------
  |  |  298|    120|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP 0x10000000
  ------------------
   34|       |
   35|    120|    response_size = sizeof(response);
   36|    120|    libspdm_get_response_key_pair_info(spdm_context,
   37|    120|                                       spdm_test_context->test_buffer_size,
   38|    120|                                       spdm_test_context->test_buffer,
   39|    120|                                       &response_size, response);
   40|    120|}
libspdm_run_test_harness:
   48|    120|{
   49|    120|    void *State;
   50|    120|    spdm_message_header_t *spdm_request_header;
   51|    120|    libspdm_setup_test_context(&m_libspdm_responder_key_pair_info_test_context);
   52|       |
   53|    120|    spdm_request_header = (spdm_message_header_t*)test_buffer;
   54|       |
   55|    120|    if (spdm_request_header->request_response_code != SPDM_GET_KEY_PAIR_INFO) {
  ------------------
  |  |   99|    120|#define SPDM_GET_KEY_PAIR_INFO 0xFC
  ------------------
  |  Branch (55:9): [True: 119, False: 1]
  ------------------
   56|    119|        spdm_request_header->request_response_code = SPDM_GET_KEY_PAIR_INFO;
  ------------------
  |  |   99|    119|#define SPDM_GET_KEY_PAIR_INFO 0xFC
  ------------------
   57|    119|    }
   58|       |
   59|    120|    m_libspdm_responder_key_pair_info_test_context.test_buffer = test_buffer;
   60|    120|    m_libspdm_responder_key_pair_info_test_context.test_buffer_size =
   61|    120|        test_buffer_size;
   62|       |
   63|       |    /* Success Case*/
   64|    120|    libspdm_unit_test_group_setup(&State);
   65|    120|    libspdm_test_responder_key_pair_info(&State);
   66|    120|    libspdm_unit_test_group_teardown(&State);
   67|    120|}

