-
Notifications
You must be signed in to change notification settings - Fork 107
/
spdm_transport_mctp_lib.h
149 lines (136 loc) · 7.63 KB
/
spdm_transport_mctp_lib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Copyright Notice:
* Copyright 2021-2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/
#ifndef SPDM_MCTP_TRANSPORT_LIB_H
#define SPDM_MCTP_TRANSPORT_LIB_H
#ifdef __cplusplus
extern "C" {
#endif
#include "library/spdm_common_lib.h"
#include "library/spdm_crypt_lib.h"
#include "industry_standard/mctp.h"
#define LIBSPDM_MCTP_ALIGNMENT 1
#define LIBSPDM_MCTP_SEQUENCE_NUMBER_COUNT 2
#define LIBSPDM_MCTP_MAX_RANDOM_NUMBER_COUNT 32
/* Required sender/receive buffer in device io.
* +-------+--------+---------------------------+------+--+------+---+--------+-----+
* | TYPE |TransHdr| EncryptionHeader |AppHdr| |Random|MAC|AlignPad|FINAL|
* | | |SessionId|SeqNum|Len|AppLen| | | | | | |
* +-------+--------+---------------------------+------+ +------+---+--------+-----+
* | MCTP | 1 | 4 | 2 | 2 | 2 | 1 | | 32 | 16| 0 | 60 |
* +-------+--------+---------------------------+------+--+------+---+--------+-----+
*/
#define LIBSPDM_MCTP_TRANSPORT_HEADER_SIZE (2 + 8 + \
LIBSPDM_MCTP_SEQUENCE_NUMBER_COUNT)
#define LIBSPDM_MCTP_TRANSPORT_TAIL_SIZE (LIBSPDM_MCTP_MAX_RANDOM_NUMBER_COUNT + \
LIBSPDM_MAX_AEAD_TAG_SIZE + \
(LIBSPDM_MCTP_ALIGNMENT - 1))
/**
* Encode an SPDM or APP message to a transport layer message.
*
* For normal SPDM message, it adds the transport layer wrapper.
* For secured SPDM message, it encrypts a secured message then adds the transport layer wrapper.
* For secured APP message, it encrypts a secured message then adds the transport layer wrapper.
*
* The APP message is encoded to a secured message directly in SPDM session.
* The APP message format is defined by the transport layer.
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Indicates if it is a secured message protected via SPDM session.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param is_requester Indicates if it is a requester message.
* @param message_size size in bytes of the message data buffer.
* @param message A pointer to a source buffer to store the message.
* For normal message, it shall point to the acquired sender buffer.
* For secured message, it shall point to the scratch buffer in spdm_context.
* @param transport_message_size size in bytes of the transport message data buffer.
* @param transport_message A pointer to a destination buffer to store the transport message.
* On input, it shall be msg_buf_ptr from sender buffer.
* On output, it will point to acquired sender buffer.
*
* @retval RETURN_SUCCESS The message is encoded successfully.
* @retval RETURN_INVALID_PARAMETER The message is NULL or the message_size is zero.
**/
libspdm_return_t libspdm_transport_mctp_encode_message(
void *spdm_context, const uint32_t *session_id, bool is_app_message,
bool is_requester, size_t message_size, void *message,
size_t *transport_message_size, void **transport_message);
/**
* Decode an SPDM or APP message from a transport layer message.
*
* For normal SPDM message, it removes the transport layer wrapper,
* For secured SPDM message, it removes the transport layer wrapper, then decrypts and verifies a secured message.
* For secured APP message, it removes the transport layer wrapper, then decrypts and verifies a secured message.
*
* The APP message is decoded from a secured message directly in SPDM session.
* The APP message format is defined by the transport layer.
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Indicates if it is a secured message protected via SPDM session.
* If *session_id is NULL, it is a normal message.
* If *session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param is_requester Indicates if it is a requester message.
* @param transport_message_size size in bytes of the transport message data buffer.
* @param transport_message A pointer to a source buffer to store the transport message.
* For normal message or secured message, it shall point to acquired receiver buffer.
* @param message_size size in bytes of the message data buffer.
* @param message A pointer to a destination buffer to store the message.
* On input, it shall point to the scratch buffer in spdm_context.
* On output, for normal message, it will point to the original receiver buffer.
* On output, for secured message, it will point to the scratch buffer in spdm_context.
*
* @retval RETURN_SUCCESS The message is decoded successfully.
* @retval RETURN_INVALID_PARAMETER The message is NULL or the message_size is zero.
* @retval RETURN_UNSUPPORTED The transport_message is unsupported.
**/
libspdm_return_t libspdm_transport_mctp_decode_message(
void *spdm_context, uint32_t **session_id,
bool *is_app_message, bool is_requester,
size_t transport_message_size, void *transport_message,
size_t *message_size, void **message);
/**
* Get sequence number in an SPDM secure message.
*
* This value is transport layer specific.
*
* @param sequence_number The current sequence number used to encode or decode message.
* @param sequence_number_buffer A buffer to hold the sequence number output used in the secured message.
* The size in byte of the output buffer shall be 8.
*
* @return size in byte of the sequence_number_buffer.
* It shall be no greater than 8.
* 0 means no sequence number is required.
**/
uint8_t libspdm_mctp_get_sequence_number(uint64_t sequence_number,
uint8_t *sequence_number_buffer);
/**
* Return max random number count in an SPDM secure message.
*
* This value is transport layer specific.
*
* @return Max random number count in an SPDM secured message.
* 0 means no random number is required.
**/
uint32_t libspdm_mctp_get_max_random_number_count(void);
/**
* This function translates the negotiated secured_message_version to a DSP0277 version.
*
* @param secured_message_version The version specified in binding specification and
* negotiated in KEY_EXCHANGE/KEY_EXCHANGE_RSP.
*
* @return The DSP0277 version specified in binding specification,
* which is bound to secured_message_version.
*/
spdm_version_number_t libspdm_mctp_get_secured_spdm_version(
spdm_version_number_t secured_message_version);
#ifdef __cplusplus
}
#endif
#endif /* SPDM_MCTP_TRANSPORT_LIB_H */