LCOV - code coverage report
Current view: top level - os_stub/spdm_device_secret_lib_sample - chal.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 54.2 % 24 13
Test Date: 2025-11-02 08:10:32 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2024-2025 DMTF. All rights reserved.
       4              :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
       5              :  **/
       6              : 
       7              : #include <stdarg.h>
       8              : #include <stddef.h>
       9              : #include <setjmp.h>
      10              : #include <stdint.h>
      11              : #include <stdlib.h>
      12              : #include <stdio.h>
      13              : #include <assert.h>
      14              : #include <string.h>
      15              : 
      16              : #include <base.h>
      17              : #include "library/memlib.h"
      18              : #include "spdm_device_secret_lib_internal.h"
      19              : #include "internal/libspdm_common_lib.h"
      20              : 
      21              : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
      22              : size_t libspdm_secret_lib_challenge_opaque_data_size;
      23              : bool g_check_challenge_request_context = false;
      24              : uint64_t g_challenge_request_context;
      25              : 
      26            8 : bool libspdm_challenge_opaque_data(
      27              :     void *spdm_context,
      28              :     spdm_version_number_t spdm_version,
      29              :     uint8_t slot_id,
      30              :     size_t request_context_size,
      31              :     const void *request_context,
      32              :     void *opaque_data,
      33              :     size_t *opaque_data_size)
      34              : {
      35              :     size_t index;
      36              : 
      37            8 :     LIBSPDM_ASSERT(libspdm_secret_lib_challenge_opaque_data_size <= *opaque_data_size);
      38              : 
      39            8 :     if (g_check_challenge_request_context) {
      40            0 :         if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >= SPDM_MESSAGE_VERSION_13) {
      41            0 :             LIBSPDM_ASSERT(request_context_size == SPDM_REQ_CONTEXT_SIZE);
      42            0 :             LIBSPDM_ASSERT(libspdm_read_uint64(request_context) == g_challenge_request_context);
      43              :         } else {
      44            0 :             LIBSPDM_ASSERT(request_context_size == 0);
      45            0 :             LIBSPDM_ASSERT(request_context == NULL);
      46              :         }
      47              :     }
      48              : 
      49            8 :     *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
      50              : 
      51           16 :     for (index = 0; index < *opaque_data_size; index++)
      52              :     {
      53            8 :         ((uint8_t *)opaque_data)[index] = (uint8_t)index;
      54              :     }
      55              : 
      56            8 :     return true;
      57              : }
      58              : 
      59            3 : bool libspdm_encap_challenge_opaque_data(
      60              :     void *spdm_context,
      61              :     spdm_version_number_t spdm_version,
      62              :     uint8_t slot_id,
      63              :     size_t request_context_size,
      64              :     const void *request_context,
      65              :     void *opaque_data,
      66              :     size_t *opaque_data_size)
      67              : {
      68              :     size_t index;
      69              : 
      70            3 :     LIBSPDM_ASSERT(libspdm_secret_lib_challenge_opaque_data_size <= *opaque_data_size);
      71              : 
      72            3 :     if (g_check_challenge_request_context) {
      73            0 :         if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >= SPDM_MESSAGE_VERSION_13) {
      74            0 :             LIBSPDM_ASSERT(request_context_size == SPDM_REQ_CONTEXT_SIZE);
      75            0 :             LIBSPDM_ASSERT(libspdm_read_uint64(request_context) == g_challenge_request_context);
      76              :         } else {
      77            0 :             LIBSPDM_ASSERT(request_context_size == 0);
      78            0 :             LIBSPDM_ASSERT(request_context == NULL);
      79              :         }
      80              :     }
      81              : 
      82            3 :     *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
      83              : 
      84            3 :     for (index = 0; index < *opaque_data_size; index++)
      85              :     {
      86            0 :         ((uint8_t *)opaque_data)[index] = (uint8_t)index;
      87              :     }
      88              : 
      89            3 :     return true;
      90              : }
      91              : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
        

Generated by: LCOV version 2.0-1