Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2024 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 :
24 8 : bool libspdm_challenge_opaque_data(
25 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
26 : void *spdm_context,
27 : #endif
28 : spdm_version_number_t spdm_version,
29 : uint8_t slot_id,
30 : uint8_t *measurement_summary_hash,
31 : size_t measurement_summary_hash_size,
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 : *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
40 :
41 16 : for (index = 0; index < *opaque_data_size; index++)
42 : {
43 8 : ((uint8_t *)opaque_data)[index] = (uint8_t)index;
44 : }
45 :
46 8 : return true;
47 : }
48 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
49 :
50 : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
51 3 : bool libspdm_encap_challenge_opaque_data(
52 : #if LIBSPDM_HAL_PASS_SPDM_CONTEXT
53 : void *spdm_context,
54 : #endif
55 : spdm_version_number_t spdm_version,
56 : uint8_t slot_id,
57 : uint8_t *measurement_summary_hash,
58 : size_t measurement_summary_hash_size,
59 : void *opaque_data,
60 : size_t *opaque_data_size)
61 : {
62 : size_t index;
63 :
64 3 : LIBSPDM_ASSERT(libspdm_secret_lib_challenge_opaque_data_size <= *opaque_data_size);
65 :
66 3 : *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
67 :
68 3 : for (index = 0; index < *opaque_data_size; index++)
69 : {
70 0 : ((uint8_t *)opaque_data)[index] = (uint8_t)index;
71 : }
72 :
73 3 : return true;
74 : }
75 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
|