Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2026 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 : #ifndef SPDM_COMMON_LIB_INTERNAL_H
8 : #define SPDM_COMMON_LIB_INTERNAL_H
9 :
10 : #include "library/spdm_common_lib.h"
11 : #include "library/spdm_secured_message_lib.h"
12 : #include "library/spdm_return_status.h"
13 : #include "library/spdm_crypt_lib.h"
14 : #include "hal/library/debuglib.h"
15 : #include "hal/library/memlib.h"
16 : #include "hal/library/requester/reqasymsignlib.h"
17 : #include "hal/library/requester/psklib.h"
18 : #include "hal/library/responder/asymsignlib.h"
19 : #include "hal/library/responder/csrlib.h"
20 : #include "hal/library/responder/measlib.h"
21 : #include "hal/library/responder/keyexlib.h"
22 : #include "hal/library/responder/key_pair_info.h"
23 : #include "hal/library/responder/psklib.h"
24 : #include "hal/library/responder/setcertlib.h"
25 : #include "hal/library/endpointinfolib.h"
26 : #include "hal/library/eventlib.h"
27 : #include "hal/library/cryptlib.h"
28 :
29 : #define INVALID_SESSION_ID LIBSPDM_INVALID_SESSION_ID
30 : /* The SPDM specification does not limit the values of CTExponent and RDTExponent.
31 : * libspdm artificially limits their values to 31, which corresponds to approximately 35 minutes
32 : * for CT and RDT. If an endpoint takes longer than 35 minutes to generate an SPDM message then
33 : * libspdm assumes the Integrator would not want to interact with such an endpoint. A maximum value
34 : * of 31 also means that, when calculating CT and RDT, a left-shift will not result in C undefined
35 : * behavior.
36 : */
37 : #define LIBSPDM_MAX_CT_EXPONENT 31
38 : #define LIBSPDM_MAX_RDT_EXPONENT 31
39 :
40 : #define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
41 :
42 : typedef struct {
43 : uint8_t spdm_version_count;
44 : spdm_version_number_t spdm_version[SPDM_MAX_VERSION_COUNT];
45 : } libspdm_device_version_t;
46 :
47 : typedef struct {
48 : uint8_t secured_message_version_count;
49 : spdm_version_number_t secured_message_version[SECURED_SPDM_MAX_VERSION_COUNT];
50 : } libspdm_secured_message_version_t;
51 :
52 : typedef struct {
53 : uint8_t ct_exponent;
54 : uint64_t rtt;
55 : uint32_t st1;
56 : uint32_t flags;
57 : uint16_t ext_flags;
58 : uint32_t data_transfer_size;
59 : uint32_t sender_data_transfer_size;
60 : uint32_t max_spdm_msg_size;
61 : uint32_t transport_header_size;
62 : uint32_t transport_tail_size;
63 : } libspdm_device_capability_t;
64 :
65 : typedef struct {
66 : uint8_t measurement_spec;
67 : uint8_t other_params_support;
68 : uint8_t mel_spec;
69 : uint32_t measurement_hash_algo;
70 : uint32_t base_asym_algo;
71 : uint32_t base_hash_algo;
72 : uint16_t dhe_named_group;
73 : uint16_t aead_cipher_suite;
74 : uint16_t req_base_asym_alg;
75 : uint16_t key_schedule;
76 : uint32_t pqc_asym_algo;
77 : uint32_t req_pqc_asym_alg;
78 : uint32_t kem_alg;
79 : bool pqc_first;
80 : } libspdm_device_algorithm_t;
81 :
82 : typedef struct {
83 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
84 : uint8_t buffer[LIBSPDM_MAX_CERT_CHAIN_SIZE];
85 : size_t buffer_size;
86 : #else
87 : uint8_t buffer_hash[LIBSPDM_MAX_HASH_SIZE];
88 : uint32_t buffer_hash_size;
89 : /* leaf cert public key of the peer */
90 : void *leaf_cert_public_key;
91 : #endif
92 : } libspdm_peer_used_cert_chain_t;
93 :
94 : typedef struct {
95 : /* Local device info */
96 : libspdm_device_version_t version;
97 : libspdm_device_capability_t capability;
98 : libspdm_device_algorithm_t algorithm;
99 : libspdm_secured_message_version_t secured_message_version;
100 :
101 : /* My Certificate */
102 : const void *local_cert_chain_provision[SPDM_MAX_SLOT_COUNT];
103 : size_t local_cert_chain_provision_size[SPDM_MAX_SLOT_COUNT];
104 : uint8_t local_supported_slot_mask;
105 : uint8_t cert_slot_reset_mask;
106 : spdm_key_pair_id_t local_key_pair_id[SPDM_MAX_SLOT_COUNT];
107 : spdm_certificate_info_t local_cert_info[SPDM_MAX_SLOT_COUNT];
108 : spdm_key_usage_bit_mask_t local_key_usage_bit_mask[SPDM_MAX_SLOT_COUNT];
109 : /* My raw public key (slot_id - 0xFF) */
110 : const void *local_public_key_provision;
111 : size_t local_public_key_provision_size;
112 :
113 : /* Peer Root Certificate */
114 : const void *peer_root_cert_provision[LIBSPDM_MAX_ROOT_CERT_SUPPORT];
115 : size_t peer_root_cert_provision_size[LIBSPDM_MAX_ROOT_CERT_SUPPORT];
116 : /* Peer raw public key (slot_id - 0xFF) */
117 : const void *peer_public_key_provision;
118 : size_t peer_public_key_provision_size;
119 :
120 : /* Peer Cert verify*/
121 : libspdm_verify_spdm_cert_chain_func verify_peer_spdm_cert_chain;
122 :
123 : /* Responder policy*/
124 : bool basic_mut_auth_requested;
125 : uint8_t heartbeat_period;
126 :
127 : /*The device role*/
128 : bool is_requester;
129 : } libspdm_local_context_t;
130 :
131 : typedef struct {
132 : /* Connection State */
133 : libspdm_connection_state_t connection_state;
134 :
135 : /* Peer device info (negotiated) */
136 : spdm_version_number_t version;
137 : libspdm_device_capability_t capability;
138 : libspdm_device_algorithm_t algorithm;
139 :
140 : /* Peer digests buffer */
141 : uint8_t peer_provisioned_slot_mask;
142 : uint8_t peer_supported_slot_mask;
143 :
144 : spdm_key_pair_id_t peer_key_pair_id[SPDM_MAX_SLOT_COUNT];
145 : spdm_certificate_info_t peer_cert_info[SPDM_MAX_SLOT_COUNT];
146 : spdm_key_usage_bit_mask_t peer_key_usage_bit_mask[SPDM_MAX_SLOT_COUNT];
147 :
148 : /* Peer CertificateChain */
149 : libspdm_peer_used_cert_chain_t peer_used_cert_chain[SPDM_MAX_SLOT_COUNT];
150 :
151 : /* Specifies whether the cached negotiated state should be invalidated. (responder only)
152 : * This is a "sticky" bit wherein if it is set to 1 then it cannot be set to 0. */
153 : uint8_t end_session_attributes;
154 :
155 : /* multi-key negotiated result */
156 : bool multi_key_conn_req;
157 : bool multi_key_conn_rsp;
158 :
159 : /* Sticky: set once a non-GET_DIGESTS request is processed after NEGOTIATED. A DIGESTS is added
160 : * to message_d only when this is false (DIGESTS immediately follows the VCA). */
161 : bool digest_transcript_window_closed;
162 : } libspdm_connection_info_t;
163 :
164 : typedef struct {
165 : size_t max_buffer_size;
166 : size_t buffer_size;
167 : /*uint8_t buffer[max_buffer_size];*/
168 : } libspdm_managed_buffer_t;
169 :
170 : typedef struct {
171 : size_t max_buffer_size;
172 : size_t buffer_size;
173 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
174 : } libspdm_vca_managed_buffer_t;
175 :
176 : /*
177 : * +--------------------------+------------------------------------------+---------+
178 : * | DIGESTS 1.4 | 4 + (H [+ 4]) * SlotNum = [36, 548] | [1, 18] |
179 : * +--------------------------+------------------------------------------+---------+
180 : * It is for multi-key.
181 : */
182 : #define LIBSPDM_MAX_MESSAGE_D_BUFFER_SIZE (4 + \
183 : (LIBSPDM_MAX_HASH_SIZE + 4) * SPDM_MAX_SLOT_COUNT)
184 :
185 : typedef struct {
186 : size_t max_buffer_size;
187 : size_t buffer_size;
188 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_D_BUFFER_SIZE];
189 : } libspdm_message_d_managed_buffer_t;
190 :
191 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
192 :
193 : /*
194 : * +--------------------------+------------------------------------------+---------+
195 : * | GET_DIGESTS 1.4 | 4 | 1 |
196 : * | DIGESTS 1.4 | 4 + (H [+ 4]) * SlotNum = [36, 548] | [1, 18] |
197 : * +--------------------------+------------------------------------------+---------+
198 : * | GET_CERTIFICATE 1.4 | 16 | 1 |
199 : * | CERTIFICATE 1.4 | 16 + PortionLen | [1, ] |
200 : * +--------------------------+------------------------------------------+---------+
201 : */
202 : #define LIBSPDM_MAX_MESSAGE_B_BUFFER_SIZE (40 + \
203 : (LIBSPDM_MAX_HASH_SIZE + 4) * SPDM_MAX_SLOT_COUNT + \
204 : LIBSPDM_MAX_CERT_CHAIN_SIZE)
205 :
206 : /*
207 : * +--------------------------+------------------------------------------+---------+
208 : * | CHALLENGE 1.4 | 44 | 1 |
209 : * | CHALLENGE_AUTH 1.4 | 46 + H * 2 + S [+ O] = [166, 678] | [6, 23] |
210 : * +--------------------------+------------------------------------------+---------+
211 : */
212 : #define LIBSPDM_MAX_MESSAGE_C_BUFFER_SIZE (90 + \
213 : LIBSPDM_MAX_HASH_SIZE * 2 + \
214 : LIBSPDM_RSP_SIGNATURE_DATA_MAX_SIZE + \
215 : SPDM_MAX_OPAQUE_DATA_SIZE)
216 :
217 : /*
218 : * +--------------------------+------------------------------------------+---------+
219 : * | GET_MEASUREMENTS 1.4 | 13 + Nonce (0 or 32) | 1 |
220 : * | MEASUREMENTS 1.4 | 50 + MeasRecLen (+ S) [+ O] = [106, 554] | [4, 19] |
221 : * +--------------------------+------------------------------------------+---------+
222 : */
223 : #define LIBSPDM_MAX_MESSAGE_M_BUFFER_SIZE (63 + SPDM_NONCE_SIZE + \
224 : LIBSPDM_MAX_MEASUREMENT_RECORD_SIZE + \
225 : LIBSPDM_RSP_SIGNATURE_DATA_MAX_SIZE + \
226 : SPDM_MAX_OPAQUE_DATA_SIZE)
227 :
228 : /*
229 : * +--------------------------+------------------------------------------+---------+
230 : * | KEY_EXCHANGE 1.4 | 42 + D [+ O] = [106, 554] | [4, 19] |
231 : * | KEY_EXCHANGE_RSP 1.4 | 42 + D + H + S (+ H) [+ O] = [234, 1194] | [8, 40] |
232 : * +--------------------------+------------------------------------------+---------+
233 : * | PSK_EXCHANGE 1.4 | 12 [+ PSKHint] + R [+ O] = 44 | 2 |
234 : * | PSK_EXCHANGE_RSP 1.4 | 12 + R + H (+ H) [+ O] = [108, 172] | [4, 6] |
235 : * +--------------------------+------------------------------------------+---------+
236 : */
237 : #define LIBSPDM_MAX_MESSAGE_K_BUFFER_SIZE (84 + LIBSPDM_REQ_EXCHANGE_DATA_MAX_SIZE + \
238 : LIBSPDM_RSP_EXCHANGE_DATA_MAX_SIZE + \
239 : LIBSPDM_MAX_HASH_SIZE * 2 + \
240 : LIBSPDM_RSP_SIGNATURE_DATA_MAX_SIZE + \
241 : SPDM_MAX_OPAQUE_DATA_SIZE * 2)
242 :
243 : /*
244 : * +--------------------------+------------------------------------------+---------+
245 : * | FINISH 1.4 | 6 (+ S) + H [+ O] = [100, 580] | [4, 20] |
246 : * | FINISH_RSP 1.4 | 6 (+ H) [+ O] = [36, 69] | [1, 3] |
247 : * +--------------------------+------------------------------------------+---------+
248 : * | PSK_FINISH 1.4 | 6 + H [+ O] = [36, 68] | [1, 3] |
249 : * | PSK_FINISH_RSP 1.4 | 6 [+ O] | 1 |
250 : * +--------------------------+------------------------------------------+---------+
251 : */
252 : #define LIBSPDM_MAX_MESSAGE_F_BUFFER_SIZE (12 + LIBSPDM_MAX_HASH_SIZE * 2 + \
253 : LIBSPDM_REQ_SIGNATURE_DATA_MAX_SIZE + \
254 : SPDM_MAX_OPAQUE_DATA_SIZE * 2)
255 :
256 : /*
257 : * +--------------------------+------------------------------------------+---------+
258 : * | GET_EP_INFO 1.4 | 8 + Nonce (0 or 32) = [8, 40] | 1 |
259 : * | EP_INFO 1.4 | 12 + Nonce + EPInfoLen (+ S) = [12, 1024]| [1, 25] |
260 : * +--------------------------+------------------------------------------+---------+
261 : */
262 : #define LIBSPDM_MAX_MESSAGE_E_BUFFER_SIZE (20 + SPDM_NONCE_SIZE * 2 + \
263 : LIBSPDM_MAX_ENDPOINT_INFO_LENGTH + \
264 : LIBSPDM_RSP_SIGNATURE_DATA_MAX_SIZE)
265 :
266 : #define LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE \
267 : (LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE + LIBSPDM_MAX_MESSAGE_M_BUFFER_SIZE)
268 :
269 : #define LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE \
270 : (LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE + \
271 : LIBSPDM_MAX_MESSAGE_B_BUFFER_SIZE + LIBSPDM_MAX_MESSAGE_C_BUFFER_SIZE)
272 :
273 : #define LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE \
274 : (LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE + \
275 : LIBSPDM_MAX_MESSAGE_D_BUFFER_SIZE + \
276 : LIBSPDM_MAX_HASH_SIZE + LIBSPDM_MAX_MESSAGE_K_BUFFER_SIZE + \
277 : LIBSPDM_MAX_MESSAGE_D_BUFFER_SIZE + \
278 : LIBSPDM_MAX_HASH_SIZE + LIBSPDM_MAX_MESSAGE_F_BUFFER_SIZE)
279 :
280 : #define LIBSPDM_MAX_MESSAGE_IL1IL2_BUFFER_SIZE \
281 : (LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE + LIBSPDM_MAX_MESSAGE_E_BUFFER_SIZE)
282 :
283 : typedef struct {
284 : size_t max_buffer_size;
285 : size_t buffer_size;
286 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_B_BUFFER_SIZE];
287 : } libspdm_message_b_managed_buffer_t;
288 :
289 : typedef struct {
290 : size_t max_buffer_size;
291 : size_t buffer_size;
292 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_C_BUFFER_SIZE];
293 : } libspdm_message_c_managed_buffer_t;
294 :
295 : typedef struct {
296 : size_t max_buffer_size;
297 : size_t buffer_size;
298 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_M_BUFFER_SIZE];
299 : } libspdm_message_m_managed_buffer_t;
300 :
301 : typedef struct {
302 : size_t max_buffer_size;
303 : size_t buffer_size;
304 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_K_BUFFER_SIZE];
305 : } libspdm_message_k_managed_buffer_t;
306 :
307 : typedef struct {
308 : size_t max_buffer_size;
309 : size_t buffer_size;
310 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_F_BUFFER_SIZE];
311 : } libspdm_message_f_managed_buffer_t;
312 :
313 : typedef struct {
314 : size_t max_buffer_size;
315 : size_t buffer_size;
316 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_E_BUFFER_SIZE];
317 : } libspdm_message_e_managed_buffer_t;
318 :
319 : typedef struct {
320 : size_t max_buffer_size;
321 : size_t buffer_size;
322 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_L1L2_BUFFER_SIZE];
323 : } libspdm_l1l2_managed_buffer_t;
324 :
325 : typedef struct {
326 : size_t max_buffer_size;
327 : size_t buffer_size;
328 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE];
329 : } libspdm_m1m2_managed_buffer_t;
330 :
331 : typedef struct {
332 : size_t max_buffer_size;
333 : size_t buffer_size;
334 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_IL1IL2_BUFFER_SIZE];
335 : } libspdm_il1il2_managed_buffer_t;
336 :
337 : typedef struct {
338 : size_t max_buffer_size;
339 : size_t buffer_size;
340 : uint8_t buffer[LIBSPDM_MAX_MESSAGE_TH_BUFFER_SIZE];
341 : } libspdm_th_managed_buffer_t;
342 :
343 : #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
344 :
345 : /* signature = Sign(SK, hash(M1))
346 : * Verify(PK, hash(M2), signature)*/
347 :
348 : /* M1/M2 = Concatenate (A, B, C)
349 : * A = Concatenate (GET_VERSION, VERSION, GET_CAPABILITIES, CAPABILITIES, NEGOTIATE_ALGORITHMS, ALGORITHMS)
350 : * B = Concatenate (GET_DIGEST, DIGEST, GET_CERTIFICATE, CERTIFICATE)
351 : * C = Concatenate (CHALLENGE, CHALLENGE_AUTH\signature)*/
352 :
353 : /* Mut M1/M2 = Concatenate (MutB, MutC)
354 : * MutB = Concatenate (GET_DIGEST, DIGEST, GET_CERTIFICATE, CERTIFICATE)
355 : * MutC = Concatenate (CHALLENGE, CHALLENGE_AUTH\signature)*/
356 :
357 : /* signature = Sign(SK, hash(L1))
358 : * Verify(PK, hash(L2), signature)*/
359 :
360 : /* L1/L2 = Concatenate (M)
361 : * M = Concatenate (GET_MEASUREMENT, MEASUREMENT\signature)*/
362 :
363 : /* IL1/IL2 = Concatenate (A, E)
364 : * E = Concatenate (GET_ENDPOINT_INFO, ENDPOINT_INFO\signature)*/
365 :
366 : /* Encap IL1/IL2 = Concatenate (A, Encap E)
367 : * Encap E = Concatenate (GET_ENDPOINT_INFO, ENDPOINT_INFO\signature)*/
368 :
369 : typedef struct {
370 : /* the message_a must be plan text because we do not know the algorithm yet.*/
371 : libspdm_vca_managed_buffer_t message_a;
372 : libspdm_message_d_managed_buffer_t message_d;
373 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
374 : libspdm_message_b_managed_buffer_t message_b;
375 : libspdm_message_c_managed_buffer_t message_c;
376 : libspdm_message_b_managed_buffer_t message_mut_b;
377 : libspdm_message_c_managed_buffer_t message_mut_c;
378 : libspdm_message_m_managed_buffer_t message_m;
379 : libspdm_message_e_managed_buffer_t message_e;
380 : libspdm_message_e_managed_buffer_t message_encap_e;
381 : #else
382 : void *digest_context_m1m2;
383 : void *digest_context_mut_m1m2;
384 : void *digest_context_l1l2;
385 : void *digest_context_il1il2;
386 : void *digest_context_encap_il1il2;
387 : #endif
388 : } libspdm_transcript_t;
389 :
390 : /* TH for KEY_EXCHANGE response signature: Concatenate (A, D, Ct, K)
391 : * D = DIGEST, if MULTI_KEY_CONN_RSP
392 : * Ct = certificate chain
393 : * K = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response\signature+verify_data)*/
394 :
395 : /* TH for KEY_EXCHANGE response HMAC: Concatenate (A, D, Ct, K)
396 : * D = DIGEST, if MULTI_KEY_CONN_RSP
397 : * Ct = certificate chain
398 : * K = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response\verify_data)*/
399 :
400 : /* TH for FINISH request signature: Concatenate (A, D, Ct, K, EncapD, CM, F)
401 : * D = DIGEST, if MULTI_KEY_CONN_RSP
402 : * Ct = certificate chain
403 : * K = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response)
404 : * EncapD = Encap DIGEST, if MULTI_KEY_CONN_REQ
405 : * CM = mutual certificate chain
406 : * F = Concatenate (FINISH request\signature+verify_data)*/
407 :
408 : /* TH for FINISH response HMAC: Concatenate (A, D, Ct, K, EncapD, CM, F)
409 : * D = DIGEST, if MULTI_KEY_CONN_RSP
410 : * Ct = certificate chain
411 : * K = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response)
412 : * EncapD = Encap DIGEST, if MULTI_KEY_CONN_REQ
413 : * CM = mutual certificate chain, if MutAuth
414 : * F = Concatenate (FINISH request\verify_data)*/
415 :
416 : /* th1: Concatenate (A, D, Ct, K)
417 : * D = DIGEST, if MULTI_KEY_CONN_RSP
418 : * Ct = certificate chain
419 : * K = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response)*/
420 :
421 : /* th2: Concatenate (A, D, Ct, K, EncapD, CM, F)
422 : * D = DIGEST, if MULTI_KEY_CONN_RSP
423 : * Ct = certificate chain
424 : * K = Concatenate (KEY_EXCHANGE request, KEY_EXCHANGE response)
425 : * EncapD = Encap DIGEST, if MULTI_KEY_CONN_REQ
426 : * CM = mutual certificate chain, if MutAuth
427 : * F = Concatenate (FINISH request, FINISH response)*/
428 :
429 : /* TH for PSK_EXCHANGE response HMAC: Concatenate (A, K)
430 : * K = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response\verify_data)*/
431 :
432 : /* TH for PSK_FINISH response HMAC: Concatenate (A, K, F)
433 : * K = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response)
434 : * F = Concatenate (PSK_FINISH request\verify_data)*/
435 :
436 : /* TH1_PSK1: Concatenate (A, K)
437 : * K = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response\verify_data)*/
438 :
439 : /* TH1_PSK2: Concatenate (A, K, F)
440 : * K = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response)
441 : * F = Concatenate (PSK_FINISH request\verify_data)*/
442 :
443 : /* TH2_PSK: Concatenate (A, K, F)
444 : * K = Concatenate (PSK_EXCHANGE request, PSK_EXCHANGE response)
445 : * F = Concatenate (PSK_FINISH request, PSK_FINISH response)*/
446 :
447 : typedef struct {
448 : libspdm_message_d_managed_buffer_t message_encap_d;
449 : /* Sticky: set once a non-GET_DIGESTS encapsulated request is processed first. An encapsulated
450 : * DIGESTS is added to message_encap_d only when this is false (it is the first encap response). */
451 : bool encap_digest_window_closed;
452 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
453 : libspdm_message_k_managed_buffer_t message_k;
454 : libspdm_message_f_managed_buffer_t message_f;
455 : libspdm_message_m_managed_buffer_t message_m;
456 : libspdm_message_e_managed_buffer_t message_e;
457 : libspdm_message_e_managed_buffer_t message_encap_e;
458 : #else
459 : bool message_f_initialized;
460 : void *digest_context_th;
461 : void *digest_context_l1l2;
462 : void *digest_context_il1il2;
463 : void *digest_context_encap_il1il2;
464 : /* this is back up for message F reset.*/
465 : void *digest_context_th_backup;
466 : #endif
467 : } libspdm_session_transcript_t;
468 :
469 : typedef struct {
470 : uint32_t session_id;
471 : bool use_psk;
472 : uint8_t mut_auth_requested;
473 : uint8_t end_session_attributes;
474 : uint8_t session_policy;
475 : uint8_t heartbeat_period;
476 : libspdm_session_transcript_t session_transcript;
477 : /* Register for the last KEY_UPDATE token and operation (responder only)*/
478 : spdm_key_update_request_t last_key_update_request;
479 : void *secured_message_context;
480 : /* Only present in session info as it is currently only used within a secure session. */
481 : uint8_t local_used_cert_chain_slot_id;
482 : uint8_t peer_used_cert_chain_slot_id;
483 : } libspdm_session_info_t;
484 :
485 : #define LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT 3
486 : typedef struct {
487 : /* Valid OpCode: GET_DIGEST/GET_CERTIFICATE/CHALLENGE/KEY_UPDATE/GET_ENDPOINT_INFO/SEND_EVENT
488 : * The last one is 0x00, as a terminator. */
489 : uint8_t request_op_code_sequence[LIBSPDM_MAX_ENCAP_REQUEST_OP_CODE_SEQUENCE_COUNT + 1];
490 : uint8_t request_op_code_count;
491 : uint8_t current_request_op_code;
492 : uint8_t request_id;
493 : uint8_t req_slot_id;
494 : spdm_message_header_t last_encap_request_header;
495 : size_t last_encap_request_size;
496 : uint32_t cert_chain_total_len;
497 : uint8_t req_context[SPDM_REQ_CONTEXT_SIZE];
498 : uint32_t session_id;
499 : bool use_large_cert_chain;
500 : } libspdm_encap_context_t;
501 :
502 : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
503 : typedef struct {
504 : bool chunk_in_use;
505 : uint8_t chunk_handle;
506 : uint32_t chunk_seq_no;
507 : size_t chunk_bytes_transferred;
508 :
509 : void* large_message;
510 : size_t large_message_size;
511 : size_t large_message_capacity;
512 : } libspdm_chunk_info_t;
513 :
514 : typedef struct {
515 : libspdm_chunk_info_t send;
516 : libspdm_chunk_info_t get;
517 : } libspdm_chunk_context_t;
518 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
519 :
520 : #if LIBSPDM_ENABLE_MSG_LOG
521 : typedef struct {
522 : void *buffer;
523 : size_t max_buffer_size;
524 : uint32_t mode;
525 : size_t buffer_size;
526 : uint32_t status;
527 : } libspdm_msg_log_t;
528 : #endif /* LIBSPDM_ENABLE_MSG_LOG */
529 :
530 : #if LIBSPDM_FIPS_MODE
531 : typedef struct {
532 : /**
533 : * Tested algo flag: 0 represents that the algo is not tested.
534 : * See LIBSPDM_FIPS_SELF_TEST_xxx;
535 : **/
536 : uint32_t tested_algo;
537 : /**
538 : * Flag for the result of run algo self_test, 0 represents the result is failed.
539 : * See LIBSPDM_FIPS_SELF_TEST_xxx;
540 : **/
541 : uint32_t self_test_result;
542 : /**
543 : * Buffer provided by integrator to hold large intermediate results.
544 : **/
545 : void *selftest_buffer;
546 : size_t selftest_buffer_size;
547 : } libspdm_fips_selftest_context_t;
548 : #endif /* LIBSPDM_FIPS_MODE */
549 :
550 : #define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
551 :
552 : typedef struct {
553 : uint32_t version;
554 :
555 : /* IO information */
556 : libspdm_device_send_message_func send_message;
557 : libspdm_device_receive_message_func receive_message;
558 :
559 : /*
560 : * reserved for request and response in the main dispatch function in SPDM responder.
561 : * this buffer is the transport message received from spdm_context->receive_message()
562 : * or sent to spdm_context->send_message().
563 : * This message may be SPDM transport message or secured SPDM transport message.
564 : **/
565 : libspdm_device_acquire_sender_buffer_func acquire_sender_buffer;
566 : libspdm_device_release_sender_buffer_func release_sender_buffer;
567 : libspdm_device_acquire_receiver_buffer_func acquire_receiver_buffer;
568 : libspdm_device_release_receiver_buffer_func release_receiver_buffer;
569 :
570 : /* Transport Layer information */
571 : libspdm_transport_encode_message_func transport_encode_message;
572 : libspdm_transport_decode_message_func transport_decode_message;
573 :
574 : /* Cached plain text command
575 : * If the command is cipher text, decrypt then cache it. */
576 : void *last_spdm_request;
577 : size_t last_spdm_request_size;
578 :
579 : /* Buffers used for data processing and transport. */
580 : void *scratch_buffer;
581 : size_t scratch_buffer_size;
582 : void *sender_buffer;
583 : size_t sender_buffer_size;
584 : void *receiver_buffer;
585 : size_t receiver_buffer_size;
586 :
587 : /* Cache session_id in this spdm_message, only valid for secured message. */
588 : uint32_t last_spdm_request_session_id;
589 : bool last_spdm_request_session_id_valid;
590 :
591 : /* Cache the error in libspdm_process_request. It is handled in libspdm_build_response. */
592 : libspdm_error_struct_t last_spdm_error;
593 :
594 : /* Register GetResponse function (responder only) */
595 : void *get_response_func;
596 :
597 : /* Register GetEncapResponse function (requester only) */
598 : void *get_encap_response_func;
599 : libspdm_encap_context_t encap_context;
600 :
601 : /* Register spdm_session_state_callback function (responder only)
602 : * Register can know the state after StartSession / EndSession. */
603 : void *spdm_session_state_callback;
604 :
605 : /* Register spdm_connection_state_callback function (responder only)
606 : * Register can know the connection state such as negotiated. */
607 : void *spdm_connection_state_callback;
608 :
609 : /* Register libspdm_key_update_callback function (responder only)
610 : * Register can know when session keys are updated during KEY_UPDATE operations. */
611 : void *spdm_key_update_callback;
612 :
613 : libspdm_local_context_t local_context;
614 :
615 : libspdm_connection_info_t connection_info;
616 : libspdm_transcript_t transcript;
617 :
618 : libspdm_session_info_t session_info[LIBSPDM_MAX_SESSION_COUNT];
619 :
620 : /* Buffer that the Responder uses to store the Requester's certificate chain for
621 : * mutual authentication. */
622 : void *mut_auth_cert_chain_buffer;
623 : size_t mut_auth_cert_chain_buffer_size;
624 : size_t mut_auth_cert_chain_buffer_max_size;
625 :
626 : /* Cache latest session ID for HANDSHAKE_IN_THE_CLEAR */
627 : uint32_t latest_session_id;
628 :
629 : /* Register for Responder state, be initial to Normal (responder only) */
630 : libspdm_response_state_t response_state;
631 :
632 : /* Cached data for SPDM_ERROR_CODE_RESPONSE_NOT_READY/SPDM_RESPOND_IF_READY */
633 : spdm_error_data_response_not_ready_t error_data;
634 : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
635 : void *cache_spdm_request;
636 : size_t cache_spdm_request_size;
637 : /* Session context of the original request that triggered the ResponseNotReady flow. The validity
638 : * of the RESPOND_IF_READY request is defined by that original request, so the RESPOND_IF_READY
639 : * must arrive in the same session context (same in-session/out-of-session, and if in a session
640 : * the same session_id). */
641 : bool cache_spdm_request_session_id_valid;
642 : uint32_t cache_spdm_request_session_id;
643 : #endif
644 : uint8_t current_token;
645 :
646 : /* Register for the retry times when receive "BUSY" Error response (requester only) */
647 : uint8_t retry_times;
648 : /* Register for the delay time in microseconds between retry requests
649 : * when receive "BUSY" Error response (requester only) */
650 : uint64_t retry_delay_time;
651 : bool crypto_request;
652 :
653 : /* App context data for use by application */
654 : void *app_context_data_ptr;
655 :
656 : /* See LIBSPDM_DATA_HANDLE_ERROR_RETURN_POLICY_*. */
657 : uint8_t handle_error_return_policy;
658 :
659 : /* Max session count for DHE session and PSK session
660 : * Set via LIBSPDM_DATA_MAX_DHE_SESSION_COUNT and LIBSPDM_DATA_MAX_PSK_SESSION_COUNT */
661 : uint32_t max_dhe_session_count;
662 : uint32_t max_psk_session_count;
663 :
664 : /* Current session count for DHE session and PSK session */
665 : uint32_t current_dhe_session_count;
666 : uint32_t current_psk_session_count;
667 :
668 : /* see LIBSPDM_DATA_MAX_SPDM_SESSION_SEQUENCE_NUMBER */
669 : uint64_t max_spdm_session_sequence_number;
670 :
671 : uint8_t sequence_number_endian;
672 :
673 : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
674 : /* Chunk specific context */
675 : libspdm_chunk_context_t chunk_context;
676 : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
677 :
678 : #if LIBSPDM_ENABLE_MSG_LOG
679 : libspdm_msg_log_t msg_log;
680 : #endif /* LIBSPDM_ENABLE_MSG_LOG */
681 :
682 : #if LIBSPDM_FIPS_MODE
683 : libspdm_fips_selftest_context_t fips_selftest_context;
684 : #endif /* LIBSPDM_FIPS_MODE */
685 :
686 : /* Endianness (BE/LE/Both) to use for signature verification on SPDM 1.0 and 1.1
687 : * This field is ignored for other SPDM versions */
688 : uint8_t spdm_10_11_verify_signature_endian;
689 :
690 : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
691 : libspdm_vendor_response_callback_func vendor_response_callback;
692 : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
693 :
694 : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
695 : libspdm_process_event_func process_event;
696 : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
697 :
698 : #if (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT)
699 : libspdm_get_endpoint_info_callback_func get_endpoint_info_callback;
700 : #endif /* (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT) */
701 :
702 : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
703 : libspdm_meas_log_reset_callback_func spdm_meas_log_reset_callback;
704 : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
705 : } libspdm_context_t;
706 :
707 : #define LIBSPDM_CONTEXT_SIZE_WITHOUT_SECURED_CONTEXT (sizeof(libspdm_context_t))
708 : #define LIBSPDM_CONTEXT_SIZE_ALL (LIBSPDM_CONTEXT_SIZE_WITHOUT_SECURED_CONTEXT + \
709 : LIBSPDM_SECURED_MESSAGE_CONTEXT_SIZE * LIBSPDM_MAX_SESSION_COUNT)
710 :
711 : #if LIBSPDM_DEBUG_PRINT_ENABLE
712 : /**
713 : * Return the request code name based on given request code.
714 : *
715 : * @param request_code The SPDM request code.
716 : *
717 : * @return request code name according to the request code.
718 : **/
719 : const char *libspdm_get_code_str(uint8_t request_code);
720 :
721 : #ifdef LIBSPDM_INTERNAL_DUMP_HEX_STR_OVERRIDE
722 : extern void LIBSPDM_INTERNAL_DUMP_HEX_STR_OVERRIDE(const uint8_t *data, size_t size);
723 : #define LIBSPDM_INTERNAL_DUMP_HEX_STR(data, size) LIBSPDM_INTERNAL_DUMP_HEX_STR_OVERRIDE(data, size)
724 : #else
725 : /**
726 : * This function dump raw data.
727 : *
728 : * @param data raw data
729 : * @param size raw data size
730 : **/
731 : void libspdm_internal_dump_hex_str(const uint8_t *data, size_t size);
732 : #define LIBSPDM_INTERNAL_DUMP_HEX_STR(data, size) libspdm_internal_dump_hex_str(data, size)
733 : #endif /* LIBSPDM_INTERNAL_DUMP_HEX_STR_OVERRIDE */
734 :
735 : #ifdef LIBSPDM_INTERNAL_DUMP_DATA_OVERRIDE
736 : extern void LIBSPDM_INTERNAL_DUMP_DATA_OVERRIDE(const uint8_t *data, size_t size);
737 : #define LIBSPDM_INTERNAL_DUMP_DATA(data, size) LIBSPDM_INTERNAL_DUMP_DATA_OVERRIDE(data, size)
738 : #else
739 : /**
740 : * This function dump raw data.
741 : *
742 : * @param data raw data
743 : * @param size raw data size
744 : **/
745 : void libspdm_internal_dump_data(const uint8_t *data, size_t size);
746 : #define LIBSPDM_INTERNAL_DUMP_DATA(data, size) libspdm_internal_dump_data(data, size)
747 : #endif /* LIBSPDM_INTERNAL_DUMP_DATA_OVERRIDE */
748 :
749 : #ifdef LIBSPDM_INTERNAL_DUMP_HEX_OVERRIDE
750 : extern void LIBSPDM_INTERNAL_DUMP_HEX_OVERRIDE(const uint8_t *data, size_t size);
751 : #define LIBSPDM_INTERNAL_DUMP_HEX(data, size) LIBSPDM_INTERNAL_DUMP_HEX_OVERRIDE(data, size)
752 : #else
753 : /**
754 : * This function dump raw data with column format.
755 : *
756 : * @param data raw data
757 : * @param size raw data size
758 : **/
759 : void libspdm_internal_dump_hex(const uint8_t *data, size_t size);
760 : #define LIBSPDM_INTERNAL_DUMP_HEX(data, size) libspdm_internal_dump_hex(data, size)
761 : #endif /* LIBSPDM_INTERNAL_DUMP_HEX_OVERRIDE */
762 :
763 : #else /* LIBSPDM_DEBUG_PRINT_ENABLE */
764 : #define LIBSPDM_INTERNAL_DUMP_HEX(data, size)
765 : #define LIBSPDM_INTERNAL_DUMP_HEX_STR(data, size)
766 : #define LIBSPDM_INTERNAL_DUMP_DATA(data, size)
767 : #endif /* LIBSPDM_DEBUG_PRINT_ENABLE */
768 :
769 : /* Required scratch buffer size for libspdm internal usage.
770 : * It may be used to hold the encrypted/decrypted message and/or last sent/received message.
771 : * It may be used to hold the large request/response and intermediate send/receive buffer
772 : * in case of chunking.
773 : *
774 : * If chunking is not supported, it should be at least below.
775 : * +--------------------------+-----------------+-----------------+
776 : * | SENDER_RECEIVER |MAX_SPDM_MSG_SIZE|MAX_SPDM_MSG_SIZE|
777 : * +--------------------------+-----------------+-----------------+
778 : * |<-Snd/Rcv buf for chunk ->|<-last request ->|<-cache request->|
779 : *
780 : *
781 : * If chunking is supported, it should be at least below.
782 : * +---------------+--------------+--------------------------+------------------------------+-----------------+-----------------+
783 : * |SECURE_MESSAGE |LARGE_MESSAGE | SENDER_RECEIVER | LARGE SENDER_RECEIVER |MAX_SPDM_MSG_SIZE|MAX_SPDM_MSG_SIZE|
784 : * +---------------+--------------+--------------------------+------------------------------+-----------------+-----------------+
785 : * |<-Secure msg ->|<-Large msg ->|<-Snd/Rcv buf for chunk ->|<-Snd/Rcv buf for large msg ->|<-last request ->|<-cache request->|
786 : *
787 : *
788 : * The value is configurable based on max_spdm_msg_size.
789 : * The value MAY be changed in different libspdm version.
790 : * It is exposed here, just in case the libspdm consumer wants to configure the setting at build time.
791 : */
792 : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
793 : /* first section */
794 : uint32_t libspdm_get_scratch_buffer_secure_message_offset(void);
795 : uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context);
796 :
797 : /* second section */
798 : uint32_t libspdm_get_scratch_buffer_large_message_offset(libspdm_context_t *spdm_context);
799 : uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context);
800 : #endif
801 :
802 : /* third section */
803 : uint32_t libspdm_get_scratch_buffer_sender_receiver_offset(libspdm_context_t *spdm_context);
804 : uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context);
805 :
806 : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
807 : /* fourth section */
808 : uint32_t libspdm_get_scratch_buffer_large_sender_receiver_offset(libspdm_context_t *spdm_context);
809 : uint32_t libspdm_get_scratch_buffer_large_sender_receiver_capacity(libspdm_context_t *spdm_context);
810 : #endif
811 :
812 : /* fifth section */
813 : uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context);
814 : uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context);
815 :
816 : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
817 : /* sixth section */
818 : uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context);
819 : uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context);
820 : #endif
821 :
822 : /* combination */
823 : uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context);
824 :
825 : /**
826 : * Append a new data buffer to the managed buffer.
827 : *
828 : * @param managed_buffer The managed buffer to be appended.
829 : * @param buffer The address of the data buffer to be appended to the managed buffer.
830 : * @param buffer_size The size in bytes of the data buffer to be appended to the managed buffer.
831 : *
832 : * @retval RETURN_SUCCESS The new data buffer is appended to the managed buffer.
833 : * @retval RETURN_BUFFER_TOO_SMALL The managed buffer is too small to be appended.
834 : **/
835 : libspdm_return_t libspdm_append_managed_buffer(void *managed_buffer,
836 : const void *buffer, size_t buffer_size);
837 :
838 : /**
839 : * Reset the managed buffer.
840 : * The buffer_size is reset to 0.
841 : * The max_buffer_size is unchanged.
842 : * The buffer is not freed.
843 : *
844 : * @param managed_buffer The managed buffer.
845 : **/
846 : void libspdm_reset_managed_buffer(void *managed_buffer);
847 :
848 : /**
849 : * Return the size of managed buffer.
850 : *
851 : * @param managed_buffer The managed buffer.
852 : *
853 : * @return the size of managed buffer.
854 : **/
855 : size_t libspdm_get_managed_buffer_size(void *managed_buffer);
856 :
857 : /**
858 : * Return the address of managed buffer.
859 : *
860 : * @param managed_buffer The managed buffer.
861 : *
862 : * @return the address of managed buffer.
863 : **/
864 : void *libspdm_get_managed_buffer(void *managed_buffer);
865 :
866 : /**
867 : * Init the managed buffer.
868 : *
869 : * @param managed_buffer The managed buffer.
870 : * @param max_buffer_size The maximum size in bytes of the managed buffer.
871 : **/
872 : void libspdm_init_managed_buffer(void *managed_buffer, size_t max_buffer_size);
873 :
874 : /**
875 : * Reset message buffer in SPDM context according to request code.
876 : *
877 : * @param spdm_context A pointer to the SPDM context.
878 : * @param spdm_session_info A pointer to the SPDM session context.
879 : * @param spdm_request The SPDM request code.
880 : */
881 : void libspdm_reset_message_buffer_via_request_code(void *context, void *session_info,
882 : uint8_t request_code);
883 :
884 : /**
885 : * Reset message buffer according to an encapsulated request code. Encapsulated-flow counterpart to
886 : * libspdm_reset_message_buffer_via_request_code.
887 : *
888 : * @param context A pointer to the SPDM context.
889 : * @param session_info A pointer to the SPDM session context.
890 : * @param request_code The encapsulated SPDM request code.
891 : */
892 : void libspdm_reset_message_buffer_via_encap_request_code(void *context, void *session_info,
893 : uint8_t request_code);
894 :
895 : /**
896 : * This function initializes the session info.
897 : *
898 : * @param spdm_context A pointer to the SPDM context.
899 : * @param session_id The SPDM session ID.
900 : **/
901 : void libspdm_session_info_init(libspdm_context_t *spdm_context,
902 : libspdm_session_info_t *session_info,
903 : uint32_t session_id, spdm_version_number_t secured_message_version,
904 : bool use_psk);
905 :
906 : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
907 : /**
908 : * Set the psk_hint to a session info.
909 : *
910 : * @param session_info A pointer to a session info.
911 : * @param psk_hint Indicate the PSK hint.
912 : * @param psk_hint_size The size in bytes of the PSK hint.
913 : */
914 : void libspdm_session_info_set_psk_hint(libspdm_session_info_t *session_info,
915 : const void *psk_hint,
916 : size_t psk_hint_size);
917 : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP */
918 :
919 : /**
920 : * This function returns if a given version is supported based upon the GET_VERSION/VERSION.
921 : *
922 : * @param spdm_context A pointer to the SPDM context.
923 : * @param version The SPDM version.
924 : *
925 : * @retval true the version is supported.
926 : * @retval false the version is not supported.
927 : **/
928 : bool libspdm_is_version_supported(const libspdm_context_t *spdm_context, uint8_t version);
929 :
930 : /**
931 : * This function returns connection version negotiated by GET_VERSION/VERSION.
932 : *
933 : * @param spdm_context A pointer to the SPDM context.
934 : *
935 : * @return the connection version.
936 : **/
937 : uint8_t libspdm_get_connection_version(const libspdm_context_t *spdm_context);
938 :
939 : /**
940 : * This function returns if a capabilities flag is supported in current SPDM connection.
941 : *
942 : * @param spdm_context A pointer to the SPDM context.
943 : * @param is_requester Is the function called from a requester.
944 : * @param requester_capabilities_flag The requester capabilities flag to be checked
945 : * @param responder_capabilities_flag The responder capabilities flag to be checked
946 : *
947 : * @retval true the capabilities flag is supported.
948 : * @retval false the capabilities flag is not supported.
949 : **/
950 : bool libspdm_is_capabilities_flag_supported(const libspdm_context_t *spdm_context,
951 : bool is_requester,
952 : uint32_t requester_capabilities_flag,
953 : uint32_t responder_capabilities_flag);
954 :
955 : /**
956 : * This function returns if a capabilities extended flag is supported in current SPDM connection.
957 : *
958 : * @param spdm_context A pointer to the SPDM context.
959 : * @param is_requester Is the function called from a requester.
960 : * @param requester_capabilities_ext_flag The requester capabilities extended flag to be checked
961 : * @param responder_capabilities_ext_flag The responder capabilities extended flag to be checked
962 : *
963 : * @retval true the capabilities extended flag is supported.
964 : * @retval false the capabilities extended flag is not supported.
965 : **/
966 : bool libspdm_is_capabilities_ext_flag_supported(const libspdm_context_t *spdm_context,
967 : bool is_requester,
968 : uint16_t requester_capabilities_ext_flag,
969 : uint16_t responder_capabilities_ext_flag);
970 :
971 : /**
972 : * Checks the negotiated SPDM version and endpoint capabilities to determine if encapsulated
973 : * messages are supported or not.
974 : *
975 : * @param spdm_context A pointer to the SPDM context.
976 : *
977 : * @retval true Both endpoints support encapsulated messages.
978 : * @retval false At least one endpoint does not support encapsulated messages.
979 : **/
980 : bool libspdm_is_encap_supported(const libspdm_context_t *spdm_context);
981 :
982 : /**
983 : * This function generates the certificate chain hash.
984 : *
985 : * @param spdm_context A pointer to the SPDM context.
986 : * @param slot_id The slot index of the certificate chain.
987 : * @param signature The buffer to store the certificate chain hash.
988 : *
989 : * @retval true certificate chain hash is generated.
990 : * @retval false certificate chain hash is not generated.
991 : **/
992 : bool libspdm_generate_cert_chain_hash(libspdm_context_t *spdm_context,
993 : size_t slot_id, uint8_t *hash);
994 :
995 : /**
996 : * This function generates the public key hash.
997 : *
998 : * @param spdm_context A pointer to the SPDM context.
999 : * @param hash The buffer to store the public key hash.
1000 : *
1001 : * @retval true public key hash is generated.
1002 : * @retval false public key hash is not generated.
1003 : **/
1004 : bool libspdm_generate_public_key_hash(libspdm_context_t *spdm_context,
1005 : uint8_t *hash);
1006 :
1007 : /**
1008 : * This function verifies the integrity of peer certificate chain buffer including
1009 : * spdm_cert_chain_t header.
1010 : *
1011 : * @param spdm_context A pointer to the SPDM context.
1012 : * @param cert_chain_buffer Certificate chain buffer including spdm_cert_chain_t header.
1013 : * @param cert_chain_buffer_size size in bytes of the certificate chain buffer.
1014 : *
1015 : * @retval true Peer certificate chain buffer integrity verification passed.
1016 : * @retval false Peer certificate chain buffer integrity verification failed.
1017 : **/
1018 : bool libspdm_verify_peer_cert_chain_buffer_integrity(libspdm_context_t *spdm_context,
1019 : const void *cert_chain_buffer,
1020 : size_t cert_chain_buffer_size);
1021 :
1022 : /**
1023 : * This function verifies peer certificate chain authority.
1024 : *
1025 : * @param spdm_context A pointer to the SPDM context.
1026 : * @param cert_chain_buffer Certificate chain buffer including spdm_cert_chain_t header.
1027 : * @param cert_chain_buffer_size size in bytes of the certificate chain buffer.
1028 : * @param trust_anchor A buffer to hold the trust_anchor which is used to validate the peer certificate, if not NULL.
1029 : * @param trust_anchor_size A buffer to hold the trust_anchor_size, if not NULL.
1030 : *
1031 : * @retval true Peer certificate chain buffer authority verification passed.
1032 : * Or there is no root_cert in local_context.
1033 : * @retval false Peer certificate chain buffer authority verification failed.
1034 : **/
1035 : bool libspdm_verify_peer_cert_chain_buffer_authority(libspdm_context_t *spdm_context,
1036 : const void *cert_chain_buffer,
1037 : size_t cert_chain_buffer_size,
1038 : const void **trust_anchor,
1039 : size_t *trust_anchor_size);
1040 : /**
1041 : * This function generates the challenge signature based upon m1m2 for authentication.
1042 : *
1043 : * @param spdm_context A pointer to the SPDM context.
1044 : * @param is_requester Indicate of the signature generation for a requester or a responder.
1045 : * @param signature The buffer to store the challenge signature.
1046 : *
1047 : * @retval true challenge signature is generated.
1048 : * @retval false challenge signature is not generated.
1049 : **/
1050 : bool libspdm_generate_challenge_auth_signature(libspdm_context_t *spdm_context,
1051 : bool is_requester,
1052 : uint8_t slot_id,
1053 : uint8_t *signature);
1054 :
1055 : /**
1056 : * This function verifies the certificate chain hash.
1057 : *
1058 : * @param spdm_context A pointer to the SPDM context.
1059 : * @param certificate_chain_hash The certificate chain hash data buffer.
1060 : * @param certificate_chain_hash_size size in bytes of the certificate chain hash data buffer.
1061 : *
1062 : * @retval true hash verification pass.
1063 : * @retval false hash verification fail.
1064 : **/
1065 : bool libspdm_verify_certificate_chain_hash(libspdm_context_t *spdm_context,
1066 : uint8_t slot_id,
1067 : const void *certificate_chain_hash,
1068 : size_t certificate_chain_hash_size);
1069 :
1070 : /**
1071 : * This function verifies the public key hash.
1072 : *
1073 : * @param spdm_context A pointer to the SPDM context.
1074 : * @param public_key_hash The public key hash data buffer.
1075 : * @param public_key_hash_size size in bytes of the public key hash data buffer.
1076 : *
1077 : * @retval true hash verification pass.
1078 : * @retval false hash verification fail.
1079 : **/
1080 : bool libspdm_verify_public_key_hash(libspdm_context_t *spdm_context,
1081 : const void *public_key_hash,
1082 : size_t public_key_hash_size);
1083 :
1084 : /**
1085 : * This function verifies the challenge signature based upon m1m2.
1086 : *
1087 : * @param spdm_context A pointer to the SPDM context.
1088 : * @param is_requester Indicate of the signature verification for a requester or a responder.
1089 : * @param sign_data The signature data buffer.
1090 : * @param sign_data_size size in bytes of the signature data buffer.
1091 : *
1092 : * @retval true signature verification pass.
1093 : * @retval false signature verification fail.
1094 : **/
1095 : bool libspdm_verify_challenge_auth_signature(libspdm_context_t *spdm_context,
1096 : bool is_requester,
1097 : uint8_t slot_id,
1098 : const void *sign_data,
1099 : size_t sign_data_size);
1100 :
1101 : /**
1102 : * This function calculate the measurement summary hash size.
1103 : *
1104 : * @param spdm_context A pointer to the SPDM context.
1105 : * @param is_requester Is the function called from a requester.
1106 : * @param measurement_summary_hash_type The type of the measurement summary hash.
1107 : *
1108 : * @return 0 measurement summary hash type is invalid, NO_MEAS hash type or no MEAS capabilities.
1109 : * @return measurement summary hash size according to type.
1110 : **/
1111 : uint32_t libspdm_get_measurement_summary_hash_size(libspdm_context_t *spdm_context,
1112 : bool is_requester,
1113 : uint8_t measurement_summary_hash_type);
1114 :
1115 : /**
1116 : * This function generates the endpoint info signature based upon il1il2 for authentication.
1117 : *
1118 : * @param spdm_context A pointer to the SPDM context.
1119 : * @param session_info A pointer to the SPDM session context.
1120 : * @param is_requester Indicate of the signature generation for a requester or a responder.
1121 : * @param signature The buffer to store the endpoint info signature.
1122 : *
1123 : * @retval true challenge signature is generated.
1124 : * @retval false challenge signature is not generated.
1125 : **/
1126 : bool libspdm_generate_endpoint_info_signature(libspdm_context_t *spdm_context,
1127 : libspdm_session_info_t *session_info,
1128 : bool is_requester,
1129 : uint8_t slot_id,
1130 : uint8_t *signature);
1131 :
1132 : /**
1133 : * This function verifies the challenge signature based upon m1m2.
1134 : *
1135 : * @param spdm_context A pointer to the SPDM context.
1136 : * @param session_info A pointer to the SPDM session context.
1137 : * @param is_requester Indicate of the signature verification for a requester or a responder.
1138 : * @param sign_data The signature data buffer.
1139 : * @param sign_data_size size in bytes of the signature data buffer.
1140 : *
1141 : * @retval true signature verification pass.
1142 : * @retval false signature verification fail.
1143 : **/
1144 : bool libspdm_verify_endpoint_info_signature(libspdm_context_t *spdm_context,
1145 : libspdm_session_info_t *session_info,
1146 : bool is_requester,
1147 : uint8_t slot_id,
1148 : const void *sign_data,
1149 : size_t sign_data_size);
1150 :
1151 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1152 : /*
1153 : * This function calculates l1l2.
1154 : * If session_info is NULL, this function will use M cache of SPDM context,
1155 : * else will use M cache of SPDM session context.
1156 : *
1157 : * @param spdm_context A pointer to the SPDM context.
1158 : * @param session_info A pointer to the SPDM session context.
1159 : * @param l1l2 The buffer to store the l1l2.
1160 : *
1161 : * @retval RETURN_SUCCESS l1l2 is calculated.
1162 : */
1163 : bool libspdm_calculate_l1l2(libspdm_context_t *spdm_context,
1164 : void *session_info,
1165 : libspdm_l1l2_managed_buffer_t *l1l2);
1166 : #else
1167 : /*
1168 : * This function calculates l1l2 hash.
1169 : * If session_info is NULL, this function will use M cache of SPDM context,
1170 : * else will use M cache of SPDM session context.
1171 : *
1172 : * @param spdm_context A pointer to the SPDM context.
1173 : * @param session_info A pointer to the SPDM session context.
1174 : * @param l1l2_hash_size size in bytes of the l1l2 hash
1175 : * @param l1l2_hash The buffer to store the l1l2 hash
1176 : *
1177 : * @retval RETURN_SUCCESS l1l2 is calculated.
1178 : */
1179 : bool libspdm_calculate_l1l2_hash(libspdm_context_t *spdm_context,
1180 : void *session_info,
1181 : size_t *l1l2_hash_size, void *l1l2_hash);
1182 : #endif /* LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT */
1183 :
1184 : /**
1185 : * Get element from multi element opaque data by element id and element index
1186 : *
1187 : * @param[in] spdm_context A pointer to the SPDM context.
1188 : * @param[in] data_in_size Size of multi element opaque data.
1189 : * @param[in] data_in A pointer to the multi element opaque data.
1190 : * @param[in] element_id Element id.
1191 : * @param[in] element_index Element index, start from 0.
1192 : * It is used to get the nth element with the same element id.
1193 : * @param[out] total_matched_element_cnt Pointer to store total matched element count with the same element id.
1194 : * @param[out] get_element_ptr Pointer to store found element.
1195 : * @param[out] get_element_len Pointer to length of found element.
1196 : *
1197 : * @retval true Get element successfully
1198 : * @retval false Get element failed
1199 : **/
1200 : bool libspdm_get_element_from_opaque_data_with_element_id (libspdm_context_t *spdm_context,
1201 : size_t data_in_size, const void *data_in,
1202 : uint8_t element_id, uint8_t element_index,
1203 : uint8_t *total_matched_element_cnt,
1204 : const void **get_element_ptr, size_t *get_element_len);
1205 :
1206 : /**
1207 : * Get secured message opaque data element from multi element opaque data by sm data id
1208 : *
1209 : * This function should be called in
1210 : * libspdm_process_opaque_data_supported_version_data/libspdm_process_opaque_data_version_selection_data.
1211 : *
1212 : * @param[in] spdm_context A pointer to the SPDM context.
1213 : * @param[in] data_in_size Size of multi element opaque data.
1214 : * @param[in] data_in A pointer to the multi element opaque data.
1215 : * @param[in] sm_data_id ID for the Secured Message data type.
1216 : * @param[out] get_element_ptr Pointer to store found element.
1217 : * @param[out] get_element_len Pointer to length of found element.
1218 : *
1219 : * @retval true Get element successfully
1220 : * @retval false Get element failed
1221 : **/
1222 : bool libspdm_get_sm_data_element_from_opaque_data (libspdm_context_t *spdm_context,
1223 : size_t data_in_size, const void *data_in,
1224 : uint8_t sm_data_id,
1225 : const void **get_element_ptr, size_t *get_element_len);
1226 :
1227 : /**
1228 : * Process opaque data version selection.
1229 : *
1230 : * This function should be called in KEY_EXCHANGE/PSK_EXCHANGE response parsing in requester.
1231 : *
1232 : * @param data_in_size Size in bytes of the data_in.
1233 : * @param data_in A pointer to the buffer to store the opaque data version selection.
1234 : **/
1235 : libspdm_return_t libspdm_process_opaque_data_version_selection_data(
1236 : libspdm_context_t *spdm_context, size_t data_in_size, void *data_in,
1237 : spdm_version_number_t *secured_message_version);
1238 :
1239 : /**
1240 : * Process general opaque data check
1241 : *
1242 : * @param data_in_size size in bytes of the data_in.
1243 : * @param data_in A pointer to the buffer to store the opaque data version selection.
1244 : *
1245 : * @retval true check opaque data successfully
1246 : * @retval false check opaque data failed
1247 : **/
1248 : bool libspdm_process_general_opaque_data_check(libspdm_context_t *spdm_context,
1249 : size_t data_in_size,
1250 : const void *data_in);
1251 :
1252 : /**
1253 : * Return the size in bytes of opaque data supported version.
1254 : *
1255 : * This function should be called in libspdm_process_opaque_data_supported_version_data.
1256 : *
1257 : * @param version_count Secure version count.
1258 : *
1259 : * @return The size in bytes of opaque data supported version.
1260 : **/
1261 : size_t libspdm_get_untrusted_opaque_data_supported_version_data_size(
1262 : libspdm_context_t *spdm_context, uint8_t version_count);
1263 :
1264 : /**
1265 : * Return the size in bytes of opaque data supported version.
1266 : *
1267 : * This function should be called in KEY_EXCHANGE/PSK_EXCHANGE request generation.
1268 : *
1269 : * @return the size in bytes of opaque data supported version.
1270 : **/
1271 : size_t libspdm_get_opaque_data_supported_version_data_size(libspdm_context_t *spdm_context);
1272 :
1273 : /**
1274 : * Return the size in bytes of opaque data version selection.
1275 : *
1276 : * This function should be called in KEY_EXCHANGE/PSK_EXCHANGE response generation.
1277 : *
1278 : * @return the size in bytes of opaque data version selection.
1279 : **/
1280 : size_t libspdm_get_opaque_data_version_selection_data_size(const libspdm_context_t *spdm_context);
1281 :
1282 : /**
1283 : * Return the SPDMversion field of the version number struct.
1284 : *
1285 : * @param ver Spdm version number struct.
1286 : *
1287 : * @return the SPDMversion of the version number struct.
1288 : **/
1289 : uint8_t libspdm_get_version_from_version_number(spdm_version_number_t ver);
1290 :
1291 : /**
1292 : * Sort SPDMversion in descending order.
1293 : *
1294 : * @param spdm_context A pointer to the SPDM context.
1295 : * @param ver_set A pointer to the version set.
1296 : * @param ver_num Version number.
1297 : */
1298 : void libspdm_version_number_sort(spdm_version_number_t *ver_set, size_t ver_num);
1299 :
1300 : /**
1301 : * Negotiate SPDMversion for connection.
1302 : * ver_set is the local version set of requester, res_ver_set is the version set of responder.
1303 : *
1304 : * @param common_version A pointer to store the common version.
1305 : * @param req_ver_set A pointer to the requester version set.
1306 : * @param req_ver_num Version number of requester.
1307 : * @param res_ver_set A pointer to the responder version set.
1308 : * @param res_ver_num Version number of responder.
1309 : *
1310 : * @retval true Negotiation successfully, connect version be saved to common_version.
1311 : * @retval false Negotiation failed.
1312 : */
1313 : bool libspdm_negotiate_connection_version(spdm_version_number_t *common_version,
1314 : spdm_version_number_t *req_ver_set,
1315 : size_t req_ver_num,
1316 : const spdm_version_number_t *res_ver_set,
1317 : size_t res_ver_num);
1318 :
1319 : /**
1320 : * Acquire a device sender buffer for transport layer message.
1321 : *
1322 : * @param context A pointer to the SPDM context.
1323 : * @param max_msg_size size in bytes of the maximum size of sender buffer.
1324 : * @param msg_buf_ptr A pointer to a sender buffer.
1325 : *
1326 : * @retval RETURN_SUCCESS The sender buffer is acquired.
1327 : **/
1328 : libspdm_return_t libspdm_acquire_sender_buffer (
1329 : libspdm_context_t *spdm_context, size_t *max_msg_size, void **msg_buf_ptr);
1330 :
1331 : /**
1332 : * Release a device sender buffer for transport layer message.
1333 : *
1334 : * @param context A pointer to the SPDM context.
1335 : *
1336 : * @retval RETURN_SUCCESS The sender buffer is Released.
1337 : **/
1338 : void libspdm_release_sender_buffer (libspdm_context_t *spdm_context);
1339 :
1340 : /**
1341 : * Get the sender buffer.
1342 : *
1343 : * @param context A pointer to the SPDM context.
1344 : * @param sender_buffer Buffer address of the sender buffer.
1345 : * @param sender_buffer_size Size of the sender buffer.
1346 : *
1347 : **/
1348 : void libspdm_get_sender_buffer (
1349 : libspdm_context_t *spdm_context,
1350 : void **sender_buffer,
1351 : size_t *sender_buffer_size);
1352 :
1353 : /**
1354 : * Acquire a device receiver buffer for transport layer message.
1355 : *
1356 : * @param context A pointer to the SPDM context.
1357 : * @param max_msg_size size in bytes of the maximum size of receiver buffer.
1358 : * @param msg_buf_pt A pointer to a receiver buffer.
1359 : *
1360 : * @retval RETURN_SUCCESS The receiver buffer is acquired.
1361 : **/
1362 : libspdm_return_t libspdm_acquire_receiver_buffer (
1363 : libspdm_context_t *spdm_context, size_t *max_msg_size, void **msg_buf_ptr);
1364 :
1365 : /**
1366 : * Release a device receiver buffer for transport layer message.
1367 : *
1368 : * @param context A pointer to the SPDM context.
1369 : *
1370 : * @retval RETURN_SUCCESS The receiver buffer is Released.
1371 : **/
1372 : void libspdm_release_receiver_buffer (libspdm_context_t *spdm_context);
1373 :
1374 : /**
1375 : * Get the receiver buffer.
1376 : *
1377 : * @param context A pointer to the SPDM context.
1378 : * @param receiver_buffer Buffer address of the receiver buffer.
1379 : * @param receiver_buffer_size Size of the receiver buffer.
1380 : *
1381 : **/
1382 : void libspdm_get_receiver_buffer (
1383 : libspdm_context_t *spdm_context,
1384 : void **receiver_buffer,
1385 : size_t *receiver_buffer_size);
1386 :
1387 : /**
1388 : * Get the certificate slot mask
1389 : *
1390 : * @param[in] context A pointer to the SPDM context.
1391 : *
1392 : * @return slot_mask get slot mask
1393 : **/
1394 : uint8_t libspdm_get_cert_slot_mask (libspdm_context_t *spdm_context);
1395 :
1396 : /**
1397 : * Get the certificate slot count
1398 : *
1399 : * @param[in] context A pointer to the SPDM context.
1400 : *
1401 : * @return slot_count get slot count
1402 : **/
1403 : uint8_t libspdm_get_cert_slot_count(libspdm_context_t *spdm_context);
1404 :
1405 : #if LIBSPDM_ENABLE_MSG_LOG
1406 : void libspdm_append_msg_log(libspdm_context_t *spdm_context, void *message, size_t message_size);
1407 : #endif
1408 :
1409 : /**
1410 : * Reset message A cache in SPDM context.
1411 : *
1412 : * @param spdm_context A pointer to the SPDM context.
1413 : **/
1414 : void libspdm_reset_message_a(libspdm_context_t *spdm_context);
1415 :
1416 : /**
1417 : * Reset message D cache in SPDM context.
1418 : *
1419 : * @param spdm_context A pointer to the SPDM context.
1420 : * @param spdm_session_info A pointer to the SPDM session context.
1421 : **/
1422 : void libspdm_reset_message_d(libspdm_context_t *spdm_context);
1423 :
1424 : /**
1425 : * Reset message B cache in SPDM context.
1426 : *
1427 : * @param spdm_context A pointer to the SPDM context.
1428 : **/
1429 : void libspdm_reset_message_b(libspdm_context_t *spdm_context);
1430 :
1431 : /**
1432 : * Reset message C cache in SPDM context.
1433 : *
1434 : * @param spdm_context A pointer to the SPDM context.
1435 : **/
1436 : void libspdm_reset_message_c(libspdm_context_t *spdm_context);
1437 :
1438 : /**
1439 : * Reset message MutB cache in SPDM context.
1440 : *
1441 : * @param spdm_context A pointer to the SPDM context.
1442 : **/
1443 : void libspdm_reset_message_mut_b(libspdm_context_t *spdm_context);
1444 :
1445 : /**
1446 : * Reset message MutC cache in SPDM context.
1447 : *
1448 : * @param spdm_context A pointer to the SPDM context.
1449 : **/
1450 : void libspdm_reset_message_mut_c(libspdm_context_t *spdm_context);
1451 :
1452 : /**
1453 : * Reset message M cache in SPDM context.
1454 : * If session_info is NULL, this function will use M cache of SPDM context,
1455 : * else will use M cache of SPDM session context.
1456 : *
1457 : * @param spdm_context A pointer to the SPDM context.
1458 : * @param session_info A pointer to the SPDM session context.
1459 : **/
1460 : void libspdm_reset_message_m(libspdm_context_t *spdm_context, void *session_info);
1461 :
1462 : /**
1463 : * Reset message K cache in SPDM context.
1464 : *
1465 : * @param spdm_context A pointer to the SPDM context.
1466 : * @param spdm_session_info A pointer to the SPDM session context.
1467 : **/
1468 : void libspdm_reset_message_k(libspdm_context_t *spdm_context, void *spdm_session_info);
1469 :
1470 : /**
1471 : * Reset message EncapD cache in SPDM context.
1472 : *
1473 : * @param spdm_session_info A pointer to the SPDM session context.
1474 : **/
1475 : void libspdm_reset_message_encap_d(void *spdm_session_info);
1476 :
1477 : /**
1478 : * Reset message F cache in SPDM context.
1479 : *
1480 : * @param spdm_context A pointer to the SPDM context.
1481 : * @param spdm_session_info A pointer to the SPDM session context.
1482 : **/
1483 : void libspdm_reset_message_f(libspdm_context_t *spdm_context, void *spdm_session_info);
1484 :
1485 : /**
1486 : * Reset message E cache in SPDM context.
1487 : * If session_info is NULL, this function will use E cache of SPDM context,
1488 : * else will use E cache of SPDM session context.
1489 : *
1490 : * @param spdm_context A pointer to the SPDM context.
1491 : * @param spdm_session_info A pointer to the SPDM session context.
1492 : **/
1493 : void libspdm_reset_message_e(libspdm_context_t *spdm_context, void *session_info);
1494 :
1495 : /**
1496 : * Reset message encap E cache in SPDM context.
1497 : * If session_info is NULL, this function will use encap E cache of SPDM context,
1498 : * else will use encap E cache of SPDM session context.
1499 : *
1500 : * @param spdm_context A pointer to the SPDM context.
1501 : * @param spdm_session_info A pointer to the SPDM session context.
1502 : **/
1503 : void libspdm_reset_message_encap_e(libspdm_context_t *spdm_context, void *session_info);
1504 :
1505 : /**
1506 : * Append message A cache in SPDM context.
1507 : *
1508 : * @param spdm_context A pointer to the SPDM context.
1509 : * @param message Message buffer.
1510 : * @param message_size Size in bytes of message buffer.
1511 : *
1512 : * @retval RETURN_SUCCESS message is appended.
1513 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1514 : **/
1515 : libspdm_return_t libspdm_append_message_a(libspdm_context_t *spdm_context, const void *message,
1516 : size_t message_size);
1517 :
1518 : /**
1519 : * Append message D cache in SPDM context.
1520 : *
1521 : * @param spdm_context A pointer to the SPDM context.
1522 : * @param message Message buffer.
1523 : * @param message_size Size in bytes of message buffer.
1524 : *
1525 : * @retval RETURN_SUCCESS message is appended.
1526 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1527 : **/
1528 : libspdm_return_t libspdm_append_message_d(libspdm_context_t *spdm_context, const void *message,
1529 : size_t message_size);
1530 :
1531 : /**
1532 : * Append message B cache in SPDM context.
1533 : *
1534 : * @param spdm_context A pointer to the SPDM context.
1535 : * @param message Message buffer.
1536 : * @param message_size Size in bytes of message buffer.
1537 : *
1538 : * @retval RETURN_SUCCESS message is appended.
1539 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1540 : **/
1541 : libspdm_return_t libspdm_append_message_b(libspdm_context_t *spdm_context, const void *message,
1542 : size_t message_size);
1543 :
1544 : /**
1545 : * Append message C cache in SPDM context.
1546 : *
1547 : * @param spdm_context A pointer to the SPDM context.
1548 : * @param message Message buffer.
1549 : * @param message_size Size in bytes of message buffer.
1550 : *
1551 : * @retval RETURN_SUCCESS message is appended.
1552 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1553 : **/
1554 : libspdm_return_t libspdm_append_message_c(libspdm_context_t *spdm_context, const void *message,
1555 : size_t message_size);
1556 :
1557 : /**
1558 : * Append message MutB cache in SPDM context.
1559 : *
1560 : * @param spdm_context A pointer to the SPDM context.
1561 : * @param message Message buffer.
1562 : * @param message_size Size in bytes of message buffer.
1563 : *
1564 : * @retval RETURN_SUCCESS message is appended.
1565 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1566 : **/
1567 : libspdm_return_t libspdm_append_message_mut_b(libspdm_context_t *spdm_context, const void *message,
1568 : size_t message_size);
1569 :
1570 : /**
1571 : * Append message MutC cache in SPDM context.
1572 : *
1573 : * @param spdm_context A pointer to the SPDM context.
1574 : * @param message Message buffer.
1575 : * @param message_size Size in bytes of message buffer.
1576 : *
1577 : * @retval RETURN_SUCCESS message is appended.
1578 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1579 : **/
1580 : libspdm_return_t libspdm_append_message_mut_c(libspdm_context_t *spdm_context, const void *message,
1581 : size_t message_size);
1582 :
1583 : /**
1584 : * Append message M cache in SPDM context.
1585 : * If session_info is NULL, this function will use M cache of SPDM context,
1586 : * else will use M cache of SPDM session context.
1587 : *
1588 : * @param spdm_context A pointer to the SPDM context.
1589 : * @param session_info A pointer to the SPDM session context.
1590 : * @param message Message buffer.
1591 : * @param message_size Size in bytes of message buffer.
1592 : *
1593 : * @retval RETURN_SUCCESS message is appended.
1594 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1595 : **/
1596 : libspdm_return_t libspdm_append_message_m(libspdm_context_t *spdm_context,
1597 : void *session_info,
1598 : const void *message, size_t message_size);
1599 :
1600 : /**
1601 : * Append message K cache in SPDM context.
1602 : *
1603 : * @param spdm_context A pointer to the SPDM context.
1604 : * @param spdm_session_info A pointer to the SPDM session context.
1605 : * @param is_requester Indicate of the key generation for a requester or a responder.
1606 : * @param message Message buffer.
1607 : * @param message_size Size in bytes of message buffer.
1608 : *
1609 : * @retval RETURN_SUCCESS message is appended.
1610 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1611 : **/
1612 : libspdm_return_t libspdm_append_message_k(libspdm_context_t *spdm_context,
1613 : void *spdm_session_info,
1614 : bool is_requester, const void *message,
1615 : size_t message_size);
1616 :
1617 : /**
1618 : * Append message EncapD cache in SPDM context.
1619 : *
1620 : * @param spdm_session_info A pointer to the SPDM session context.
1621 : * @param message Message buffer.
1622 : * @param message_size Size in bytes of message buffer.
1623 : *
1624 : * @retval RETURN_SUCCESS message is appended.
1625 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1626 : **/
1627 : libspdm_return_t libspdm_append_message_encap_d(void *spdm_session_info,
1628 : const void *message,
1629 : size_t message_size);
1630 :
1631 : /**
1632 : * Append message F cache in SPDM context.
1633 : *
1634 : * @param spdm_context A pointer to the SPDM context.
1635 : * @param spdm_session_info A pointer to the SPDM session context.
1636 : * @param is_requester Indicate of the key generation for a requester or a responder.
1637 : * @param message Message buffer.
1638 : * @param message_size Size in bytes of message buffer.
1639 : *
1640 : * @retval RETURN_SUCCESS message is appended.
1641 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1642 : **/
1643 : libspdm_return_t libspdm_append_message_f(libspdm_context_t *spdm_context,
1644 : void *spdm_session_info,
1645 : bool is_requester, const void *message,
1646 : size_t message_size);
1647 :
1648 : /**
1649 : * Append message E cache in SPDM context.
1650 : * If session_info is NULL, this function will use E cache of SPDM context,
1651 : * else will use E cache of SPDM session context.
1652 : *
1653 : * @param spdm_context A pointer to the SPDM context.
1654 : * @param session_info A pointer to the SPDM session context.
1655 : * @param message message buffer.
1656 : * @param message_size size in bytes of message buffer.
1657 : *
1658 : * @retval RETURN_SUCCESS message is appended.
1659 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1660 : **/
1661 : libspdm_return_t libspdm_append_message_e(libspdm_context_t *spdm_context, void *session_info,
1662 : const void *message, size_t message_size);
1663 :
1664 : /**
1665 : * Append message encap E cache in SPDM context.
1666 : * If session_info is NULL, this function will use encap E cache of SPDM context,
1667 : * else will use encap E cache of SPDM session context.
1668 : *
1669 : * @param spdm_context A pointer to the SPDM context.
1670 : * @param session_info A pointer to the SPDM session context.
1671 : * @param message message buffer.
1672 : * @param message_size size in bytes of message buffer.
1673 : *
1674 : * @retval RETURN_SUCCESS message is appended.
1675 : * @retval RETURN_OUT_OF_RESOURCES message is not appended because the internal cache is full.
1676 : **/
1677 : libspdm_return_t libspdm_append_message_encap_e(libspdm_context_t *spdm_context, void *session_info,
1678 : const void *message, size_t message_size);
1679 :
1680 : /**
1681 : * This function generates a session ID by concatenating req_session_id and rsp_session_id.
1682 : *
1683 : * @param[in] req_session_id
1684 : * @param[in] rsp_session_id
1685 : *
1686 : * @return Session ID.
1687 : **/
1688 : uint32_t libspdm_generate_session_id(uint16_t req_session_id, uint16_t rsp_session_id);
1689 :
1690 : /**
1691 : * This function assigns a new session ID.
1692 : *
1693 : * @param spdm_context A pointer to the SPDM context.
1694 : * @param session_id The SPDM session ID.
1695 : *
1696 : * @return session info associated with this new session ID.
1697 : **/
1698 : libspdm_session_info_t *libspdm_assign_session_id(libspdm_context_t *spdm_context,
1699 : uint32_t session_id,
1700 : spdm_version_number_t secured_message_version,
1701 : bool use_psk);
1702 :
1703 : /**
1704 : * This function frees a session ID.
1705 : *
1706 : * @param spdm_context A pointer to the SPDM context.
1707 : * @param session_id The SPDM session ID.
1708 : **/
1709 : void libspdm_free_session_id(libspdm_context_t *spdm_context, uint32_t session_id);
1710 :
1711 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1712 : /*
1713 : * This function calculates current TH data with message A and message K.
1714 : *
1715 : * @param spdm_context A pointer to the SPDM context.
1716 : * @param session_info The SPDM session ID.
1717 : * @param cert_chain_buffer Certificate chain buffer with spdm_cert_chain_t header.
1718 : * @param cert_chain_buffer_size Size in bytes of the certificate chain buffer.
1719 : * @param th_data_buffer_size Size in bytes of the th_data_buffer
1720 : * @param th_data_buffer The buffer to store the th_data_buffer
1721 : *
1722 : * @retval RETURN_SUCCESS current TH data is calculated.
1723 : */
1724 : bool libspdm_calculate_th_for_exchange(
1725 : libspdm_context_t *spdm_context, void *spdm_session_info,
1726 : const uint8_t *cert_chain_buffer, size_t cert_chain_buffer_size,
1727 : libspdm_th_managed_buffer_t *th_curr);
1728 : #else
1729 : /*
1730 : * This function calculates current TH hash with message A and message K.
1731 : *
1732 : * @param spdm_context A pointer to the SPDM context.
1733 : * @param session_info The SPDM session ID.
1734 : * @param th_hash_buffer_size Size in bytes of the th_hash_buffer
1735 : * @param th_hash_buffer The buffer to store the th_hash_buffer
1736 : *
1737 : * @retval RETURN_SUCCESS current TH hash is calculated.
1738 : */
1739 : bool libspdm_calculate_th_hash_for_exchange(
1740 : libspdm_context_t *spdm_context, void *spdm_session_info,
1741 : size_t *th_hash_buffer_size, void *th_hash_buffer);
1742 :
1743 : /*
1744 : * This function calculates current TH hmac with message A and message K, with response finished_key.
1745 : *
1746 : * @param spdm_context A pointer to the SPDM context.
1747 : * @param session_info The SPDM session ID.
1748 : * @param th_hmac_buffer_size Size in bytes of the th_hmac_buffer
1749 : * @param th_hmac_buffer The buffer to store the th_hmac_buffer
1750 : *
1751 : * @retval RETURN_SUCCESS current TH hmac is calculated.
1752 : */
1753 : bool libspdm_calculate_th_hmac_for_exchange_rsp(
1754 : libspdm_context_t *spdm_context, void *spdm_session_info,
1755 : size_t *th_hmac_buffer_size, void *th_hmac_buffer);
1756 : #endif
1757 :
1758 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1759 : /*
1760 : * This function calculates current TH data with message A, message K and message F.
1761 : *
1762 : * @param spdm_context A pointer to the SPDM context.
1763 : * @param session_info The SPDM session ID.
1764 : * @param cert_chain_buffer Certificate chain buffer with spdm_cert_chain_t header.
1765 : * @param cert_chain_buffer_size Size in bytes of the certificate chain buffer.
1766 : * @param mut_cert_chain_buffer Certificate chain buffer with spdm_cert_chain_t header in mutual authentication.
1767 : * @param mut_cert_chain_buffer_size Size in bytes of the certificate chain buffer in mutual authentication.
1768 : * @param th_data_buffer_size Size in bytes of the th_data_buffer.
1769 : * @param th_data_buffer The buffer to store the th_data_buffer
1770 : *
1771 : * @retval RETURN_SUCCESS current TH data is calculated.
1772 : */
1773 : bool libspdm_calculate_th_for_finish(libspdm_context_t *spdm_context,
1774 : void *spdm_session_info,
1775 : const uint8_t *cert_chain_buffer,
1776 : size_t cert_chain_buffer_size,
1777 : const uint8_t *mut_cert_chain_buffer,
1778 : size_t mut_cert_chain_buffer_size,
1779 : libspdm_th_managed_buffer_t *th_curr);
1780 : #else
1781 : /*
1782 : * This function calculates current TH hash with message A, message K and message F.
1783 : *
1784 : * @param spdm_context A pointer to the SPDM context.
1785 : * @param session_info The SPDM session ID.
1786 : * @param th_hash_buffer_size Size in bytes of the th_hash_buffer
1787 : * @param th_hash_buffer The buffer to store the th_hash_buffer
1788 : *
1789 : * @retval RETURN_SUCCESS current TH hash is calculated.
1790 : */
1791 : bool libspdm_calculate_th_hash_for_finish(libspdm_context_t *spdm_context,
1792 : void *spdm_session_info,
1793 : size_t *th_hash_buffer_size,
1794 : void *th_hash_buffer);
1795 :
1796 : /*
1797 : * This function calculates current TH hmac with message A, message K and message F, with response finished_key.
1798 : *
1799 : * @param spdm_context A pointer to the SPDM context.
1800 : * @param session_info The SPDM session ID.
1801 : * @param th_hmac_buffer_size Size in bytes of the th_hmac_buffer
1802 : * @param th_hmac_buffer The buffer to store the th_hmac_buffer
1803 : *
1804 : * @retval RETURN_SUCCESS current TH hmac is calculated.
1805 : */
1806 : bool libspdm_calculate_th_hmac_for_finish_rsp(libspdm_context_t *spdm_context,
1807 : void *spdm_session_info,
1808 : size_t *th_hmac_buffer_size,
1809 : void *th_hmac_buffer);
1810 :
1811 : /*
1812 : * This function calculates current TH hmac with message A, message K and message F, with request finished_key.
1813 : *
1814 : * @param spdm_context A pointer to the SPDM context.
1815 : * @param session_info The SPDM session ID.
1816 : * @param th_hmac_buffer_size Size in bytes of the th_hmac_buffer
1817 : * @param th_hmac_buffer The buffer to store the th_hmac_buffer
1818 : *
1819 : * @retval RETURN_SUCCESS current TH hmac is calculated.
1820 : */
1821 : bool libspdm_calculate_th_hmac_for_finish_req(libspdm_context_t *spdm_context,
1822 : void *spdm_session_info,
1823 : size_t *th_hmac_buffer_size,
1824 : void *th_hmac_buffer);
1825 : #endif
1826 :
1827 : /*
1828 : * This function calculates th1 hash.
1829 : *
1830 : * @param spdm_context A pointer to the SPDM context.
1831 : * @param session_info The SPDM session ID.
1832 : * @param is_requester Indicate of the key generation for a requester or a responder.
1833 : * @param th1_hash_data Th1 hash.
1834 : *
1835 : * @retval RETURN_SUCCESS th1 hash is calculated.
1836 : */
1837 : bool libspdm_calculate_th1_hash(libspdm_context_t *spdm_context,
1838 : void *spdm_session_info,
1839 : bool is_requester,
1840 : uint8_t *th1_hash_data);
1841 :
1842 : /*
1843 : * This function calculates th2 hash.
1844 : *
1845 : * @param spdm_context A pointer to the SPDM context.
1846 : * @param session_info The SPDM session ID.
1847 : * @param is_requester Indicate of the key generation for a requester or a responder.
1848 : * @param th1_hash_data Th2 hash
1849 : *
1850 : * @retval RETURN_SUCCESS th2 hash is calculated.
1851 : */
1852 : bool libspdm_calculate_th2_hash(libspdm_context_t *spdm_context,
1853 : void *spdm_session_info,
1854 : bool is_requester,
1855 : uint8_t *th2_hash_data);
1856 :
1857 : /**
1858 : * Reads a 24-bit value from memory that may be unaligned.
1859 : *
1860 : * @param buffer The pointer to a 24-bit value that may be unaligned.
1861 : *
1862 : * @return The 24-bit value read from buffer.
1863 : **/
1864 : uint32_t libspdm_read_uint24(const uint8_t *buffer);
1865 :
1866 : /**
1867 : * Writes a 24-bit value to memory that may be unaligned.
1868 : *
1869 : * @param buffer The pointer to a 24-bit value that may be unaligned.
1870 : * @param value 24-bit value to write to buffer.
1871 : **/
1872 : void libspdm_write_uint24(uint8_t *buffer, uint32_t value);
1873 :
1874 : /**
1875 : * Reads a 16-bit value from memory that may be unaligned.
1876 : *
1877 : * @param buffer The pointer to a 16-bit value that may be unaligned.
1878 : *
1879 : * @return The 16-bit value read from buffer.
1880 : **/
1881 : uint16_t libspdm_read_uint16(const uint8_t *buffer);
1882 :
1883 : /**
1884 : * Writes a 16-bit value to memory that may be unaligned.
1885 : *
1886 : * @param buffer The pointer to a 16-bit value that may be unaligned.
1887 : * @param value 16-bit value to write to buffer.
1888 : **/
1889 : void libspdm_write_uint16(uint8_t *buffer, uint16_t value);
1890 :
1891 : /**
1892 : * Reads a 32-bit value from memory that may be unaligned.
1893 : *
1894 : * @param buffer The pointer to a 32-bit value that may be unaligned.
1895 : *
1896 : * @return The 32-bit value read from buffer.
1897 : **/
1898 : uint32_t libspdm_read_uint32(const uint8_t *buffer);
1899 :
1900 : /**
1901 : * Writes a 32-bit value to memory that may be unaligned.
1902 : *
1903 : * @param buffer The pointer to a 32-bit value that may be unaligned.
1904 : * @param value 32-bit value to write to buffer.
1905 : **/
1906 : void libspdm_write_uint32(uint8_t *buffer, uint32_t value);
1907 :
1908 : /**
1909 : * Reads a 64-bit value from memory that may be unaligned.
1910 : *
1911 : * @param buffer The pointer to a 64-bit value that may be unaligned.
1912 : *
1913 : * @return The 64-bit value read from buffer.
1914 : **/
1915 : uint64_t libspdm_read_uint64(const uint8_t *buffer);
1916 :
1917 : /**
1918 : * Writes a 64-bit value to memory that may be unaligned.
1919 : *
1920 : * @param buffer The pointer to a 64-bit value that may be unaligned.
1921 : * @param value 64-bit value to write to buffer.
1922 : **/
1923 : void libspdm_write_uint64(uint8_t *buffer, uint64_t value);
1924 :
1925 : /**
1926 : * Determine if bitmask has at most one bit set.
1927 : *
1928 : * @param mask The bitmask to be tested.
1929 : *
1930 : * @retval true At most one bit is set.
1931 : * @retval false More than one bit is set.
1932 : */
1933 420 : static inline bool libspdm_onehot0(uint32_t mask)
1934 : {
1935 420 : return !mask || !(mask & (mask - 1));
1936 : }
1937 :
1938 12 : static inline uint64_t libspdm_byte_swap_64(uint64_t value)
1939 : {
1940 12 : return (((value & 0x00000000000000ff) << 56) |
1941 12 : ((value & 0x000000000000ff00) << 40) |
1942 12 : ((value & 0x0000000000ff0000) << 24) |
1943 12 : ((value & 0x00000000ff000000) << 8) |
1944 12 : ((value & 0x000000ff00000000) >> 8) |
1945 12 : ((value & 0x0000ff0000000000) >> 24) |
1946 24 : ((value & 0x00ff000000000000) >> 40) |
1947 12 : ((value & 0xff00000000000000) >> 56));
1948 : }
1949 :
1950 : static inline uint32_t libspdm_byte_swap_32(uint32_t value)
1951 : {
1952 : return ((value & 0x000000FF) << 24) |
1953 : ((value & 0x0000FF00) << 8) |
1954 : ((value & 0x00FF0000) >> 8) |
1955 : ((value & 0xFF000000) >> 24);
1956 : }
1957 :
1958 : static inline uint16_t libspdm_byte_swap_16(uint16_t value)
1959 : {
1960 : return ((value & 0x00FF) << 8) |
1961 : ((value & 0xFF00) >> 8);
1962 : }
1963 :
1964 : /**
1965 : * Return capability flags that are masked by the negotiated SPDM version.
1966 : *
1967 : * @param spdm_context A pointer to the SPDM context.
1968 : * @param is_request_flags If true then flags are from a request message or Requester.
1969 : * If false then flags are from a response message or Responder.
1970 : * @param flags A bitmask of capability flags.
1971 : *
1972 : * @return The masked capability flags.
1973 : */
1974 : uint32_t libspdm_mask_capability_flags(libspdm_context_t *spdm_context,
1975 : bool is_request_flags, uint32_t flags);
1976 :
1977 : /**
1978 : * Return capability extended flags that are masked by the negotiated SPDM version.
1979 : *
1980 : * @param spdm_context A pointer to the SPDM context.
1981 : * @param is_request_flags If true then flags are from a request message or Requester.
1982 : * If false then flags are from a response message or Responder.
1983 : * @param ext_flags A bitmask of capability extended flags.
1984 : *
1985 : * @return The masked capability extended flags.
1986 : */
1987 : uint16_t libspdm_mask_capability_ext_flags(libspdm_context_t *spdm_context,
1988 : bool is_request_flags, uint16_t ext_flags);
1989 :
1990 : /**
1991 : * Return BaseHashAlgo that is masked by the negotiated SPDM version.
1992 : *
1993 : * @param spdm_context A pointer to the SPDM context.
1994 : * @param base_hash_algo Unmasked BaseHashAlgo.
1995 : *
1996 : * @return The masked BaseHashAlgo.
1997 : */
1998 : uint32_t libspdm_mask_base_hash_algo(libspdm_context_t *spdm_context, uint32_t base_hash_algo);
1999 :
2000 : /**
2001 : * Return MeasurementHashAlgo that is masked by the negotiated SPDM version.
2002 : *
2003 : * @param spdm_context A pointer to the SPDM context.
2004 : * @param measurement_hash_algo Unmasked MeasurementHashAlgo.
2005 : *
2006 : * @return The masked MeasurementHashAlgo.
2007 : */
2008 : uint32_t libspdm_mask_measurement_hash_algo(libspdm_context_t *spdm_context,
2009 : uint32_t measurement_hash_algo);
2010 :
2011 : /**
2012 : * Return MeasurementSpecification that is masked by the negotiated SPDM version.
2013 : *
2014 : * @param spdm_context A pointer to the SPDM context.
2015 : * @param measurement_specification Unmasked MeasurementSpecification.
2016 : *
2017 : * @return The masked MeasurementSpecification.
2018 : */
2019 : uint8_t libspdm_mask_measurement_specification(uint8_t measurement_specification);
2020 :
2021 : /**
2022 : * Return MELspecification that is masked by the negotiated SPDM version.
2023 : *
2024 : * @param spdm_context A pointer to the SPDM context.
2025 : * @param mel_specification Unmasked MELspecification.
2026 : *
2027 : * @return The masked MELspecification.
2028 : */
2029 : uint8_t libspdm_mask_mel_specification(libspdm_context_t *spdm_context, uint8_t mel_specification);
2030 :
2031 : /**
2032 : * Return BaseAsymAlgo that is masked by the negotiated SPDM version.
2033 : *
2034 : * @param spdm_context A pointer to the SPDM context.
2035 : * @param base_asym_algo Unmasked BaseAsymAlgo.
2036 : *
2037 : * @return The masked BaseAsymAlgo.
2038 : */
2039 : uint32_t libspdm_mask_base_asym_algo(libspdm_context_t *spdm_context, uint32_t base_asym_algo);
2040 :
2041 : /**
2042 : * Check if the combination of SVH ID and VendorIDLen are legal.
2043 : *
2044 : * @param id Registry or standards body identifier (SPDM_REGISTRY_ID_*).
2045 : * Its size is two bytes due to the vendor-defined messages.
2046 : * @param vendor_id_len Length, in bytes, of the VendorID field.
2047 : * @retval true The ID and VendorIDLen are legal.
2048 : * @retval false The ID and VendorIDLen are illegal.
2049 : */
2050 : bool libspdm_validate_svh_vendor_id_len(uint16_t id, uint8_t vendor_id_len);
2051 :
2052 : /**
2053 : * Map slot ID to key pair ID.
2054 : *
2055 : * @param spdm_context A pointer to the SPDM context.
2056 : * @param slot_id The slot ID.
2057 : * @param is_requester Indicate of the key generation for a requester or a responder.
2058 : *
2059 : * @return key pair ID.
2060 : */
2061 : uint8_t libspdm_slot_id_to_key_pair_id (
2062 : void *spdm_context,
2063 : uint8_t slot_id,
2064 : bool is_requester);
2065 :
2066 : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
2067 : /**
2068 : * Check if the combination of DMTF EventTypeId and EventDetailLen is legal in a SEND_EVENT message.
2069 : *
2070 : * @param event_type_id Value of the DMTF EventTypeId.
2071 : * @param event_detail_len Size, in bytes, of EventDetail.
2072 : *
2073 : * @retval true The EventTypeId and EventDetailLen are legal.
2074 : * @retval false The EventTypeId and EventDetailLen are illegal.
2075 : */
2076 : bool libspdm_validate_dmtf_event_type(uint16_t event_type_id, uint16_t event_detail_len);
2077 :
2078 : /**
2079 : * Given a list of events, finds the event identified by the target EventInstanceID.
2080 : *
2081 : * @param events_list_start Pointer to list of events.
2082 : * @param event_count Number of events in the list.
2083 : * @param target_event_instance_id EventInstanceID to be found.
2084 : *
2085 : * @retval NULL Could not find the EventInstanceID.
2086 : * @retval non-NULL Pointer to the event corresponding to the target EventInstanceID
2087 : */
2088 : const void *libspdm_find_event_instance_id(const void *events_list_start, uint32_t event_count,
2089 : uint32_t target_event_instance_id);
2090 : /**
2091 : * Parses and sends an event to the Integrator. This function shall not be called if the Integrator
2092 : * has not registered an event handler via libspdm_register_event_callback.
2093 : *
2094 : * @param context A pointer to the SPDM context.
2095 : * @param session_id Secure session identifier.
2096 : * @param event_data A pointer to the event do be parsed and sent to Integrator.
2097 : * @param next_event_data On output, returns a pointer to the next event in event_data.
2098 : *
2099 : * @retval true The event was successfully parsed and sent to the Integrator.
2100 : * @retval false Unable to parse the event or the Integrator returned an error for the event.
2101 : */
2102 : bool libspdm_parse_and_send_event(libspdm_context_t *context, uint32_t session_id,
2103 : const void *event_data, const void **next_event_data);
2104 : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
2105 :
2106 : /**
2107 : * Given a buffer that spans from ptr to end_ptr, check if ptr + increment is within the buffer.
2108 : *
2109 : * @retval true There is enough space in the buffer.
2110 : * @retval false There is not enough space in the buffer.
2111 : */
2112 : bool libspdm_check_for_space(const uint8_t *ptr, const uint8_t *end_ptr, size_t increment);
2113 :
2114 : #endif /* SPDM_COMMON_LIB_INTERNAL_H */
|