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 : bool g_start_basic_mut_auth = false;
26 :
27 8 : bool libspdm_challenge_opaque_data(
28 : void *spdm_context,
29 : spdm_version_number_t spdm_version,
30 : uint8_t slot_id,
31 : size_t request_context_size,
32 : const void *request_context,
33 : void *opaque_data,
34 : size_t *opaque_data_size)
35 : {
36 : size_t index;
37 :
38 8 : LIBSPDM_ASSERT(libspdm_secret_lib_challenge_opaque_data_size <= *opaque_data_size);
39 :
40 8 : if (g_check_challenge_request_context) {
41 0 : if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >= SPDM_MESSAGE_VERSION_13) {
42 0 : LIBSPDM_ASSERT(request_context_size == SPDM_REQ_CONTEXT_SIZE);
43 0 : LIBSPDM_ASSERT(libspdm_read_uint64(request_context) == g_challenge_request_context);
44 : } else {
45 0 : LIBSPDM_ASSERT(request_context_size == 0);
46 0 : LIBSPDM_ASSERT(request_context == NULL);
47 : }
48 : }
49 :
50 8 : *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
51 :
52 16 : for (index = 0; index < *opaque_data_size; index++)
53 : {
54 8 : ((uint8_t *)opaque_data)[index] = (uint8_t)index;
55 : }
56 :
57 8 : return true;
58 : }
59 :
60 3 : bool libspdm_encap_challenge_opaque_data(
61 : void *spdm_context,
62 : spdm_version_number_t spdm_version,
63 : uint8_t slot_id,
64 : size_t request_context_size,
65 : const void *request_context,
66 : void *opaque_data,
67 : size_t *opaque_data_size)
68 : {
69 : size_t index;
70 :
71 3 : LIBSPDM_ASSERT(libspdm_secret_lib_challenge_opaque_data_size <= *opaque_data_size);
72 :
73 3 : if (g_check_challenge_request_context) {
74 0 : if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >= SPDM_MESSAGE_VERSION_13) {
75 0 : LIBSPDM_ASSERT(request_context_size == SPDM_REQ_CONTEXT_SIZE);
76 0 : LIBSPDM_ASSERT(libspdm_read_uint64(request_context) == g_challenge_request_context);
77 : } else {
78 0 : LIBSPDM_ASSERT(request_context_size == 0);
79 0 : LIBSPDM_ASSERT(request_context == NULL);
80 : }
81 : }
82 :
83 3 : *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
84 :
85 3 : for (index = 0; index < *opaque_data_size; index++)
86 : {
87 0 : ((uint8_t *)opaque_data)[index] = (uint8_t)index;
88 : }
89 :
90 3 : return true;
91 : }
92 :
93 : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
94 0 : bool libspdm_challenge_start_mut_auth(
95 : void *spdm_context,
96 : spdm_version_number_t spdm_version,
97 : uint8_t slot_id,
98 : size_t request_context_size,
99 : const void *request_context)
100 : {
101 0 : return g_start_basic_mut_auth;
102 : }
103 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
104 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP */
|