libspdm_get_scratch_buffer_secure_message_capacity:
   17|  2.70k|uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
   18|  2.70k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   19|  2.70k|           spdm_context->local_context.capability.transport_header_size +
   20|  2.70k|           spdm_context->local_context.capability.transport_tail_size;
   21|  2.70k|}
libspdm_get_scratch_buffer_large_message_offset:
   24|  1.08k|uint32_t libspdm_get_scratch_buffer_large_message_offset(libspdm_context_t *spdm_context) {
   25|  1.08k|    return libspdm_get_scratch_buffer_secure_message_capacity(spdm_context);
   26|  1.08k|}
libspdm_get_scratch_buffer_large_message_capacity:
   28|  1.62k|uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
   29|  1.62k|    return spdm_context->local_context.capability.max_spdm_msg_size;
   30|  1.62k|}
libspdm_get_scratch_buffer_sender_receiver_capacity:
   43|  1.62k|uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
   44|  1.62k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   45|  1.62k|           spdm_context->local_context.capability.transport_header_size +
   46|  1.62k|           spdm_context->local_context.capability.transport_tail_size;
   47|  1.62k|}
libspdm_get_scratch_buffer_large_sender_receiver_capacity:
   58|  1.62k|{
   59|  1.62k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   60|  1.62k|           spdm_context->local_context.capability.transport_header_size +
   61|  1.62k|           spdm_context->local_context.capability.transport_tail_size;
   62|  1.62k|}
libspdm_get_scratch_buffer_last_spdm_request_offset:
   66|    540|uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
   67|    540|    return 0 +
   68|    540|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   69|    540|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   70|    540|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   71|    540|#endif
   72|    540|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   73|    540|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   74|    540|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   75|    540|#endif
   76|    540|           0;
   77|    540|}
libspdm_get_scratch_buffer_last_spdm_request_capacity:
   79|  1.62k|uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
   80|  1.62k|    return spdm_context->local_context.capability.max_spdm_msg_size;
   81|  1.62k|}
libspdm_get_scratch_buffer_cache_spdm_request_offset:
   85|    540|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
   86|    540|    return 0 +
   87|    540|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   88|    540|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   89|    540|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   90|    540|#endif
   91|    540|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   92|    540|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   93|    540|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   94|    540|#endif
   95|    540|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
   96|    540|           0;
   97|    540|}
libspdm_get_scratch_buffer_cache_spdm_request_capacity:
   99|  1.08k|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
  100|  1.08k|    return spdm_context->local_context.capability.max_spdm_msg_size;
  101|  1.08k|}
libspdm_get_scratch_buffer_capacity:
  105|    540|uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
  106|    540|    return 0 +
  107|    540|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  108|    540|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
  109|    540|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
  110|    540|#endif
  111|    540|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
  112|    540|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  113|    540|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
  114|    540|#endif
  115|    540|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
  116|    540|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
  117|    540|           libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
  118|    540|#endif
  119|    540|           0;
  120|    540|}
libspdm_get_connection_version:
 2632|  1.26k|{
 2633|  1.26k|    return (uint8_t)(spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
  ------------------
  |  |  140|  1.26k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 2634|  1.26k|}
libspdm_is_capabilities_flag_supported:
 2651|    540|{
 2652|    540|    uint32_t negotiated_requester_capabilities_flag;
 2653|    540|    uint32_t negotiated_responder_capabilities_flag;
 2654|       |
 2655|    540|    if (is_requester) {
  ------------------
  |  Branch (2655:9): [True: 0, False: 540]
  ------------------
 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|    540|    } else {
 2659|    540|        negotiated_requester_capabilities_flag = spdm_context->connection_info.capability.flags;
 2660|    540|        negotiated_responder_capabilities_flag = spdm_context->local_context.capability.flags;
 2661|    540|    }
 2662|       |
 2663|    540|    if (((requester_capabilities_flag == 0) ||
  ------------------
  |  Branch (2663:10): [True: 0, False: 540]
  ------------------
 2664|    540|         ((negotiated_requester_capabilities_flag &
  ------------------
  |  Branch (2664:10): [True: 540, False: 0]
  ------------------
 2665|    540|           requester_capabilities_flag) != 0)) &&
 2666|    540|        ((responder_capabilities_flag == 0) ||
  ------------------
  |  Branch (2666:10): [True: 0, False: 540]
  ------------------
 2667|    540|         ((negotiated_responder_capabilities_flag &
  ------------------
  |  Branch (2667:10): [True: 540, False: 0]
  ------------------
 2668|    540|           responder_capabilities_flag) != 0))) {
 2669|    540|        return true;
 2670|    540|    } else {
 2671|      0|        return false;
 2672|      0|    }
 2673|    540|}
libspdm_register_device_io_func:
 2720|    540|{
 2721|    540|    libspdm_context_t *context;
 2722|       |
 2723|    540|    context = spdm_context;
 2724|    540|    context->send_message = send_message;
 2725|    540|    context->receive_message = receive_message;
 2726|    540|}
libspdm_register_device_buffer_func:
 2779|    540|{
 2780|    540|    libspdm_context_t *context;
 2781|       |
 2782|    540|    context = spdm_context;
 2783|    540|    context->sender_buffer_size = sender_buffer_size;
 2784|    540|    context->receiver_buffer_size = receiver_buffer_size;
 2785|    540|    context->acquire_sender_buffer = acquire_sender_buffer;
 2786|    540|    context->release_sender_buffer = release_sender_buffer;
 2787|    540|    context->acquire_receiver_buffer = acquire_receiver_buffer;
 2788|    540|    context->release_receiver_buffer = release_receiver_buffer;
 2789|       |
 2790|    540|    LIBSPDM_ASSERT (sender_buffer_size >=
 2791|    540|                    context->local_context.capability.transport_header_size +
 2792|    540|                    context->local_context.capability.transport_tail_size);
 2793|    540|    sender_buffer_size -= (context->local_context.capability.transport_header_size +
 2794|    540|                           context->local_context.capability.transport_tail_size);
 2795|    540|    LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2796|    540|    context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
 2797|       |
 2798|    540|    LIBSPDM_ASSERT(receiver_buffer_size >=
 2799|    540|                   context->local_context.capability.transport_header_size +
 2800|    540|                   context->local_context.capability.transport_tail_size);
 2801|    540|    receiver_buffer_size -= (context->local_context.capability.transport_header_size +
 2802|    540|                             context->local_context.capability.transport_tail_size);
 2803|    540|    LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2804|    540|    context->local_context.capability.data_transfer_size = receiver_buffer_size;
 2805|    540|}
libspdm_register_transport_layer_func:
 2823|    540|{
 2824|    540|    libspdm_context_t *context;
 2825|       |
 2826|    540|    context = spdm_context;
 2827|       |
 2828|       |    /* fix the data_transfer_size if it is set before */
 2829|    540|    if ((context->local_context.capability.data_transfer_size != 0) &&
  ------------------
  |  Branch (2829:9): [True: 0, False: 540]
  ------------------
 2830|    540|        (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|    540|    if ((context->local_context.capability.sender_data_transfer_size != 0) &&
  ------------------
  |  Branch (2836:9): [True: 0, False: 540]
  ------------------
 2837|    540|        (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|    540|    context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
 2845|    540|    context->local_context.capability.transport_header_size = transport_header_size;
 2846|    540|    context->local_context.capability.transport_tail_size = transport_tail_size;
 2847|    540|    context->transport_encode_message = transport_encode_message;
 2848|    540|    context->transport_decode_message = transport_decode_message;
 2849|    540|}
libspdm_get_sizeof_required_scratch_buffer:
 2886|    540|{
 2887|    540|    libspdm_context_t *context;
 2888|    540|    size_t scratch_buffer_size;
 2889|       |
 2890|    540|    context = spdm_context;
 2891|    540|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2892|       |
 2893|    540|    scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
 2894|    540|    return scratch_buffer_size;
 2895|    540|}
libspdm_set_scratch_buffer:
 2911|    540|{
 2912|    540|    libspdm_context_t *context;
 2913|       |
 2914|    540|    context = spdm_context;
 2915|    540|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2916|    540|    LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
 2917|    540|    context->scratch_buffer = scratch_buffer;
 2918|    540|    context->scratch_buffer_size = scratch_buffer_size;
 2919|    540|    context->last_spdm_request = (uint8_t *)scratch_buffer +
 2920|    540|                                 libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
 2921|    540|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2922|    540|    context->cache_spdm_request = (uint8_t *)scratch_buffer +
 2923|    540|                                  libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
 2924|    540|#endif
 2925|    540|}
libspdm_get_scratch_buffer:
 2939|    540|{
 2940|    540|    libspdm_context_t *context;
 2941|       |
 2942|    540|    context = spdm_context;
 2943|    540|    LIBSPDM_ASSERT (context->scratch_buffer != NULL);
 2944|    540|    LIBSPDM_ASSERT (context->scratch_buffer_size >=
 2945|    540|                    libspdm_get_scratch_buffer_capacity(spdm_context));
 2946|    540|    *scratch_buffer = context->scratch_buffer;
 2947|    540|    *scratch_buffer_size = context->scratch_buffer_size;
 2948|       |    /* need to remove last 2 sections, because they are for libspdm internal state track. */
 2949|    540|    *scratch_buffer_size -= libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context);
 2950|    540|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2951|    540|    *scratch_buffer_size -= libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context);
 2952|    540|#endif
 2953|    540|}
libspdm_init_context_with_secured_context:
 3240|    540|{
 3241|    540|    libspdm_context_t *context;
 3242|    540|    size_t index;
 3243|       |
 3244|    540|    LIBSPDM_ASSERT(spdm_context != NULL);
 3245|    540|    LIBSPDM_ASSERT(secured_contexts != NULL);
 3246|    540|    LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
 3247|       |
 3248|    540|    context = spdm_context;
 3249|    540|    libspdm_zero_mem(context, sizeof(libspdm_context_t));
 3250|    540|    context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
  ------------------
  |  |  527|    540|#define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
  ------------------
 3251|    540|    context->transcript.message_a.max_buffer_size =
 3252|    540|        sizeof(context->transcript.message_a.buffer);
 3253|    540|    context->transcript.message_d.max_buffer_size =
 3254|    540|        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|    540|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3272|    540|    context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   17|    540|#define SPDM_MAX_VERSION_COUNT 4
  ------------------
 3273|    540|    context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|    540|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
 3274|    540|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    540|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3275|    540|    context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    540|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 3276|    540|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    540|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3277|    540|    context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    540|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
 3278|    540|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    540|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3279|    540|    context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|    540|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
 3280|    540|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    540|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3281|    540|    context->local_context.secured_message_version.spdm_version_count =
 3282|    540|        SECURED_SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   55|    540|#define SECURED_SPDM_MAX_VERSION_COUNT 3
  ------------------
 3283|    540|    context->local_context.secured_message_version.spdm_version[0] =
 3284|    540|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|    540|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    540|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3285|    540|    context->local_context.secured_message_version.spdm_version[1] =
 3286|    540|        SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   58|    540|#define SECURED_SPDM_VERSION_11 0x11
  ------------------
                      SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    540|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3287|    540|    context->local_context.secured_message_version.spdm_version[2] =
 3288|    540|        SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   59|    540|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
                      SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    540|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3289|    540|    context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
  ------------------
  |  | 1514|    540|#define SPDM_ST1_VALUE_US 100000
  ------------------
 3290|       |
 3291|    540|    context->mut_auth_cert_chain_buffer_size = 0;
 3292|       |
 3293|    540|    context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
  ------------------
  |  |   39|    540|#define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
  ------------------
 3294|       |
 3295|    540|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    540|#define INVALID_SESSION_ID 0
  ------------------
 3296|    540|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    540|#define INVALID_SESSION_ID 0
  ------------------
 3297|    540|    context->last_spdm_request_session_id_valid = false;
 3298|    540|    context->last_spdm_request_size = 0;
 3299|       |
 3300|       |    /* To be updated in libspdm_register_device_buffer_func */
 3301|    540|    context->local_context.capability.data_transfer_size = 0;
 3302|    540|    context->local_context.capability.sender_data_transfer_size = 0;
 3303|    540|    context->local_context.capability.max_spdm_msg_size = 0;
 3304|       |
 3305|  2.70k|    for (index = 0; index < num_secured_contexts; index++) {
  ------------------
  |  Branch (3305:21): [True: 2.16k, False: 540]
  ------------------
 3306|  2.16k|        if (secured_contexts[index] == NULL) {
  ------------------
  |  Branch (3306:13): [True: 0, False: 2.16k]
  ------------------
 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|  2.16k|        context->session_info[index].secured_message_context = secured_contexts[index];
 3311|  2.16k|        libspdm_secured_message_init_context(
 3312|  2.16k|            context->session_info[index].secured_message_context);
 3313|  2.16k|    }
 3314|       |
 3315|    540|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    540|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    540|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3316|    540|}
libspdm_init_context:
 3331|    540|{
 3332|    540|    libspdm_context_t *context;
 3333|    540|    void *secured_context;
 3334|    540|    void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
 3335|    540|    size_t secured_context_size;
 3336|    540|    size_t index;
 3337|       |
 3338|    540|    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|    540|    context = spdm_context;
 3343|    540|    secured_context = (void *)((size_t)(context + 1));
 3344|    540|    secured_context_size = libspdm_secured_message_get_context_size();
 3345|       |
 3346|  2.70k|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|  2.70k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3346:21): [True: 2.16k, False: 540]
  ------------------
 3347|  2.16k|    {
 3348|  2.16k|        secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
 3349|  2.16k|    }
 3350|       |
 3351|    540|    return libspdm_init_context_with_secured_context(spdm_context,
 3352|    540|                                                     secured_contexts,
 3353|    540|                                                     LIBSPDM_MAX_SESSION_COUNT);
  ------------------
  |  |  198|    540|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3354|    540|}
libspdm_get_context_size:
 3467|    540|{
 3468|    540|    size_t size;
 3469|       |
 3470|    540|    size = sizeof(libspdm_context_t) +
 3471|    540|           libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
  ------------------
  |  |  198|    540|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3472|    540|    LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
 3473|    540|    return size;
 3474|    540|}

libspdm_get_response_chunk_get:
   17|    540|{
   18|    540|    libspdm_chunk_info_t* get_info;
   19|    540|    uint32_t min_data_transfer_size;
   20|    540|    uint64_t max_chunk_data_transfer_size;
   21|       |
   22|    540|    const spdm_chunk_get_request_t* spdm_request;
   23|    540|    spdm_chunk_response_response_t* spdm_response;
   24|       |
   25|    540|    uint8_t* spdm_chunk;
   26|       |
   27|    540|    spdm_request = (const spdm_chunk_get_request_t*) request;
   28|    540|    spdm_response = (spdm_chunk_response_response_t*) response;
   29|    540|    get_info = &spdm_context->chunk_context.get;
   30|       |
   31|    540|    if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_12) {
  ------------------
  |  |  112|    540|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
  |  Branch (31:9): [True: 0, False: 540]
  ------------------
   32|      0|        return libspdm_generate_error_response(spdm_context,
   33|      0|                                               SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
  ------------------
  |  |  859|      0|#define SPDM_ERROR_CODE_UNSUPPORTED_REQUEST 0x07
  ------------------
   34|      0|                                               SPDM_CHUNK_GET,
  ------------------
  |  |   91|      0|#define SPDM_CHUNK_GET 0x86
  ------------------
   35|      0|                                               response_size, response);
   36|      0|    }
   37|       |
   38|    540|    if (!libspdm_is_capabilities_flag_supported(
  ------------------
  |  Branch (38:9): [True: 0, False: 540]
  ------------------
   39|    540|            spdm_context, false, SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP,
  ------------------
  |  |  213|    540|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP 0x00020000
  ------------------
   40|    540|            SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP)) {
  ------------------
  |  |  274|    540|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP 0x00020000
  ------------------
   41|      0|        return libspdm_generate_error_response(
   42|      0|            spdm_context,
   43|      0|            SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   44|      0|            response_size, response);
   45|      0|    }
   46|       |
   47|       |    /*chunk mechanism can be used for normal or encap state*/
   48|    540|    if ((spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) &&
  ------------------
  |  Branch (48:9): [True: 0, False: 540]
  ------------------
   49|    540|        (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP)) {
  ------------------
  |  Branch (49:9): [True: 0, False: 0]
  ------------------
   50|      0|        return libspdm_responder_handle_response_state(
   51|      0|            spdm_context,
   52|      0|            spdm_request->header.request_response_code,
   53|      0|            response_size, response);
   54|      0|    }
   55|       |
   56|    540|    if (spdm_context->connection_info.connection_state <
  ------------------
  |  Branch (56:9): [True: 0, False: 540]
  ------------------
   57|    540|        LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES) {
   58|      0|        return libspdm_generate_error_response(
   59|      0|            spdm_context,
   60|      0|            SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   61|      0|            response_size, response);
   62|      0|    }
   63|       |
   64|    540|    if (request_size < sizeof(spdm_chunk_get_request_t)) {
  ------------------
  |  Branch (64:9): [True: 16, False: 524]
  ------------------
   65|     16|        return libspdm_generate_error_response(
   66|     16|            spdm_context,
   67|     16|            SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|     16|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
   68|     16|            response_size, response);
   69|     16|    }
   70|       |
   71|    524|    if (spdm_request->header.spdm_version < SPDM_MESSAGE_VERSION_12) {
  ------------------
  |  |  112|    524|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
  |  Branch (71:9): [True: 264, False: 260]
  ------------------
   72|    264|        return libspdm_generate_error_response(
   73|    264|            spdm_context,
   74|    264|            SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, SPDM_CHUNK_GET,
  ------------------
  |  |  859|    264|#define SPDM_ERROR_CODE_UNSUPPORTED_REQUEST 0x07
  ------------------
                          SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, SPDM_CHUNK_GET,
  ------------------
  |  |   91|    264|#define SPDM_CHUNK_GET 0x86
  ------------------
   75|    264|            response_size, response);
   76|    264|    }
   77|       |
   78|    260|    if (spdm_request->header.spdm_version
  ------------------
  |  Branch (78:9): [True: 64, False: 196]
  ------------------
   79|    260|        != libspdm_get_connection_version(spdm_context)) {
   80|     64|        return libspdm_generate_error_response(
   81|     64|            spdm_context,
   82|     64|            SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
  ------------------
  |  |  860|     64|#define SPDM_ERROR_CODE_VERSION_MISMATCH 0x41
  ------------------
   83|     64|            response_size, response);
   84|     64|    }
   85|       |
   86|    196|    if (get_info->chunk_in_use == false) {
  ------------------
  |  Branch (86:9): [True: 0, False: 196]
  ------------------
   87|      0|        return libspdm_generate_error_response(
   88|      0|            spdm_context,
   89|      0|            SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   90|      0|            response_size, response);
   91|      0|    }
   92|       |
   93|    196|    if (spdm_request->header.param2 != get_info->chunk_handle) {
  ------------------
  |  Branch (93:9): [True: 60, False: 136]
  ------------------
   94|     60|        return libspdm_generate_error_response(
   95|     60|            spdm_context,
   96|     60|            SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|     60|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
   97|     60|            response_size, response);
   98|     60|    }
   99|       |
  100|    136|    if (spdm_request->chunk_seq_no != get_info->chunk_seq_no) {
  ------------------
  |  Branch (100:9): [True: 62, False: 74]
  ------------------
  101|     62|        return libspdm_generate_error_response(
  102|     62|            spdm_context,
  103|     62|            SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|     62|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
  104|     62|            response_size, response);
  105|     62|    }
  106|       |
  107|     74|    min_data_transfer_size = LIBSPDM_MIN(
  ------------------
  |  |   72|     74|#define LIBSPDM_MIN(a, b) (((a) < (b)) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (72:28): [True: 74, False: 0]
  |  |  ------------------
  ------------------
  108|     74|        spdm_context->connection_info.capability.data_transfer_size,
  109|     74|        spdm_context->local_context.capability.sender_data_transfer_size);
  110|       |
  111|       |    /* Fail if exceed max chunks */
  112|     74|    max_chunk_data_transfer_size =
  113|     74|        ((size_t) min_data_transfer_size - sizeof(spdm_chunk_response_response_t)) * 65536 -
  114|     74|        sizeof(uint32_t);
  115|       |    /* max_spdm_msg_size already checked in caller */
  116|       |
  117|     74|    if (get_info->large_message_size > max_chunk_data_transfer_size) {
  ------------------
  |  Branch (117:9): [True: 0, False: 74]
  ------------------
  118|      0|        return libspdm_generate_error_response(
  119|      0|            spdm_context,
  120|      0|            SPDM_ERROR_CODE_RESPONSE_TOO_LARGE, 0,
  ------------------
  |  |  874|      0|#define SPDM_ERROR_CODE_RESPONSE_TOO_LARGE 0x0D
  ------------------
  121|      0|            response_size, response);
  122|      0|    }
  123|       |
  124|     74|    libspdm_zero_mem(response, *response_size);
  125|       |
  126|       |    /* Assert the data transfer size is smaller than the response size.
  127|       |     * Otherwise there is no reason to chunk this response. */
  128|     74|    LIBSPDM_ASSERT(min_data_transfer_size < *response_size);
  129|       |
  130|     74|    spdm_response->header.spdm_version = spdm_request->header.spdm_version;
  131|     74|    spdm_response->header.request_response_code = SPDM_CHUNK_RESPONSE;
  ------------------
  |  |   54|     74|#define SPDM_CHUNK_RESPONSE 0x06
  ------------------
  132|     74|    spdm_response->header.param1 = 0;
  133|     74|    spdm_response->header.param2 = get_info->chunk_handle;
  134|     74|    spdm_response->chunk_seq_no = get_info->chunk_seq_no;
  135|       |
  136|     74|    if (spdm_request->chunk_seq_no == 0) {
  ------------------
  |  Branch (136:9): [True: 12, False: 62]
  ------------------
  137|     12|        spdm_response->chunk_size =
  138|     12|            min_data_transfer_size
  139|     12|            - sizeof(spdm_chunk_response_response_t)
  140|     12|            - sizeof(uint32_t);
  141|       |
  142|       |        /* No reason to do chunking if message is smaller than largest chunk size. */
  143|     12|        LIBSPDM_ASSERT(spdm_response->chunk_size < get_info->large_message_size);
  144|       |
  145|     12|        spdm_chunk = (uint8_t*) (spdm_response + 1);
  146|       |
  147|       |        /* Set LargeMessageSize only in first chunk. */
  148|     12|        *((uint32_t*) (spdm_chunk)) = (uint32_t)get_info->large_message_size;
  149|     12|        spdm_chunk += sizeof(uint32_t);
  150|       |
  151|     12|        *response_size = sizeof(spdm_chunk_response_response_t)
  152|     12|                         + sizeof(uint32_t)
  153|     12|                         + spdm_response->chunk_size;
  154|     62|    } else {
  155|     62|        spdm_response->chunk_size =
  156|     62|            LIBSPDM_MIN(min_data_transfer_size
  ------------------
  |  |   72|     62|#define LIBSPDM_MIN(a, b) (((a) < (b)) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (72:28): [True: 31, False: 31]
  |  |  ------------------
  ------------------
  157|     62|                        - sizeof(spdm_chunk_response_response_t),
  158|     62|                        (uint32_t) (get_info->large_message_size
  159|     62|                                    - get_info->chunk_bytes_transferred));
  160|       |
  161|     62|        spdm_chunk = (uint8_t*) (spdm_response + 1);
  162|       |
  163|     62|        *response_size = sizeof(spdm_chunk_response_response_t)
  164|     62|                         + spdm_response->chunk_size;
  165|     62|    }
  166|       |
  167|     74|    libspdm_copy_mem(spdm_chunk, spdm_response->chunk_size,
  168|     74|                     (uint8_t*) get_info->large_message + get_info->chunk_bytes_transferred,
  169|     74|                     spdm_response->chunk_size);
  170|       |
  171|     74|    get_info->chunk_seq_no++;
  172|     74|    get_info->chunk_bytes_transferred += spdm_response->chunk_size;
  173|       |
  174|     74|    LIBSPDM_ASSERT(get_info->chunk_bytes_transferred <= get_info->large_message_size);
  175|     74|    if (get_info->chunk_bytes_transferred == get_info->large_message_size) {
  ------------------
  |  Branch (175:9): [True: 31, False: 43]
  ------------------
  176|     31|        get_info->chunk_in_use = false;
  177|     31|        get_info->chunk_handle++; /* implicit wrap - around to 0. */
  178|     31|        get_info->chunk_seq_no = 0;
  179|     31|        get_info->large_message = NULL;
  180|     31|        get_info->large_message_size = 0;
  181|     31|        get_info->chunk_bytes_transferred = 0;
  182|       |
  183|     31|        spdm_response->header.param1 |= SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK;
  ------------------
  |  | 1281|     31|#define SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK (1 << 0)
  ------------------
  184|     31|    }
  185|       |
  186|     74|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|     74|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|     74|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  187|     74|}

libspdm_generate_error_response:
   14|    466|{
   15|    466|    spdm_error_response_t *spdm_response;
   16|       |
   17|    466|    LIBSPDM_ASSERT(*response_size >= sizeof(spdm_error_response_t));
   18|    466|    *response_size = sizeof(spdm_error_response_t);
   19|    466|    spdm_response = response;
   20|       |
   21|    466|    spdm_response->header.spdm_version = libspdm_get_connection_version (spdm_context);
   22|    466|    if (spdm_response->header.spdm_version == 0) {
  ------------------
  |  Branch (22:9): [True: 0, False: 466]
  ------------------
   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|    466|    spdm_response->header.request_response_code = SPDM_ERROR;
  ------------------
  |  |   37|    466|#define SPDM_ERROR 0x7F
  ------------------
   27|    466|    spdm_response->header.param1 = error_code;
   28|    466|    spdm_response->header.param2 = error_data;
   29|       |
   30|    466|    if (spdm_response->header.spdm_version <= SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|    466|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  |  Branch (30:9): [True: 0, False: 466]
  ------------------
   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|    466|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    466|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    466|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   36|    466|}

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

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

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

libspdm_set_mem:
   10|  1.62k|{
   11|  1.62k|    volatile uint8_t *pointer;
   12|       |
   13|  1.62k|    pointer = (uint8_t *)buffer;
   14|  51.3k|    while (length-- != 0) {
  ------------------
  |  Branch (14:12): [True: 49.6k, False: 1.62k]
  ------------------
   15|  49.6k|        *(pointer++) = value;
   16|  49.6k|    }
   17|  1.62k|}

libspdm_zero_mem:
   17|  3.31k|{
   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|  3.31k|    volatile uint8_t *pointer;
   27|       |
   28|  3.31k|    pointer = (uint8_t *)buffer;
   29|  14.6M|    while (length-- != 0) {
  ------------------
  |  Branch (29:12): [True: 14.6M, False: 3.31k]
  ------------------
   30|  14.6M|        *(pointer++) = 0;
   31|  14.6M|    }
   32|       |
   33|       |#if defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
   34|       |    _ReadWriteBarrier();
   35|       |#elif defined(__GNUC__)
   36|       |    __asm__ __volatile__ ("" : : : "memory");
   37|  3.31k|#endif
   38|       |
   39|  3.31k|#endif
   40|  3.31k|}

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

libspdm_alignment_size:
   21|    135|{
   22|    135|    size_t alignment;
   23|    135|    size_t max_buffer_size;
   24|       |
   25|    135|    alignment = LIBSPDM_TEST_ALIGNMENT;
  ------------------
  |  |   15|    135|#define LIBSPDM_TEST_ALIGNMENT 4
  ------------------
   26|    135|    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|    135|    if ((size > max_buffer_size - alignment) && (size & (alignment - 1)) != 0) {
  ------------------
  |  Branch (29:9): [True: 43, False: 92]
  |  Branch (29:49): [True: 3, False: 40]
  ------------------
   30|      3|        size -= alignment;
   31|      3|    }
   32|       |
   33|    135|    if (((size) & (alignment - 1)) == 3) {
  ------------------
  |  Branch (33:9): [True: 17, False: 118]
  ------------------
   34|     17|        size += 1;
   35|     17|    }
   36|    135|    if (((size) & (alignment - 1)) == 2) {
  ------------------
  |  Branch (36:9): [True: 14, False: 121]
  ------------------
   37|     14|        size += 2;
   38|     14|    }
   39|    135|    if (((size) & (alignment - 1)) == 1) {
  ------------------
  |  Branch (39:9): [True: 52, False: 83]
  ------------------
   40|     52|        size += 3;
   41|     52|    }
   42|    135|    return size;
   43|    135|}
LLVMFuzzerTestOneInput:
  112|    135|{
  113|    135|    void *test_buffer;
  114|    135|    size_t max_buffer_size;
  115|       |
  116|       |    /* 1. Initialize test_buffer*/
  117|    135|    max_buffer_size = libspdm_get_max_buffer_size();
  118|    135|    test_buffer = allocate_zero_pool(max_buffer_size);
  119|    135|    if (test_buffer == NULL) {
  ------------------
  |  Branch (119:9): [True: 0, False: 135]
  ------------------
  120|      0|        return 0;
  121|      0|    }
  122|    135|    if (size == 0) {
  ------------------
  |  Branch (122:9): [True: 0, False: 135]
  ------------------
  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|    135|    if (size > max_buffer_size) {
  ------------------
  |  Branch (127:9): [True: 39, False: 96]
  ------------------
  128|     39|        size = max_buffer_size;
  129|     96|    } else {
  130|     96|        libspdm_copy_mem(test_buffer, max_buffer_size, data, size);
  131|     96|    }
  132|    135|    size = libspdm_alignment_size(size);
  133|       |    /* 2. Run test*/
  134|    135|    libspdm_run_test_harness(test_buffer, size);
  135|       |    /* 3. Clean up*/
  136|    135|    free(test_buffer);
  137|    135|    return 0;
  138|    135|}

libspdm_get_max_buffer_size:
   16|    270|{
   17|    270|    return LIBSPDM_MAX_SPDM_MSG_SIZE;
  ------------------
  |  |  101|    270|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   18|    270|}
libspdm_test_responder_chunk_get_case1:
   21|    135|{
   22|    135|    libspdm_test_context_t *spdm_test_context;
   23|    135|    libspdm_context_t *spdm_context;
   24|    135|    size_t response_size;
   25|    135|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
   26|    135|    spdm_chunk_get_request_t *spdm_request;
   27|       |
   28|    135|    void* scratch_buffer;
   29|    135|    size_t scratch_buffer_size;
   30|    135|    uint32_t data_transfer_size;
   31|    135|    uint32_t first_chunk_size;
   32|    135|    uint32_t second_chunk_size;
   33|    135|    uint32_t third_chunk_size;
   34|    135|    uint32_t total_chunk_size;
   35|       |
   36|    135|    spdm_test_context = *State;
   37|    135|    spdm_context = spdm_test_context->spdm_context;
   38|       |
   39|    135|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    135|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
   40|    135|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    135|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   41|       |
   42|    135|    spdm_context->connection_info.connection_state =
   43|    135|        LIBSPDM_CONNECTION_STATE_NEGOTIATED;
   44|    135|    spdm_context->connection_info.algorithm.base_hash_algo =
   45|    135|        m_libspdm_use_hash_algo;
   46|    135|    spdm_context->connection_info.capability.data_transfer_size =
   47|    135|        CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
  ------------------
  |  |   13|    135|#define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
  ------------------
   48|       |
   49|    135|    data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
  ------------------
  |  |   13|    135|#define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
  ------------------
   50|    135|    spdm_context->local_context.capability.data_transfer_size = data_transfer_size;
   51|    135|    spdm_context->local_context.capability.flags |=
   52|    135|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
  ------------------
  |  |  274|    135|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP 0x00020000
  ------------------
   53|    135|    spdm_context->connection_info.capability.flags |=
   54|    135|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
  ------------------
  |  |  213|    135|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP 0x00020000
  ------------------
   55|       |
   56|    135|    libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
   57|       |
   58|    135|    scratch_buffer = (uint8_t*)scratch_buffer +
   59|    135|                     libspdm_get_scratch_buffer_large_message_offset(spdm_context);
   60|    135|    scratch_buffer_size = scratch_buffer_size -
   61|    135|                          libspdm_get_scratch_buffer_large_message_offset(spdm_context);
   62|    135|    libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
   63|       |
   64|    135|    first_chunk_size = data_transfer_size -
   65|    135|                       (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t));
   66|    135|    second_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
   67|    135|    third_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
   68|    135|    total_chunk_size = first_chunk_size + second_chunk_size + third_chunk_size;
   69|       |
   70|    135|    libspdm_set_mem(scratch_buffer, first_chunk_size, 1);
   71|    135|    libspdm_set_mem((uint8_t*)scratch_buffer + first_chunk_size, second_chunk_size, 2);
   72|    135|    libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size + second_chunk_size,
   73|    135|                    third_chunk_size, 3);
   74|       |
   75|    135|    spdm_request = (spdm_chunk_get_request_t *)spdm_test_context->test_buffer;
   76|       |
   77|    135|    spdm_context->chunk_context.get.chunk_in_use = true;
   78|    135|    spdm_context->chunk_context.get.chunk_handle = 0;
   79|    135|    spdm_context->chunk_context.get.chunk_seq_no = spdm_request->chunk_seq_no;
   80|    135|    spdm_context->chunk_context.get.large_message = scratch_buffer;
   81|    135|    spdm_context->chunk_context.get.large_message_size = total_chunk_size;
   82|    135|    spdm_context->chunk_context.get.chunk_bytes_transferred = 0;
   83|       |
   84|    135|    response_size = sizeof(response);
   85|    135|    libspdm_get_response_chunk_get(spdm_context,
   86|    135|                                   spdm_test_context->test_buffer_size,
   87|    135|                                   spdm_test_context->test_buffer,
   88|    135|                                   &response_size, response);
   89|    135|}
libspdm_test_responder_chunk_get_case2:
   92|    135|{
   93|    135|    libspdm_test_context_t *spdm_test_context;
   94|    135|    libspdm_context_t *spdm_context;
   95|    135|    size_t response_size;
   96|    135|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
   97|       |
   98|    135|    void* scratch_buffer;
   99|    135|    size_t scratch_buffer_size;
  100|    135|    uint32_t data_transfer_size;
  101|    135|    uint32_t first_chunk_size;
  102|    135|    uint32_t second_chunk_size;
  103|    135|    uint32_t third_chunk_size;
  104|    135|    uint32_t total_chunk_size;
  105|       |
  106|    135|    spdm_test_context = *State;
  107|    135|    spdm_context = spdm_test_context->spdm_context;
  108|       |
  109|    135|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    135|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
  110|    135|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    135|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  111|       |
  112|    135|    spdm_context->connection_info.connection_state =
  113|    135|        LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  114|    135|    spdm_context->connection_info.algorithm.base_hash_algo =
  115|    135|        m_libspdm_use_hash_algo;
  116|    135|    spdm_context->connection_info.capability.data_transfer_size =
  117|    135|        CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
  ------------------
  |  |   13|    135|#define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
  ------------------
  118|       |
  119|    135|    data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
  ------------------
  |  |   13|    135|#define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
  ------------------
  120|    135|    spdm_context->local_context.capability.data_transfer_size = data_transfer_size;
  121|    135|    spdm_context->local_context.capability.flags |=
  122|    135|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
  ------------------
  |  |  274|    135|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP 0x00020000
  ------------------
  123|    135|    spdm_context->connection_info.capability.flags |=
  124|    135|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
  ------------------
  |  |  213|    135|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP 0x00020000
  ------------------
  125|       |
  126|    135|    libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
  127|       |
  128|    135|    scratch_buffer = (uint8_t*)scratch_buffer +
  129|    135|                     libspdm_get_scratch_buffer_large_message_offset(spdm_context);
  130|    135|    scratch_buffer_size = scratch_buffer_size -
  131|    135|                          libspdm_get_scratch_buffer_large_message_offset(spdm_context);
  132|    135|    libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
  133|       |
  134|    135|    first_chunk_size = data_transfer_size -
  135|    135|                       (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t));
  136|    135|    second_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
  137|    135|    third_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
  138|    135|    total_chunk_size = first_chunk_size + second_chunk_size + third_chunk_size;
  139|       |
  140|    135|    libspdm_set_mem(scratch_buffer, first_chunk_size, 1);
  141|    135|    libspdm_set_mem((uint8_t*)scratch_buffer + first_chunk_size, second_chunk_size, 2);
  142|    135|    libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size + second_chunk_size,
  143|    135|                    third_chunk_size, 3);
  144|       |
  145|    135|    spdm_context->chunk_context.get.chunk_in_use = true;
  146|    135|    spdm_context->chunk_context.get.chunk_handle = 0;
  147|    135|    spdm_context->chunk_context.get.chunk_seq_no = 0;
  148|    135|    spdm_context->chunk_context.get.large_message = scratch_buffer;
  149|    135|    spdm_context->chunk_context.get.large_message_size = total_chunk_size;
  150|    135|    spdm_context->chunk_context.get.chunk_bytes_transferred = 0;
  151|       |
  152|    135|    response_size = sizeof(response);
  153|    135|    libspdm_get_response_chunk_get(spdm_context,
  154|    135|                                   spdm_test_context->test_buffer_size,
  155|    135|                                   spdm_test_context->test_buffer,
  156|    135|                                   &response_size, response);
  157|    135|}
libspdm_test_responder_chunk_get_case3:
  160|    135|{
  161|    135|    libspdm_test_context_t *spdm_test_context;
  162|    135|    libspdm_context_t *spdm_context;
  163|    135|    size_t response_size;
  164|    135|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
  165|       |
  166|    135|    void* scratch_buffer;
  167|    135|    size_t scratch_buffer_size;
  168|    135|    uint32_t data_transfer_size;
  169|    135|    uint32_t first_chunk_size;
  170|    135|    uint32_t second_chunk_size;
  171|    135|    uint32_t third_chunk_size;
  172|    135|    uint32_t total_chunk_size;
  173|       |
  174|    135|    spdm_test_context = *State;
  175|    135|    spdm_context = spdm_test_context->spdm_context;
  176|       |
  177|    135|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    135|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
  178|    135|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    135|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  179|       |
  180|    135|    spdm_context->connection_info.connection_state =
  181|    135|        LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  182|    135|    spdm_context->connection_info.algorithm.base_hash_algo =
  183|    135|        m_libspdm_use_hash_algo;
  184|    135|    spdm_context->connection_info.capability.data_transfer_size =
  185|    135|        CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
  ------------------
  |  |   13|    135|#define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
  ------------------
  186|       |
  187|    135|    data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
  ------------------
  |  |   13|    135|#define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
  ------------------
  188|    135|    spdm_context->local_context.capability.data_transfer_size = data_transfer_size;
  189|    135|    spdm_context->local_context.capability.flags |=
  190|    135|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
  ------------------
  |  |  274|    135|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP 0x00020000
  ------------------
  191|    135|    spdm_context->connection_info.capability.flags |=
  192|    135|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
  ------------------
  |  |  213|    135|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP 0x00020000
  ------------------
  193|       |
  194|    135|    libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
  195|       |
  196|    135|    scratch_buffer = (uint8_t*)scratch_buffer +
  197|    135|                     libspdm_get_scratch_buffer_large_message_offset(spdm_context);
  198|    135|    scratch_buffer_size = scratch_buffer_size -
  199|    135|                          libspdm_get_scratch_buffer_large_message_offset(spdm_context);
  200|    135|    libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
  201|       |
  202|    135|    first_chunk_size = data_transfer_size -
  203|    135|                       (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t));
  204|    135|    second_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
  205|    135|    third_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
  206|    135|    total_chunk_size = first_chunk_size + second_chunk_size + third_chunk_size;
  207|       |
  208|    135|    libspdm_set_mem(scratch_buffer, first_chunk_size, 1);
  209|    135|    libspdm_set_mem((uint8_t*)scratch_buffer + first_chunk_size, second_chunk_size, 2);
  210|    135|    libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size + second_chunk_size,
  211|    135|                    third_chunk_size, 3);
  212|       |
  213|    135|    spdm_context->chunk_context.get.chunk_in_use = true;
  214|    135|    spdm_context->chunk_context.get.chunk_handle = 0;
  215|    135|    spdm_context->chunk_context.get.chunk_seq_no = 0;
  216|    135|    spdm_context->chunk_context.get.large_message = scratch_buffer;
  217|    135|    spdm_context->chunk_context.get.large_message_size = total_chunk_size;
  218|    135|    spdm_context->chunk_context.get.chunk_bytes_transferred = 0;
  219|       |
  220|    135|    response_size = sizeof(response);
  221|    135|    libspdm_get_response_chunk_get(spdm_context,
  222|    135|                                   spdm_test_context->test_buffer_size,
  223|    135|                                   spdm_test_context->test_buffer,
  224|    135|                                   &response_size, response);
  225|    135|}
libspdm_test_responder_chunk_get_case4:
  228|    135|{
  229|    135|    libspdm_test_context_t *spdm_test_context;
  230|    135|    libspdm_context_t *spdm_context;
  231|    135|    size_t response_size;
  232|    135|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
  233|    135|    spdm_chunk_get_request_t *spdm_request;
  234|       |
  235|    135|    void* scratch_buffer;
  236|    135|    size_t scratch_buffer_size;
  237|    135|    uint32_t data_transfer_size;
  238|    135|    uint32_t first_chunk_size;
  239|    135|    uint32_t second_chunk_size;
  240|    135|    uint32_t third_chunk_size;
  241|    135|    uint32_t total_chunk_size;
  242|       |
  243|    135|    spdm_test_context = *State;
  244|    135|    spdm_context = spdm_test_context->spdm_context;
  245|       |
  246|    135|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    135|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
  247|    135|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    135|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  248|       |
  249|    135|    spdm_context->connection_info.connection_state =
  250|    135|        LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  251|    135|    spdm_context->connection_info.algorithm.base_hash_algo =
  252|    135|        m_libspdm_use_hash_algo;
  253|    135|    spdm_context->connection_info.capability.data_transfer_size =
  254|    135|        CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
  ------------------
  |  |   13|    135|#define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
  ------------------
  255|       |
  256|    135|    data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE;
  ------------------
  |  |   13|    135|#define CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE (44)
  ------------------
  257|    135|    spdm_context->local_context.capability.data_transfer_size = data_transfer_size;
  258|    135|    spdm_context->local_context.capability.flags |=
  259|    135|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP;
  ------------------
  |  |  274|    135|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP 0x00020000
  ------------------
  260|    135|    spdm_context->connection_info.capability.flags |=
  261|    135|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
  ------------------
  |  |  213|    135|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP 0x00020000
  ------------------
  262|       |
  263|    135|    libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size);
  264|       |
  265|    135|    scratch_buffer = (uint8_t*)scratch_buffer +
  266|    135|                     libspdm_get_scratch_buffer_large_message_offset(spdm_context);
  267|    135|    scratch_buffer_size = scratch_buffer_size -
  268|    135|                          libspdm_get_scratch_buffer_large_message_offset(spdm_context);
  269|    135|    libspdm_zero_mem(scratch_buffer, scratch_buffer_size);
  270|       |
  271|    135|    first_chunk_size = data_transfer_size -
  272|    135|                       (sizeof(spdm_chunk_response_response_t) + sizeof(uint32_t));
  273|    135|    second_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
  274|    135|    third_chunk_size = data_transfer_size - sizeof(spdm_chunk_response_response_t);
  275|    135|    total_chunk_size = first_chunk_size + second_chunk_size + third_chunk_size;
  276|       |
  277|    135|    libspdm_set_mem(scratch_buffer, first_chunk_size, 1);
  278|    135|    libspdm_set_mem((uint8_t*)scratch_buffer + first_chunk_size, second_chunk_size, 2);
  279|    135|    libspdm_set_mem((uint8_t*) scratch_buffer + first_chunk_size + second_chunk_size,
  280|    135|                    third_chunk_size, 3);
  281|       |
  282|    135|    spdm_request = (spdm_chunk_get_request_t *)spdm_test_context->test_buffer;
  283|       |
  284|    135|    spdm_context->chunk_context.get.chunk_in_use = true;
  285|    135|    spdm_context->chunk_context.get.chunk_handle = 0;
  286|    135|    spdm_context->chunk_context.get.chunk_seq_no = spdm_request->chunk_seq_no;
  287|    135|    spdm_context->chunk_context.get.large_message = scratch_buffer;
  288|    135|    spdm_context->chunk_context.get.large_message_size = total_chunk_size;
  289|    135|    spdm_context->chunk_context.get.chunk_bytes_transferred = first_chunk_size + second_chunk_size;
  290|       |
  291|    135|    response_size = sizeof(response);
  292|    135|    libspdm_get_response_chunk_get(spdm_context,
  293|    135|                                   spdm_test_context->test_buffer_size,
  294|    135|                                   spdm_test_context->test_buffer,
  295|    135|                                   &response_size, response);
  296|    135|}
libspdm_run_test_harness:
  304|    135|{
  305|    135|    void *State;
  306|       |
  307|    135|    libspdm_setup_test_context(&m_libspdm_responder_chunk_get_test_context);
  308|       |
  309|    135|    m_libspdm_responder_chunk_get_test_context.test_buffer = test_buffer;
  310|    135|    m_libspdm_responder_chunk_get_test_context.test_buffer_size =
  311|    135|        test_buffer_size;
  312|       |
  313|       |    /* Successful request of chunk*/
  314|    135|    libspdm_unit_test_group_setup(&State);
  315|    135|    libspdm_test_responder_chunk_get_case1(&State);
  316|    135|    libspdm_unit_test_group_teardown(&State);
  317|       |
  318|       |    /*Successful request of first chunk*/
  319|    135|    libspdm_unit_test_group_setup(&State);
  320|    135|    libspdm_test_responder_chunk_get_case2(&State);
  321|    135|    libspdm_unit_test_group_teardown(&State);
  322|       |
  323|       |    /* When request.chunk_seq_no is 0xff. Successful request of chunk */
  324|    135|    libspdm_unit_test_group_setup(&State);
  325|    135|    libspdm_test_responder_chunk_get_case3(&State);
  326|    135|    libspdm_unit_test_group_teardown(&State);
  327|       |
  328|       |    /* Successful request of  chunk, where size is exactly max chunk size */
  329|    135|    libspdm_unit_test_group_setup(&State);
  330|    135|    libspdm_test_responder_chunk_get_case4(&State);
  331|    135|    libspdm_unit_test_group_teardown(&State);
  332|    135|}

