libspdm_get_scratch_buffer_secure_message_capacity:
   17|  2.05k|uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
   18|  2.05k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   19|  2.05k|           spdm_context->local_context.capability.transport_header_size +
   20|  2.05k|           spdm_context->local_context.capability.transport_tail_size;
   21|  2.05k|}
libspdm_get_scratch_buffer_large_message_capacity:
   28|  2.05k|uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
   29|  2.05k|    return spdm_context->local_context.capability.max_spdm_msg_size;
   30|  2.05k|}
libspdm_get_scratch_buffer_sender_receiver_capacity:
   43|  2.05k|uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
   44|  2.05k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   45|  2.05k|           spdm_context->local_context.capability.transport_header_size +
   46|  2.05k|           spdm_context->local_context.capability.transport_tail_size;
   47|  2.05k|}
libspdm_get_scratch_buffer_large_sender_receiver_capacity:
   58|  2.05k|{
   59|  2.05k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   60|  2.05k|           spdm_context->local_context.capability.transport_header_size +
   61|  2.05k|           spdm_context->local_context.capability.transport_tail_size;
   62|  2.05k|}
libspdm_get_scratch_buffer_last_spdm_request_offset:
   66|    686|uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
   67|    686|    return 0 +
   68|    686|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   69|    686|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   70|    686|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   71|    686|#endif
   72|    686|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   73|    686|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   74|    686|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   75|    686|#endif
   76|    686|           0;
   77|    686|}
libspdm_get_scratch_buffer_last_spdm_request_capacity:
   79|  1.37k|uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
   80|  1.37k|    return spdm_context->local_context.capability.max_spdm_msg_size;
   81|  1.37k|}
libspdm_get_scratch_buffer_cache_spdm_request_offset:
   85|    686|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
   86|    686|    return 0 +
   87|    686|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   88|    686|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   89|    686|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   90|    686|#endif
   91|    686|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   92|    686|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   93|    686|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   94|    686|#endif
   95|    686|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
   96|    686|           0;
   97|    686|}
libspdm_get_scratch_buffer_cache_spdm_request_capacity:
   99|    686|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
  100|    686|    return spdm_context->local_context.capability.max_spdm_msg_size;
  101|    686|}
libspdm_get_scratch_buffer_capacity:
  105|    686|uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
  106|    686|    return 0 +
  107|    686|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  108|    686|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
  109|    686|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
  110|    686|#endif
  111|    686|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
  112|    686|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  113|    686|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
  114|    686|#endif
  115|    686|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
  116|    686|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
  117|    686|           libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
  118|    686|#endif
  119|    686|           0;
  120|    686|}
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_register_device_io_func:
 2720|    686|{
 2721|    686|    libspdm_context_t *context;
 2722|       |
 2723|    686|    context = spdm_context;
 2724|    686|    context->send_message = send_message;
 2725|    686|    context->receive_message = receive_message;
 2726|    686|}
libspdm_register_device_buffer_func:
 2779|    686|{
 2780|    686|    libspdm_context_t *context;
 2781|       |
 2782|    686|    context = spdm_context;
 2783|    686|    context->sender_buffer_size = sender_buffer_size;
 2784|    686|    context->receiver_buffer_size = receiver_buffer_size;
 2785|    686|    context->acquire_sender_buffer = acquire_sender_buffer;
 2786|    686|    context->release_sender_buffer = release_sender_buffer;
 2787|    686|    context->acquire_receiver_buffer = acquire_receiver_buffer;
 2788|    686|    context->release_receiver_buffer = release_receiver_buffer;
 2789|       |
 2790|    686|    LIBSPDM_ASSERT (sender_buffer_size >=
 2791|    686|                    context->local_context.capability.transport_header_size +
 2792|    686|                    context->local_context.capability.transport_tail_size);
 2793|    686|    sender_buffer_size -= (context->local_context.capability.transport_header_size +
 2794|    686|                           context->local_context.capability.transport_tail_size);
 2795|    686|    LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2796|    686|    context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
 2797|       |
 2798|    686|    LIBSPDM_ASSERT(receiver_buffer_size >=
 2799|    686|                   context->local_context.capability.transport_header_size +
 2800|    686|                   context->local_context.capability.transport_tail_size);
 2801|    686|    receiver_buffer_size -= (context->local_context.capability.transport_header_size +
 2802|    686|                             context->local_context.capability.transport_tail_size);
 2803|    686|    LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2804|    686|    context->local_context.capability.data_transfer_size = receiver_buffer_size;
 2805|    686|}
libspdm_register_transport_layer_func:
 2823|    686|{
 2824|    686|    libspdm_context_t *context;
 2825|       |
 2826|    686|    context = spdm_context;
 2827|       |
 2828|       |    /* fix the data_transfer_size if it is set before */
 2829|    686|    if ((context->local_context.capability.data_transfer_size != 0) &&
  ------------------
  |  Branch (2829:9): [True: 0, False: 686]
  ------------------
 2830|    686|        (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|    686|    if ((context->local_context.capability.sender_data_transfer_size != 0) &&
  ------------------
  |  Branch (2836:9): [True: 0, False: 686]
  ------------------
 2837|    686|        (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|    686|    context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
 2845|    686|    context->local_context.capability.transport_header_size = transport_header_size;
 2846|    686|    context->local_context.capability.transport_tail_size = transport_tail_size;
 2847|    686|    context->transport_encode_message = transport_encode_message;
 2848|    686|    context->transport_decode_message = transport_decode_message;
 2849|    686|}
libspdm_get_sizeof_required_scratch_buffer:
 2886|    686|{
 2887|    686|    libspdm_context_t *context;
 2888|    686|    size_t scratch_buffer_size;
 2889|       |
 2890|    686|    context = spdm_context;
 2891|    686|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2892|       |
 2893|    686|    scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
 2894|    686|    return scratch_buffer_size;
 2895|    686|}
libspdm_set_scratch_buffer:
 2911|    686|{
 2912|    686|    libspdm_context_t *context;
 2913|       |
 2914|    686|    context = spdm_context;
 2915|    686|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2916|    686|    LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
 2917|    686|    context->scratch_buffer = scratch_buffer;
 2918|    686|    context->scratch_buffer_size = scratch_buffer_size;
 2919|    686|    context->last_spdm_request = (uint8_t *)scratch_buffer +
 2920|    686|                                 libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
 2921|    686|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2922|    686|    context->cache_spdm_request = (uint8_t *)scratch_buffer +
 2923|    686|                                  libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
 2924|    686|#endif
 2925|    686|}
libspdm_init_context_with_secured_context:
 3240|    686|{
 3241|    686|    libspdm_context_t *context;
 3242|    686|    size_t index;
 3243|       |
 3244|    686|    LIBSPDM_ASSERT(spdm_context != NULL);
 3245|    686|    LIBSPDM_ASSERT(secured_contexts != NULL);
 3246|    686|    LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
 3247|       |
 3248|    686|    context = spdm_context;
 3249|    686|    libspdm_zero_mem(context, sizeof(libspdm_context_t));
 3250|    686|    context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
  ------------------
  |  |  527|    686|#define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
  ------------------
 3251|    686|    context->transcript.message_a.max_buffer_size =
 3252|    686|        sizeof(context->transcript.message_a.buffer);
 3253|    686|    context->transcript.message_d.max_buffer_size =
 3254|    686|        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|    686|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3272|    686|    context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   17|    686|#define SPDM_MAX_VERSION_COUNT 4
  ------------------
 3273|    686|    context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|    686|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
 3274|    686|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    686|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3275|    686|    context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    686|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 3276|    686|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    686|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3277|    686|    context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    686|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
 3278|    686|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    686|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3279|    686|    context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|    686|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
 3280|    686|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    686|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3281|    686|    context->local_context.secured_message_version.spdm_version_count =
 3282|    686|        SECURED_SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   55|    686|#define SECURED_SPDM_MAX_VERSION_COUNT 3
  ------------------
 3283|    686|    context->local_context.secured_message_version.spdm_version[0] =
 3284|    686|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|    686|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    686|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3285|    686|    context->local_context.secured_message_version.spdm_version[1] =
 3286|    686|        SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   58|    686|#define SECURED_SPDM_VERSION_11 0x11
  ------------------
                      SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    686|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3287|    686|    context->local_context.secured_message_version.spdm_version[2] =
 3288|    686|        SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   59|    686|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
                      SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    686|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3289|    686|    context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
  ------------------
  |  | 1514|    686|#define SPDM_ST1_VALUE_US 100000
  ------------------
 3290|       |
 3291|    686|    context->mut_auth_cert_chain_buffer_size = 0;
 3292|       |
 3293|    686|    context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
  ------------------
  |  |   39|    686|#define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
  ------------------
 3294|       |
 3295|    686|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    686|#define INVALID_SESSION_ID 0
  ------------------
 3296|    686|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    686|#define INVALID_SESSION_ID 0
  ------------------
 3297|    686|    context->last_spdm_request_session_id_valid = false;
 3298|    686|    context->last_spdm_request_size = 0;
 3299|       |
 3300|       |    /* To be updated in libspdm_register_device_buffer_func */
 3301|    686|    context->local_context.capability.data_transfer_size = 0;
 3302|    686|    context->local_context.capability.sender_data_transfer_size = 0;
 3303|    686|    context->local_context.capability.max_spdm_msg_size = 0;
 3304|       |
 3305|  3.43k|    for (index = 0; index < num_secured_contexts; index++) {
  ------------------
  |  Branch (3305:21): [True: 2.74k, False: 686]
  ------------------
 3306|  2.74k|        if (secured_contexts[index] == NULL) {
  ------------------
  |  Branch (3306:13): [True: 0, False: 2.74k]
  ------------------
 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.74k|        context->session_info[index].secured_message_context = secured_contexts[index];
 3311|  2.74k|        libspdm_secured_message_init_context(
 3312|  2.74k|            context->session_info[index].secured_message_context);
 3313|  2.74k|    }
 3314|       |
 3315|    686|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    686|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    686|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3316|    686|}
libspdm_init_context:
 3331|    686|{
 3332|    686|    libspdm_context_t *context;
 3333|    686|    void *secured_context;
 3334|    686|    void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
 3335|    686|    size_t secured_context_size;
 3336|    686|    size_t index;
 3337|       |
 3338|    686|    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|    686|    context = spdm_context;
 3343|    686|    secured_context = (void *)((size_t)(context + 1));
 3344|    686|    secured_context_size = libspdm_secured_message_get_context_size();
 3345|       |
 3346|  3.43k|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|  3.43k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3346:21): [True: 2.74k, False: 686]
  ------------------
 3347|  2.74k|    {
 3348|  2.74k|        secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
 3349|  2.74k|    }
 3350|       |
 3351|    686|    return libspdm_init_context_with_secured_context(spdm_context,
 3352|    686|                                                     secured_contexts,
 3353|    686|                                                     LIBSPDM_MAX_SESSION_COUNT);
  ------------------
  |  |  198|    686|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3354|    686|}
libspdm_get_context_size:
 3467|    686|{
 3468|    686|    size_t size;
 3469|       |
 3470|    686|    size = sizeof(libspdm_context_t) +
 3471|    686|           libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
  ------------------
  |  |  198|    686|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3472|    686|    LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
 3473|    686|    return size;
 3474|    686|}
libspdm_get_version_from_version_number:
 3500|    272|{
 3501|    272|    return (uint8_t)(ver >> SPDM_VERSION_NUMBER_SHIFT_BIT);
  ------------------
  |  |  140|    272|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3502|    272|}
libspdm_version_number_sort:
 3512|    116|{
 3513|    116|    size_t index;
 3514|    116|    size_t index_sort;
 3515|    116|    size_t index_max;
 3516|    116|    spdm_version_number_t version;
 3517|       |
 3518|       |    /* Select sort */
 3519|    116|    if (ver_num > 1) {
  ------------------
  |  Branch (3519:9): [True: 52, False: 64]
  ------------------
 3520|    190|        for (index_sort = 0; index_sort < ver_num; index_sort++) {
  ------------------
  |  Branch (3520:30): [True: 138, False: 52]
  ------------------
 3521|    138|            index_max = index_sort;
 3522|    280|            for (index = index_sort + 1; index < ver_num; index++) {
  ------------------
  |  Branch (3522:42): [True: 142, False: 138]
  ------------------
 3523|       |                /* if ver_ser[index] higher than ver_set[index_max] */
 3524|    142|                if (ver_set[index] > ver_set[index_max]) {
  ------------------
  |  Branch (3524:21): [True: 54, False: 88]
  ------------------
 3525|     54|                    index_max = index;
 3526|     54|                }
 3527|    142|            }
 3528|       |            /* swap ver_ser[index_min] and ver_set[index_sort] */
 3529|    138|            version = ver_set[index_sort];
 3530|    138|            ver_set[index_sort] = ver_set[index_max];
 3531|    138|            ver_set[index_max] = version;
 3532|    138|        }
 3533|     52|    }
 3534|    116|}
libspdm_negotiate_connection_version:
 3554|     67|{
 3555|     67|    spdm_version_number_t req_version_list[LIBSPDM_MAX_VERSION_COUNT];
 3556|     67|    spdm_version_number_t res_version_list[LIBSPDM_MAX_VERSION_COUNT];
 3557|     67|    size_t req_index;
 3558|     67|    size_t res_index;
 3559|       |
 3560|     67|    if (req_ver_num > LIBSPDM_MAX_VERSION_COUNT || res_ver_num > LIBSPDM_MAX_VERSION_COUNT) {
  ------------------
  |  |  168|    134|#define LIBSPDM_MAX_VERSION_COUNT 5
  ------------------
                  if (req_ver_num > LIBSPDM_MAX_VERSION_COUNT || res_ver_num > LIBSPDM_MAX_VERSION_COUNT) {
  ------------------
  |  |  168|     67|#define LIBSPDM_MAX_VERSION_COUNT 5
  ------------------
  |  Branch (3560:9): [True: 0, False: 67]
  |  Branch (3560:52): [True: 9, False: 58]
  ------------------
 3561|      9|        return false;
 3562|      9|    }
 3563|       |
 3564|     58|    if (req_ver_set == NULL || req_ver_num == 0 || res_ver_set == NULL || res_ver_num == 0) {
  ------------------
  |  Branch (3564:9): [True: 0, False: 58]
  |  Branch (3564:32): [True: 0, False: 58]
  |  Branch (3564:52): [True: 0, False: 58]
  |  Branch (3564:75): [True: 0, False: 58]
  ------------------
 3565|      0|        return false;
 3566|      0|    }
 3567|       |
 3568|     58|    libspdm_zero_mem(req_version_list, sizeof(spdm_version_number_t) * LIBSPDM_MAX_VERSION_COUNT);
  ------------------
  |  |  168|     58|#define LIBSPDM_MAX_VERSION_COUNT 5
  ------------------
 3569|     58|    libspdm_zero_mem(res_version_list, sizeof(spdm_version_number_t) * LIBSPDM_MAX_VERSION_COUNT);
  ------------------
  |  |  168|     58|#define LIBSPDM_MAX_VERSION_COUNT 5
  ------------------
 3570|       |
 3571|     58|    libspdm_copy_mem(req_version_list, sizeof(spdm_version_number_t) * LIBSPDM_MAX_VERSION_COUNT,
  ------------------
  |  |  168|     58|#define LIBSPDM_MAX_VERSION_COUNT 5
  ------------------
 3572|     58|                     req_ver_set, sizeof(spdm_version_number_t) * req_ver_num);
 3573|     58|    libspdm_copy_mem(res_version_list, sizeof(spdm_version_number_t) * LIBSPDM_MAX_VERSION_COUNT,
  ------------------
  |  |  168|     58|#define LIBSPDM_MAX_VERSION_COUNT 5
  ------------------
 3574|     58|                     res_ver_set, sizeof(spdm_version_number_t) * res_ver_num);
 3575|       |
 3576|       |    /* Sort SPDMversion in descending order. */
 3577|     58|    libspdm_version_number_sort(req_version_list, req_ver_num);
 3578|     58|    libspdm_version_number_sort(res_version_list, res_ver_num);
 3579|       |
 3580|       |    /**
 3581|       |     * Find highest same version and make req_index point to it.
 3582|       |     * If not found, return false.
 3583|       |     **/
 3584|    186|    for (res_index = 0; res_index < res_ver_num; res_index++) {
  ------------------
  |  Branch (3584:25): [True: 136, False: 50]
  ------------------
 3585|    264|        for (req_index = 0; req_index < req_ver_num; req_index++) {
  ------------------
  |  Branch (3585:29): [True: 136, False: 128]
  ------------------
 3586|    136|            if (libspdm_get_version_from_version_number(req_version_list[req_index]) ==
  ------------------
  |  Branch (3586:17): [True: 8, False: 128]
  ------------------
 3587|    136|                libspdm_get_version_from_version_number(res_version_list[res_index])) {
 3588|      8|                *common_version = req_version_list[req_index];
 3589|      8|                return true;
 3590|      8|            }
 3591|    136|        }
 3592|    136|    }
 3593|     50|    return false;
 3594|     58|}

libspdm_get_untrusted_opaque_data_supported_version_data_size:
   80|    686|{
   81|    686|    size_t size;
   82|       |
   83|    686|    if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
  ------------------
  |  |  112|    686|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
  |  Branch (83:9): [True: 343, False: 343]
  ------------------
   84|    343|        size = sizeof(spdm_general_opaque_data_table_header_t) +
   85|    343|               sizeof(secured_message_opaque_element_table_header_t) +
   86|    343|               sizeof(secured_message_opaque_element_supported_version_t) +
   87|    343|               sizeof(spdm_version_number_t) * version_count;
   88|    343|    } else {
   89|    343|        size = sizeof(secured_message_general_opaque_data_table_header_t) +
   90|    343|               sizeof(secured_message_opaque_element_table_header_t) +
   91|    343|               sizeof(secured_message_opaque_element_supported_version_t) +
   92|    343|               sizeof(spdm_version_number_t) * version_count;
   93|    343|    }
   94|       |    /* Add Padding*/
   95|    686|    return (size + 3) & ~3;
   96|    686|}
libspdm_get_element_from_opaque_data:
  117|    574|{
  118|    574|    const secured_message_general_opaque_data_table_header_t
  119|    574|    *general_opaque_data_table_header;
  120|    574|    const spdm_general_opaque_data_table_header_t
  121|    574|    *spdm_general_opaque_data_table_header;
  122|    574|    const opaque_element_table_header_t
  123|    574|    *opaque_element_table_header;
  124|    574|    uint16_t opaque_element_data_len;
  125|    574|    const secured_message_opaque_element_table_header_t
  126|    574|    *secured_message_element_table_header;
  127|    574|    const secured_message_opaque_element_header_t
  128|    574|    *secured_message_element_header;
  129|       |
  130|    574|    bool result;
  131|    574|    uint8_t element_num;
  132|    574|    uint8_t element_index;
  133|    574|    size_t data_element_size;
  134|    574|    size_t current_element_len;
  135|    574|    size_t total_element_len;
  136|       |
  137|    574|    total_element_len = 0;
  138|    574|    result = false;
  139|       |
  140|       |    /*check parameter in*/
  141|    574|    if (element_id > SPDM_REGISTRY_ID_MAX) {
  ------------------
  |  |  506|    574|#define SPDM_REGISTRY_ID_MAX  0xa
  ------------------
  |  Branch (141:9): [True: 0, False: 574]
  ------------------
  142|      0|        return false;
  143|      0|    }
  144|    574|    if ((data_in_size == 0) || (data_in == NULL)) {
  ------------------
  |  Branch (144:9): [True: 0, False: 574]
  |  Branch (144:32): [True: 0, False: 574]
  ------------------
  145|      0|        return false;
  146|      0|    }
  147|       |
  148|    574|    if (libspdm_get_connection_version (spdm_context) >= SPDM_MESSAGE_VERSION_12) {
  ------------------
  |  |  112|    574|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
  |  Branch (148:9): [True: 335, False: 239]
  ------------------
  149|    335|        spdm_general_opaque_data_table_header = data_in;
  150|    335|        if (data_in_size < sizeof(spdm_general_opaque_data_table_header_t)) {
  ------------------
  |  Branch (150:13): [True: 0, False: 335]
  ------------------
  151|      0|            return false;
  152|      0|        }
  153|    335|        if (spdm_general_opaque_data_table_header->total_elements < 1) {
  ------------------
  |  Branch (153:13): [True: 45, False: 290]
  ------------------
  154|     45|            return false;
  155|     45|        }
  156|    290|        opaque_element_table_header = (const void *)(spdm_general_opaque_data_table_header + 1);
  157|       |
  158|    290|        element_num = spdm_general_opaque_data_table_header->total_elements;
  159|       |
  160|    290|        data_element_size = data_in_size - sizeof(spdm_general_opaque_data_table_header_t);
  161|    290|    } else {
  162|    239|        general_opaque_data_table_header = data_in;
  163|    239|        if (data_in_size < sizeof(secured_message_general_opaque_data_table_header_t)) {
  ------------------
  |  Branch (163:13): [True: 0, False: 239]
  ------------------
  164|      0|            return false;
  165|      0|        }
  166|    239|        if ((general_opaque_data_table_header->spec_id !=
  ------------------
  |  Branch (166:13): [True: 153, False: 86]
  ------------------
  167|    239|             SECURED_MESSAGE_OPAQUE_DATA_SPEC_ID) ||
  ------------------
  |  |   78|    239|#define SECURED_MESSAGE_OPAQUE_DATA_SPEC_ID 0x444D5446
  ------------------
  168|    239|            (general_opaque_data_table_header->opaque_version !=
  ------------------
  |  Branch (168:13): [True: 12, False: 74]
  ------------------
  169|     86|             SECURED_MESSAGE_OPAQUE_VERSION) ||
  ------------------
  |  |   79|     86|#define SECURED_MESSAGE_OPAQUE_VERSION 0x1
  ------------------
  170|    239|            (general_opaque_data_table_header->total_elements < 1)) {
  ------------------
  |  Branch (170:13): [True: 1, False: 73]
  ------------------
  171|    166|            return false;
  172|    166|        }
  173|     73|        opaque_element_table_header = (const void *)(general_opaque_data_table_header + 1);
  174|       |
  175|     73|        element_num = general_opaque_data_table_header->total_elements;
  176|       |
  177|     73|        data_element_size = data_in_size -
  178|     73|                            sizeof(secured_message_general_opaque_data_table_header_t);
  179|     73|    }
  180|       |
  181|  2.85k|    for (element_index = 0; element_index < element_num; element_index++) {
  ------------------
  |  Branch (181:29): [True: 2.70k, False: 144]
  ------------------
  182|       |        /*ensure the opaque_element_table_header is valid*/
  183|  2.70k|        if (total_element_len + sizeof(opaque_element_table_header_t) >
  ------------------
  |  Branch (183:13): [True: 58, False: 2.65k]
  ------------------
  184|  2.70k|            data_element_size) {
  185|     58|            return false;
  186|     58|        }
  187|       |
  188|       |        /*check element header id*/
  189|  2.65k|        if ((opaque_element_table_header->id > SPDM_REGISTRY_ID_MAX)) {
  ------------------
  |  |  506|  2.65k|#define SPDM_REGISTRY_ID_MAX  0xa
  ------------------
  |  Branch (189:13): [True: 61, False: 2.59k]
  ------------------
  190|     61|            return false;
  191|     61|        }
  192|       |
  193|  2.59k|        if (total_element_len + sizeof(opaque_element_table_header_t) +
  ------------------
  |  Branch (193:13): [True: 34, False: 2.55k]
  ------------------
  194|  2.59k|            opaque_element_table_header->vendor_len + 2 >
  195|  2.59k|            data_element_size) {
  196|     34|            return false;
  197|     34|        }
  198|       |
  199|  2.55k|        opaque_element_data_len = libspdm_read_uint16(
  200|  2.55k|            (const uint8_t *)opaque_element_table_header +
  201|  2.55k|            sizeof(opaque_element_table_header_t) +
  202|  2.55k|            opaque_element_table_header->vendor_len);
  203|       |
  204|  2.55k|        current_element_len = sizeof(opaque_element_table_header_t) +
  205|  2.55k|                              opaque_element_table_header->vendor_len +
  206|  2.55k|                              2 + opaque_element_data_len;
  207|       |        /* Add Padding*/
  208|  2.55k|        current_element_len = (current_element_len + 3) & ~3;
  209|       |
  210|  2.55k|        total_element_len += current_element_len;
  211|       |
  212|  2.55k|        if (data_element_size < total_element_len) {
  ------------------
  |  Branch (212:13): [True: 49, False: 2.50k]
  ------------------
  213|     49|            return false;
  214|     49|        }
  215|       |
  216|  2.50k|        if (opaque_element_table_header->id == element_id) {
  ------------------
  |  Branch (216:13): [True: 1.98k, False: 521]
  ------------------
  217|  1.98k|            secured_message_element_table_header = (const void *)opaque_element_table_header;
  218|  1.98k|            if (secured_message_element_table_header->vendor_len == 0) {
  ------------------
  |  Branch (218:17): [True: 1.73k, False: 247]
  ------------------
  219|  1.73k|                secured_message_element_header =
  220|  1.73k|                    (const void *)(secured_message_element_table_header + 1);
  221|  1.73k|                if ((const uint8_t *)secured_message_element_header +
  ------------------
  |  Branch (221:21): [True: 17, False: 1.72k]
  ------------------
  222|  1.73k|                    sizeof(secured_message_opaque_element_header_t) >
  223|  1.73k|                    (const uint8_t *)data_in + data_in_size) {
  224|     17|                    return false;
  225|     17|                }
  226|       |
  227|  1.72k|                if ((secured_message_element_header->sm_data_id == sm_data_id) &&
  ------------------
  |  Branch (227:21): [True: 262, False: 1.46k]
  ------------------
  228|  1.72k|                    (secured_message_element_header->sm_data_version ==
  ------------------
  |  Branch (228:21): [True: 183, False: 79]
  ------------------
  229|    262|                     SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION)) {
  ------------------
  |  |   98|    262|#define SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_DATA_VERSION 0x1
  ------------------
  230|       |                    /*get element by element id*/
  231|    183|                    *get_element_ptr = opaque_element_table_header;
  232|    183|                    *get_element_len = current_element_len;
  233|    183|                    result = true;
  234|    183|                }
  235|  1.72k|            }
  236|  1.98k|        }
  237|       |
  238|       |        /*move to next element*/
  239|  2.49k|        opaque_element_table_header = (const opaque_element_table_header_t *)
  240|  2.49k|                                      ((const uint8_t *)opaque_element_table_header +
  241|  2.49k|                                       current_element_len);
  242|  2.49k|    }
  243|       |
  244|       |    /*ensure data size is right*/
  245|    144|    if (data_element_size != total_element_len) {
  ------------------
  |  Branch (245:9): [True: 33, False: 111]
  ------------------
  246|     33|        return false;
  247|     33|    }
  248|       |
  249|    111|    return result;
  250|    144|}

libspdm_read_uint16:
  170|  2.55k|{
  171|  2.55k|    return (uint16_t)(buffer[0] | buffer[1] << 8);
  172|  2.55k|}

libspdm_process_opaque_data_supported_version_data:
   98|    686|{
   99|    686|    const secured_message_opaque_element_table_header_t
  100|    686|    *opaque_element_table_header;
  101|    686|    const secured_message_opaque_element_supported_version_t
  102|    686|    *opaque_element_support_version;
  103|    686|    const spdm_version_number_t *versions_list;
  104|    686|    spdm_version_number_t common_version;
  105|    686|    uint8_t version_count;
  106|       |
  107|    686|    bool result;
  108|    686|    const void *get_element_ptr;
  109|    686|    size_t get_element_len;
  110|       |
  111|    686|    result = false;
  112|    686|    get_element_ptr = NULL;
  113|       |
  114|    686|    if (spdm_context->local_context.secured_message_version.spdm_version_count == 0) {
  ------------------
  |  Branch (114:9): [True: 0, False: 686]
  ------------------
  115|      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)))
  |  |  ------------------
  ------------------
  116|      0|    }
  117|       |
  118|    686|    if (data_in_size <
  ------------------
  |  Branch (118:9): [True: 112, False: 574]
  ------------------
  119|    686|        libspdm_get_untrusted_opaque_data_supported_version_data_size(spdm_context, 1)) {
  120|    112|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|    112|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|    112|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  121|    112|    }
  122|       |
  123|    574|    result = libspdm_get_element_from_opaque_data(
  124|    574|        spdm_context, data_in_size,
  125|    574|        data_in, SPDM_REGISTRY_ID_DMTF,
  ------------------
  |  |  495|    574|#define SPDM_REGISTRY_ID_DMTF 0x0
  ------------------
  126|    574|        SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_SUPPORTED_VERSION,
  ------------------
  |  |  122|    574|#define SECURED_MESSAGE_OPAQUE_ELEMENT_SMDATA_ID_SUPPORTED_VERSION 0x1
  ------------------
  127|    574|        &get_element_ptr, &get_element_len);
  128|    574|    if ((!result) || (get_element_ptr == NULL)) {
  ------------------
  |  Branch (128:9): [True: 473, False: 101]
  |  Branch (128:22): [True: 0, False: 101]
  ------------------
  129|    473|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,"get element error!\n"));
  130|    473|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|    473|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|    473|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  131|    473|    }
  132|       |
  133|    101|    opaque_element_table_header = (const secured_message_opaque_element_table_header_t*)
  134|    101|                                  get_element_ptr;
  135|       |
  136|       |    /*check for supported version data*/
  137|    101|    opaque_element_support_version = (const void *)(opaque_element_table_header + 1);
  138|       |
  139|    101|    if ((const uint8_t *)opaque_element_support_version +
  ------------------
  |  Branch (139:9): [True: 3, False: 98]
  ------------------
  140|    101|        sizeof(secured_message_opaque_element_supported_version_t) >
  141|    101|        (const uint8_t *)opaque_element_table_header + get_element_len) {
  142|      3|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      3|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      3|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  143|      3|    }
  144|       |
  145|     98|    if (opaque_element_support_version->version_count == 0) {
  ------------------
  |  Branch (145:9): [True: 3, False: 95]
  ------------------
  146|      3|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      3|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      3|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  147|      3|    }
  148|       |
  149|     95|    version_count = opaque_element_support_version->version_count;
  150|       |
  151|     95|    if ((opaque_element_table_header->vendor_len != 0) ||
  ------------------
  |  Branch (151:9): [True: 0, False: 95]
  ------------------
  152|     95|        (opaque_element_table_header->opaque_element_data_len !=
  ------------------
  |  Branch (152:9): [True: 28, False: 67]
  ------------------
  153|     95|         sizeof(secured_message_opaque_element_supported_version_t) +
  154|     95|         sizeof(spdm_version_number_t) * version_count)) {
  155|     28|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|     28|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|     28|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  156|     28|    }
  157|       |
  158|     67|    versions_list = (const void *)(opaque_element_support_version + 1);
  159|       |
  160|     67|    if ((const uint8_t *)versions_list + sizeof(spdm_version_number_t) >
  ------------------
  |  Branch (160:9): [True: 0, False: 67]
  ------------------
  161|     67|        (const uint8_t *)opaque_element_table_header + get_element_len) {
  162|      0|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  163|      0|    }
  164|       |
  165|     67|    result = libspdm_negotiate_connection_version(
  166|     67|        &common_version,
  167|     67|        spdm_context->local_context.secured_message_version.spdm_version,
  168|     67|        spdm_context->local_context.secured_message_version.spdm_version_count,
  169|     67|        versions_list, version_count);
  170|     67|    if (!result) {
  ------------------
  |  Branch (170:9): [True: 59, False: 8]
  ------------------
  171|     59|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|     59|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|     59|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  172|     59|    }
  173|       |
  174|      8|    libspdm_copy_mem(&(spdm_context->connection_info.secured_message_version),
  175|      8|                     sizeof(spdm_context->connection_info.secured_message_version),
  176|      8|                     &(common_version),
  177|      8|                     sizeof(spdm_version_number_t));
  178|       |
  179|      8|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      8|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      8|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  180|     67|}

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

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

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

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

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

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

libspdm_get_max_buffer_size:
   14|    686|{
   15|    686|    return SPDM_MAX_OPAQUE_DATA_SIZE;
  ------------------
  |  |   19|    686|#define SPDM_MAX_OPAQUE_DATA_SIZE 1024
  ------------------
   16|    686|}
libspdm_test_process_opaque_data_case1:
   19|    343|{
   20|    343|    libspdm_test_context_t *spdm_test_context;
   21|    343|    libspdm_context_t *spdm_context;
   22|       |
   23|       |
   24|    343|    spdm_test_context = *State;
   25|    343|    spdm_context = spdm_test_context->spdm_context;
   26|    343|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    343|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
   27|    343|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    343|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   28|    343|    spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
   29|    343|    spdm_context->connection_info.connection_state =
   30|    343|        LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
   31|    343|    spdm_context->local_context.capability.flags |=
   32|    343|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
  ------------------
  |  |  238|    343|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG 0x00000010
  ------------------
   33|       |
   34|    343|    spdm_context->local_context.secured_message_version.spdm_version_count = 1;
   35|    343|    spdm_context->local_context.secured_message_version.spdm_version[0] =
   36|    343|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|    343|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    343|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   37|       |
   38|    343|    libspdm_process_opaque_data_supported_version_data(
   39|    343|        spdm_context, spdm_test_context->test_buffer_size,
   40|    343|        (uint8_t *)spdm_test_context->test_buffer);
   41|       |
   42|    343|}
libspdm_test_process_opaque_data_case2:
   46|    343|{
   47|    343|    libspdm_test_context_t *spdm_test_context;
   48|    343|    libspdm_context_t *spdm_context;
   49|       |
   50|       |
   51|    343|    spdm_test_context = *State;
   52|    343|    spdm_context = spdm_test_context->spdm_context;
   53|    343|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    343|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
   54|    343|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    343|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   55|    343|    spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
   56|    343|    spdm_context->connection_info.connection_state =
   57|    343|        LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
   58|    343|    spdm_context->local_context.capability.flags |=
   59|    343|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
  ------------------
  |  |  238|    343|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG 0x00000010
  ------------------
   60|       |
   61|    343|    spdm_context->local_context.secured_message_version.spdm_version_count = 1;
   62|    343|    spdm_context->local_context.secured_message_version.spdm_version[0] =
   63|    343|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|    343|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    343|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   64|       |
   65|    343|    libspdm_process_opaque_data_supported_version_data(
   66|    343|        spdm_context, spdm_test_context->test_buffer_size,
   67|    343|        (uint8_t *)spdm_test_context->test_buffer);
   68|       |
   69|    343|}
libspdm_run_test_harness:
   78|    343|{
   79|    343|    void *State;
   80|       |
   81|    343|    libspdm_setup_test_context(&m_spdm_process_opaque_data_test_context);
   82|       |
   83|    343|    m_spdm_process_opaque_data_test_context.test_buffer = test_buffer;
   84|    343|    m_spdm_process_opaque_data_test_context.test_buffer_size =
   85|    343|        test_buffer_size;
   86|       |
   87|       |    /* Success Case*/
   88|    343|    libspdm_unit_test_group_setup(&State);
   89|    343|    libspdm_test_process_opaque_data_case1(&State);
   90|    343|    libspdm_unit_test_group_teardown(&State);
   91|       |
   92|       |    /* Success Case*/
   93|    343|    libspdm_unit_test_group_setup(&State);
   94|    343|    libspdm_test_process_opaque_data_case2(&State);
   95|    343|    libspdm_unit_test_group_teardown(&State);
   96|    343|}

