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 : #include "internal/libspdm_common_lib.h"
8 :
9 : #if LIBSPDM_DEBUG_PRINT_ENABLE
10 : typedef struct {
11 : uint8_t code;
12 : const char *code_str;
13 : } libspdm_code_str_struct_t;
14 :
15 136579 : const char *libspdm_get_code_str(uint8_t request_code)
16 : {
17 : size_t index;
18 :
19 : static const libspdm_code_str_struct_t code_str_struct[] = {
20 : /* SPDM response code (1.0) */
21 : { SPDM_DIGESTS, "SPDM_DIGESTS" },
22 : { SPDM_CERTIFICATE, "SPDM_CERTIFICATE" },
23 : { SPDM_CHALLENGE_AUTH, "SPDM_CHALLENGE_AUTH" },
24 : { SPDM_VERSION, "SPDM_VERSION" },
25 : { SPDM_MEASUREMENTS, "SPDM_MEASUREMENTS" },
26 : { SPDM_CAPABILITIES, "SPDM_CAPABILITIES" },
27 : { SPDM_ALGORITHMS, "SPDM_ALGORITHMS" },
28 : { SPDM_VENDOR_DEFINED_RESPONSE, "SPDM_VENDOR_DEFINED_RESPONSE" },
29 : { SPDM_ERROR, "SPDM_ERROR" },
30 : /* SPDM response code (1.1) */
31 : { SPDM_KEY_EXCHANGE_RSP, "SPDM_KEY_EXCHANGE_RSP" },
32 : { SPDM_FINISH_RSP, "SPDM_FINISH_RSP" },
33 : { SPDM_PSK_EXCHANGE_RSP, "SPDM_PSK_EXCHANGE_RSP" },
34 : { SPDM_PSK_FINISH_RSP, "SPDM_PSK_FINISH_RSP" },
35 : { SPDM_HEARTBEAT_ACK, "SPDM_HEARTBEAT_ACK" },
36 : { SPDM_KEY_UPDATE_ACK, "SPDM_KEY_UPDATE_ACK" },
37 : { SPDM_ENCAPSULATED_REQUEST, "SPDM_ENCAPSULATED_REQUEST" },
38 : { SPDM_ENCAPSULATED_RESPONSE_ACK, "SPDM_ENCAPSULATED_RESPONSE_ACK" },
39 : { SPDM_END_SESSION_ACK, "SPDM_END_SESSION_ACK" },
40 : /* SPDM response code (1.2) */
41 : { SPDM_CSR, "SPDM_CSR" },
42 : { SPDM_SET_CERTIFICATE_RSP, "SPDM_SET_CERTIFICATE_RSP" },
43 : { SPDM_CHUNK_SEND_ACK, "SPDM_CHUNK_SEND_ACK" },
44 : { SPDM_CHUNK_RESPONSE, "SPDM_CHUNK_RESPONSE" },
45 : /* SPDM response code (1.3 )*/
46 : { SPDM_SUPPORTED_EVENT_TYPES, "SPDM_SUPPORTED_EVENT_TYPES" },
47 : { SPDM_SUBSCRIBE_EVENT_TYPES_ACK, "SPDM_SUBSCRIBE_EVENT_TYPES_ACK" },
48 : { SPDM_EVENT_ACK, "SPDM_EVENT_ACK" },
49 : { SPDM_MEASUREMENT_EXTENSION_LOG, "SPDM_MEASUREMENT_EXTENSION_LOG" },
50 : { SPDM_KEY_PAIR_INFO, "SPDM_KEY_PAIR_INFO" },
51 : { SPDM_SET_KEY_PAIR_INFO_ACK, "SPDM_SET_KEY_PAIR_INFO_ACK" },
52 : { SPDM_ENDPOINT_INFO, "SPDM_ENDPOINT_INFO" },
53 : /* SPDM request code (1.0) */
54 : { SPDM_GET_DIGESTS, "SPDM_GET_DIGESTS" },
55 : { SPDM_GET_CERTIFICATE, "SPDM_GET_CERTIFICATE" },
56 : { SPDM_CHALLENGE, "SPDM_CHALLENGE" },
57 : { SPDM_GET_VERSION, "SPDM_GET_VERSION" },
58 : { SPDM_GET_MEASUREMENTS, "SPDM_GET_MEASUREMENTS" },
59 : { SPDM_GET_CAPABILITIES, "SPDM_GET_CAPABILITIES" },
60 : { SPDM_NEGOTIATE_ALGORITHMS, "SPDM_NEGOTIATE_ALGORITHMS" },
61 : { SPDM_VENDOR_DEFINED_REQUEST, "SPDM_VENDOR_DEFINED_REQUEST" },
62 : { SPDM_RESPOND_IF_READY, "SPDM_RESPOND_IF_READY" },
63 : /* SPDM request code (1.1) */
64 : { SPDM_KEY_EXCHANGE, "SPDM_KEY_EXCHANGE" },
65 : { SPDM_FINISH, "SPDM_FINISH" },
66 : { SPDM_PSK_EXCHANGE, "SPDM_PSK_EXCHANGE" },
67 : { SPDM_PSK_FINISH, "SPDM_PSK_FINISH" },
68 : { SPDM_HEARTBEAT, "SPDM_HEARTBEAT" },
69 : { SPDM_KEY_UPDATE, "SPDM_KEY_UPDATE" },
70 : { SPDM_GET_ENCAPSULATED_REQUEST, "SPDM_GET_ENCAPSULATED_REQUEST" },
71 : { SPDM_DELIVER_ENCAPSULATED_RESPONSE, "SPDM_DELIVER_ENCAPSULATED_RESPONSE" },
72 : { SPDM_END_SESSION, "SPDM_END_SESSION" },
73 : /* SPDM request code (1.2) */
74 : { SPDM_GET_CSR, "SPDM_GET_CSR" },
75 : { SPDM_SET_CERTIFICATE, "SPDM_SET_CERTIFICATE" },
76 : { SPDM_CHUNK_SEND, "SPDM_CHUNK_SEND" },
77 : { SPDM_CHUNK_GET, "SPDM_CHUNK_GET" },
78 : /* SPDM request code (1.3) */
79 : { SPDM_GET_SUPPORTED_EVENT_TYPES, "SPDM_GET_SUPPORTED_EVENT_TYPES" },
80 : { SPDM_SUBSCRIBE_EVENT_TYPES, "SPDM_SUBSCRIBE_EVENT_TYPES" },
81 : { SPDM_SEND_EVENT, "SPDM_SEND_EVENT" },
82 : { SPDM_GET_MEASUREMENT_EXTENSION_LOG, "SPDM_GET_MEASUREMENT_EXTENSION_LOG" },
83 : { SPDM_GET_KEY_PAIR_INFO, "SPDM_GET_KEY_PAIR_INFO" },
84 : { SPDM_SET_KEY_PAIR_INFO, "SPDM_SET_KEY_PAIR_INFO" },
85 : { SPDM_GET_ENDPOINT_INFO, "SPDM_GET_ENDPOINT_INFO" },
86 : };
87 :
88 4897042 : for (index = 0; index < LIBSPDM_ARRAY_SIZE(code_str_struct); index++) {
89 4897040 : if (request_code == code_str_struct[index].code) {
90 136577 : return code_str_struct[index].code_str;
91 : }
92 : }
93 :
94 2 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "RequestResponseCode 0x%x not found.\n", request_code));
95 :
96 2 : return "<unknown>";
97 : }
98 :
99 37 : void libspdm_internal_dump_hex_str(const uint8_t *data, size_t size)
100 : {
101 : size_t index;
102 1221 : for (index = 0; index < size; index++) {
103 1184 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "%02x", data[index]));
104 : }
105 37 : }
106 :
107 213780 : void libspdm_internal_dump_data(const uint8_t *data, size_t size)
108 : {
109 : size_t index;
110 3851920 : for (index = 0; index < size; index++) {
111 3638140 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "%02x ", data[index]));
112 : }
113 213780 : }
114 :
115 139227 : void libspdm_internal_dump_hex(const uint8_t *data, size_t size)
116 : {
117 : size_t index;
118 : size_t count;
119 : size_t left;
120 :
121 : #define COLUMN_SIZE (16 * 2)
122 :
123 139227 : count = size / COLUMN_SIZE;
124 139227 : left = size % COLUMN_SIZE;
125 211769 : for (index = 0; index < count; index++) {
126 72542 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "%04zx: ", index * COLUMN_SIZE));
127 72542 : LIBSPDM_INTERNAL_DUMP_DATA(data + index * COLUMN_SIZE, COLUMN_SIZE);
128 72542 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
129 : }
130 :
131 139227 : if (left != 0) {
132 138881 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "%04zx: ", index * COLUMN_SIZE));
133 138881 : LIBSPDM_INTERNAL_DUMP_DATA(data + index * COLUMN_SIZE, left);
134 138881 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
135 : }
136 139227 : }
137 : #endif /* LIBSPDM_DEBUG_PRINT_ENABLE */
138 :
139 1108 : uint16_t libspdm_read_uint16(const uint8_t *buffer)
140 : {
141 2216 : return (uint16_t)
142 1108 : ((uint16_t)buffer[0] |
143 1108 : ((uint16_t)buffer[1] << 8));
144 : }
145 :
146 667 : void libspdm_write_uint16(uint8_t *buffer, uint16_t value)
147 : {
148 667 : buffer[0] = (uint8_t)(value & 0xFF);
149 667 : buffer[1] = (uint8_t)((value >> 8) & 0xFF);
150 667 : }
151 :
152 257 : uint32_t libspdm_read_uint24(const uint8_t *buffer)
153 : {
154 514 : return (uint32_t)
155 257 : ((uint32_t)buffer[0] |
156 257 : ((uint32_t)buffer[1] << 8) |
157 257 : ((uint32_t)buffer[2] << 16));
158 : }
159 :
160 2341 : void libspdm_write_uint24(uint8_t *buffer, uint32_t value)
161 : {
162 2341 : buffer[0] = (uint8_t)(value & 0xFF);
163 2341 : buffer[1] = (uint8_t)((value >> 8) & 0xFF);
164 2341 : buffer[2] = (uint8_t)((value >> 16) & 0xFF);
165 2341 : }
166 :
167 597 : uint32_t libspdm_read_uint32(const uint8_t *buffer)
168 : {
169 1194 : return (uint32_t)
170 597 : ((uint32_t)buffer[0] |
171 597 : ((uint32_t)buffer[1] << 8) |
172 597 : ((uint32_t)buffer[2] << 16) |
173 597 : ((uint32_t)buffer[3] << 24));
174 : }
175 :
176 82 : void libspdm_write_uint32(uint8_t *buffer, uint32_t value)
177 : {
178 82 : buffer[0] = (uint8_t)(value & 0xFF);
179 82 : buffer[1] = (uint8_t)((value >> 8) & 0xFF);
180 82 : buffer[2] = (uint8_t)((value >> 16) & 0xFF);
181 82 : buffer[3] = (uint8_t)((value >> 24) & 0xFF);
182 82 : }
183 :
184 3 : uint64_t libspdm_read_uint64(const uint8_t *buffer)
185 : {
186 6 : return (uint64_t)
187 3 : ((uint64_t)buffer[0] |
188 3 : ((uint64_t)buffer[1] << 8) |
189 3 : ((uint64_t)buffer[2] << 16) |
190 3 : ((uint64_t)buffer[3] << 24) |
191 3 : ((uint64_t)buffer[4] << 32) |
192 3 : ((uint64_t)buffer[5] << 40) |
193 3 : ((uint64_t)buffer[6] << 48) |
194 3 : ((uint64_t)buffer[7] << 56));
195 : }
196 :
197 3 : void libspdm_write_uint64(uint8_t *buffer, uint64_t value)
198 : {
199 3 : buffer[0] = (uint8_t)(value & 0xFF);
200 3 : buffer[1] = (uint8_t)((value >> 8) & 0xFF);
201 3 : buffer[2] = (uint8_t)((value >> 16) & 0xFF);
202 3 : buffer[3] = (uint8_t)((value >> 24) & 0xFF);
203 3 : buffer[4] = (uint8_t)((value >> 32) & 0xFF);
204 3 : buffer[5] = (uint8_t)((value >> 40) & 0xFF);
205 3 : buffer[6] = (uint8_t)((value >> 48) & 0xFF);
206 3 : buffer[7] = (uint8_t)((value >> 56) & 0xFF);
207 3 : }
208 :
209 471 : libspdm_return_t libspdm_append_managed_buffer(void *m_buffer, const void *buffer,
210 : size_t buffer_size)
211 : {
212 : libspdm_managed_buffer_t *managed_buffer;
213 :
214 471 : LIBSPDM_ASSERT(buffer != NULL);
215 :
216 471 : if (buffer_size == 0) {
217 0 : return LIBSPDM_STATUS_SUCCESS;
218 : }
219 :
220 471 : managed_buffer = m_buffer;
221 :
222 471 : LIBSPDM_ASSERT(buffer_size != 0);
223 471 : LIBSPDM_ASSERT(managed_buffer->max_buffer_size >= managed_buffer->buffer_size);
224 :
225 471 : if (buffer_size > managed_buffer->max_buffer_size - managed_buffer->buffer_size) {
226 : /* Do not LIBSPDM_ASSERT here, because command processor will append message from external.*/
227 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
228 : "libspdm_append_managed_buffer 0x%x fail, rest 0x%x only\n",
229 : (uint32_t)buffer_size,
230 : (uint32_t)(managed_buffer->max_buffer_size - managed_buffer->buffer_size)));
231 1 : return LIBSPDM_STATUS_BUFFER_FULL;
232 : }
233 470 : LIBSPDM_ASSERT(buffer_size <= managed_buffer->max_buffer_size - managed_buffer->buffer_size);
234 :
235 470 : libspdm_copy_mem((uint8_t *)(managed_buffer + 1) + managed_buffer->buffer_size,
236 : buffer_size, buffer, buffer_size);
237 470 : managed_buffer->buffer_size += buffer_size;
238 :
239 470 : return LIBSPDM_STATUS_SUCCESS;
240 : }
241 :
242 888 : void libspdm_reset_managed_buffer(void *m_buffer)
243 : {
244 : libspdm_managed_buffer_t *managed_buffer;
245 :
246 888 : managed_buffer = m_buffer;
247 888 : managed_buffer->buffer_size = 0;
248 :
249 888 : libspdm_zero_mem(managed_buffer + 1, managed_buffer->max_buffer_size);
250 888 : }
251 :
252 700 : size_t libspdm_get_managed_buffer_size(void *m_buffer)
253 : {
254 : libspdm_managed_buffer_t *managed_buffer;
255 :
256 700 : managed_buffer = m_buffer;
257 :
258 700 : return managed_buffer->buffer_size;
259 : }
260 :
261 686 : void *libspdm_get_managed_buffer(void *m_buffer)
262 : {
263 : libspdm_managed_buffer_t *managed_buffer;
264 :
265 686 : managed_buffer = m_buffer;
266 :
267 686 : return (managed_buffer + 1);
268 : }
269 :
270 116 : void libspdm_init_managed_buffer(void *m_buffer, size_t max_buffer_size)
271 : {
272 : libspdm_managed_buffer_t *managed_buffer;
273 :
274 116 : managed_buffer = m_buffer;
275 116 : managed_buffer->max_buffer_size = max_buffer_size;
276 :
277 116 : libspdm_reset_managed_buffer(m_buffer);
278 116 : }
279 :
280 0 : uint32_t libspdm_module_version(void)
281 : {
282 0 : return (LIBSPDM_MAJOR_VERSION << 24) |
283 : (LIBSPDM_MINOR_VERSION << 16) |
284 : (LIBSPDM_PATCH_VERSION << 8) |
285 : (LIBSPDM_ALPHA);
286 : }
287 :
288 : /*true: FIPS enabled, false: FIPS disabled*/
289 0 : bool libspdm_get_fips_mode(void)
290 : {
291 : #if LIBSPDM_FIPS_MODE
292 0 : return true;
293 : #else
294 : return false;
295 : #endif
296 : }
297 :
298 77 : uint32_t libspdm_mask_capability_flags(libspdm_context_t *spdm_context,
299 : bool is_request_flags, uint32_t flags)
300 : {
301 77 : switch (libspdm_get_connection_version(spdm_context)) {
302 9 : case SPDM_MESSAGE_VERSION_10:
303 9 : if (is_request_flags) {
304 : /* A 1.0 Requester does not have any capability flags. */
305 2 : return 0;
306 : } else {
307 7 : return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_10_MASK);
308 : }
309 45 : case SPDM_MESSAGE_VERSION_11:
310 45 : if (is_request_flags) {
311 39 : return (flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_11_MASK);
312 : } else {
313 6 : return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_11_MASK);
314 : }
315 12 : case SPDM_MESSAGE_VERSION_12:
316 12 : if (is_request_flags) {
317 10 : return (flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_12_MASK);
318 : } else {
319 2 : return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_12_MASK);
320 : }
321 11 : case SPDM_MESSAGE_VERSION_13:
322 11 : if (is_request_flags) {
323 6 : return (flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_13_MASK);
324 : } else {
325 5 : return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_13_MASK);
326 : }
327 0 : case SPDM_MESSAGE_VERSION_14:
328 0 : if (is_request_flags) {
329 0 : return (flags & SPDM_GET_CAPABILITIES_REQUEST_FLAGS_14_MASK);
330 : } else {
331 0 : return (flags & SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_14_MASK);
332 : }
333 0 : default:
334 0 : LIBSPDM_ASSERT(false);
335 0 : return 0;
336 : }
337 : }
338 :
339 0 : uint16_t libspdm_mask_capability_ext_flags(libspdm_context_t *spdm_context,
340 : bool is_request_flags, uint16_t ext_flags)
341 : {
342 0 : switch (libspdm_get_connection_version(spdm_context)) {
343 0 : case SPDM_MESSAGE_VERSION_10:
344 : case SPDM_MESSAGE_VERSION_11:
345 : case SPDM_MESSAGE_VERSION_12:
346 : case SPDM_MESSAGE_VERSION_13:
347 : /* No extended capability flags are defined for SPDM 1.0 - 1.3. */
348 0 : return 0;
349 0 : case SPDM_MESSAGE_VERSION_14:
350 0 : if (is_request_flags) {
351 : /* No extended request flags are defined for SPDM 1.4. */
352 0 : return 0;
353 : } else {
354 0 : return (ext_flags & SPDM_GET_CAPABILITIES_EXTENDED_RESPONSE_FLAGS_14_MASK);
355 : }
356 0 : default:
357 0 : LIBSPDM_ASSERT(false);
358 0 : return 0;
359 : }
360 : }
361 :
362 0 : uint32_t libspdm_mask_base_hash_algo(libspdm_context_t *spdm_context, uint32_t base_hash_algo)
363 : {
364 0 : const uint8_t spdm_version = libspdm_get_connection_version(spdm_context);
365 :
366 0 : if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
367 0 : return (base_hash_algo & SPDM_ALGORITHMS_BASE_HASH_ALGO_12_MASK);
368 : } else {
369 0 : return (base_hash_algo & SPDM_ALGORITHMS_BASE_HASH_ALGO_10_MASK);
370 : }
371 : }
372 :
373 0 : uint32_t libspdm_mask_measurement_hash_algo(libspdm_context_t *spdm_context,
374 : uint32_t measurement_hash_algo)
375 : {
376 0 : const uint8_t spdm_version = libspdm_get_connection_version(spdm_context);
377 :
378 0 : if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
379 0 : return (measurement_hash_algo & SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_12_MASK);
380 : } else {
381 0 : return (measurement_hash_algo & SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_10_MASK);
382 : }
383 : }
384 :
385 0 : uint8_t libspdm_mask_measurement_specification(uint8_t measurement_specification)
386 : {
387 0 : return (measurement_specification & SPDM_MEASUREMENT_SPECIFICATION_10_MASK);
388 : }
389 :
390 0 : uint8_t libspdm_mask_mel_specification(libspdm_context_t *spdm_context, uint8_t mel_specification)
391 : {
392 0 : LIBSPDM_ASSERT(libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13);
393 :
394 0 : return (mel_specification & SPDM_MEL_SPECIFICATION_13_MASK);
395 : }
396 :
397 0 : uint32_t libspdm_mask_base_asym_algo(libspdm_context_t *spdm_context, uint32_t base_asym_algo)
398 : {
399 0 : const uint8_t spdm_version = libspdm_get_connection_version(spdm_context);
400 :
401 0 : if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
402 0 : return (base_asym_algo & SPDM_ALGORITHMS_BASE_ASYM_ALGO_12_MASK);
403 : } else {
404 0 : return (base_asym_algo & SPDM_ALGORITHMS_BASE_ASYM_ALGO_10_MASK);
405 : }
406 : }
407 :
408 0 : uint16_t libspdm_mask_alg_supported(libspdm_context_t *spdm_context, uint8_t alg_type,
409 : uint16_t alg_supported)
410 : {
411 0 : const uint8_t spdm_version = libspdm_get_connection_version(spdm_context);
412 :
413 0 : LIBSPDM_ASSERT(spdm_version >= SPDM_MESSAGE_VERSION_11);
414 :
415 0 : switch (alg_type) {
416 0 : case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE:
417 0 : if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
418 0 : return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_DHE_12_MASK);
419 : } else {
420 0 : return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_DHE_11_MASK);
421 : }
422 0 : case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD:
423 0 : if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
424 0 : return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_AEAD_12_MASK);
425 : } else {
426 0 : return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_AEAD_11_MASK);
427 : }
428 0 : case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG:
429 0 : if (spdm_version >= SPDM_MESSAGE_VERSION_12) {
430 0 : return (alg_supported &
431 : SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_REQ_BASE_ASYM_ALG_12_MASK);
432 : } else {
433 0 : return (alg_supported &
434 : SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_REQ_BASE_ASYM_ALG_11_MASK);
435 : }
436 0 : case SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE:
437 0 : return (alg_supported & SPDM_NEGOTIATE_ALGORITHMS_ALG_SUPPORTED_KEY_SCHEDULE_11_MASK);
438 0 : default:
439 0 : LIBSPDM_ASSERT(false);
440 0 : return 0;
441 : }
442 : }
443 :
444 36 : bool libspdm_validate_svh_vendor_id_len(uint16_t id, uint8_t vendor_id_len)
445 : {
446 36 : switch (id) {
447 28 : case SPDM_REGISTRY_ID_DMTF:
448 : case SPDM_REGISTRY_ID_VESA:
449 28 : return (vendor_id_len == 0);
450 8 : case SPDM_REGISTRY_ID_TCG:
451 : case SPDM_REGISTRY_ID_USB:
452 : case SPDM_REGISTRY_ID_PCISIG:
453 : case SPDM_REGISTRY_ID_MIPI:
454 : case SPDM_REGISTRY_ID_CXL:
455 : case SPDM_REGISTRY_ID_JEDEC:
456 8 : return ((vendor_id_len == 0) || (vendor_id_len == 2));
457 0 : case SPDM_REGISTRY_ID_IANA:
458 : case SPDM_REGISTRY_ID_HDBASET:
459 0 : return ((vendor_id_len == 0) || (vendor_id_len == 4));
460 0 : case SPDM_REGISTRY_ID_IANA_CBOR:
461 0 : switch (vendor_id_len) {
462 : /* A CBOR-encoded tag number is either a simple one byte identifier, or a one byte
463 : * identifier followed by a one, two, four, or eight byte unsigned integer. */
464 0 : case 1:
465 : case 2:
466 : case 3:
467 : case 5:
468 : case 9:
469 0 : return true;
470 0 : default:
471 0 : return false;
472 : }
473 0 : case SPDM_REGISTRY_ID_DMTF_DSP:
474 0 : return (vendor_id_len == 2);
475 0 : default:
476 0 : return false;
477 : }
478 : }
479 :
480 100 : bool libspdm_check_for_space(const uint8_t *ptr, const uint8_t *end_ptr, size_t increment)
481 : {
482 100 : LIBSPDM_ASSERT(ptr <= end_ptr);
483 :
484 100 : return ((uintptr_t)(end_ptr - ptr) >= increment);
485 : }
|