blob: 8a8f3482051b5d0eab87b7c6d40df67b096be5fc [file] [log] [blame]
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +08001/*
2 * Copyright (c) 2020-2022, Intel Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef SOCFPGA_FCS_H
8#define SOCFPGA_FCS_H
9
10/* FCS Definitions */
11
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080012#define FCS_RANDOM_WORD_SIZE 8U
13#define FCS_PROV_DATA_WORD_SIZE 44U
14#define FCS_SHA384_WORD_SIZE 12U
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +080015
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080016#define FCS_RANDOM_BYTE_SIZE (FCS_RANDOM_WORD_SIZE * 4U)
17#define FCS_RANDOM_EXT_MAX_WORD_SIZE 1020U
18#define FCS_PROV_DATA_BYTE_SIZE (FCS_PROV_DATA_WORD_SIZE * 4U)
19#define FCS_SHA384_BYTE_SIZE (FCS_SHA384_WORD_SIZE * 4U)
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +080020
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080021#define FCS_RANDOM_EXT_OFFSET 3
Sieu Mun Tange7a037f2022-05-10 17:18:19 +080022
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080023#define FCS_MODE_DECRYPT 0x0
24#define FCS_MODE_ENCRYPT 0x1
25#define FCS_ENCRYPTION_DATA_0 0x10100
26#define FCS_DECRYPTION_DATA_0 0x10102
27#define FCS_OWNER_ID_OFFSET 0xC
28#define FCS_CRYPTION_CRYPTO_HEADER 0x07000000
29#define FCS_CRYPTION_RESP_WORD_SIZE 4U
30#define FCS_CRYPTION_RESP_SIZE_OFFSET 3U
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +080031
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080032#define PSGSIGMA_TEARDOWN_MAGIC 0xB852E2A4
33#define PSGSIGMA_SESSION_ID_ONE 0x1
34#define PSGSIGMA_UNKNOWN_SESSION 0xFFFFFFFF
Sieu Mun Tang2a820b92022-05-11 09:59:55 +080035
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080036#define RESERVED_AS_ZERO 0x0
Sieu Mun Tanga068fdf2022-05-11 10:01:54 +080037/* FCS Single cert */
38
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080039#define FCS_BIG_CNTR_SEL 0x1
Sieu Mun Tanga068fdf2022-05-11 10:01:54 +080040
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080041#define FCS_SVN_CNTR_0_SEL 0x2
42#define FCS_SVN_CNTR_1_SEL 0x3
43#define FCS_SVN_CNTR_2_SEL 0x4
44#define FCS_SVN_CNTR_3_SEL 0x5
Sieu Mun Tanga068fdf2022-05-11 10:01:54 +080045
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080046#define FCS_BIG_CNTR_VAL_MAX 495U
47#define FCS_SVN_CNTR_VAL_MAX 64U
Sieu Mun Tang2a820b92022-05-11 09:59:55 +080048
Sieu Mun Tang28af1652022-05-09 10:48:53 +080049/* FCS Attestation Cert Request Parameter */
50
Boon Khai Ngd2df2042021-08-30 15:05:49 +080051#define FCS_ATTEST_FIRMWARE_CERT 0x01
52#define FCS_ATTEST_DEV_ID_SELF_SIGN_CERT 0x02
53#define FCS_ATTEST_DEV_ID_ENROLL_CERT 0x04
54#define FCS_ATTEST_ENROLL_SELF_SIGN_CERT 0x08
55#define FCS_ATTEST_ALIAS_CERT 0x10
56#define FCS_ATTEST_CERT_MAX_REQ_PARAM 0xFF
Sieu Mun Tang28af1652022-05-09 10:48:53 +080057
Sieu Mun Tangfb1f6e92022-05-09 14:16:14 +080058/* FCS Crypto Service */
59
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080060#define FCS_CS_KEY_OBJ_MAX_WORD_SIZE 88U
61#define FCS_CS_KEY_INFO_MAX_WORD_SIZE 36U
62#define FCS_CS_KEY_RESP_STATUS_MASK 0xFF
63#define FCS_CS_KEY_RESP_STATUS_OFFSET 16U
Sieu Mun Tangfb1f6e92022-05-09 14:16:14 +080064
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080065#define FCS_CS_FIELD_SIZE_MASK 0xFFFF
66#define FCS_CS_FIELD_FLAG_OFFSET 24
67#define FCS_CS_FIELD_FLAG_INIT BIT(0)
68#define FCS_CS_FIELD_FLAG_UPDATE BIT(1)
69#define FCS_CS_FIELD_FLAG_FINALIZE BIT(2)
Sieu Mun Tange7a037f2022-05-10 17:18:19 +080070
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080071#define FCS_AES_MAX_DATA_SIZE 0x10000000 /* 256 MB */
72#define FCS_AES_MIN_DATA_SIZE 0x20 /* 32 Byte */
73#define FCS_AES_CMD_MAX_WORD_SIZE 15U
Sieu Mun Tangb0c1d112022-05-10 17:30:00 +080074
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080075#define FCS_GET_DIGEST_CMD_MAX_WORD_SIZE 7U
76#define FCS_GET_DIGEST_RESP_MAX_WORD_SIZE 19U
77#define FCS_MAC_VERIFY_CMD_MAX_WORD_SIZE 23U
78#define FCS_MAC_VERIFY_RESP_MAX_WORD_SIZE 4U
79#define FCS_SHA_HMAC_CRYPTO_PARAM_SIZE_OFFSET 8U
Sieu Mun Tange2f3ede2022-05-10 17:36:32 +080080
Sieu Mun Tangdcaab772022-05-11 10:16:40 +080081#define FCS_ECDSA_GET_PUBKEY_MAX_WORD_SIZE 5U
82#define FCS_ECDSA_SHA2_DATA_SIGN_CMD_MAX_WORD_SIZE 7U
83#define FCS_ECDSA_SHA2_DATA_SIG_VERIFY_CMD_MAX_WORD_SIZE 43U
Sieu Mun Tang8aa05ad2022-05-10 17:50:30 +080084#define FCS_ECDSA_HASH_SIGN_CMD_MAX_WORD_SIZE 17U
Sieu Mun Tang59357e82022-05-10 17:53:32 +080085#define FCS_ECDSA_HASH_SIG_VERIFY_CMD_MAX_WORD_SIZE 52U
Sieu Mun Tang0675c222022-05-10 17:48:11 +080086#define FCS_ECDH_REQUEST_CMD_MAX_WORD_SIZE 29U
Jit Loon Lim6f9a4cc2022-09-13 10:24:04 +080087
88#define FCS_CRYPTO_ECB_BUFFER_SIZE 12U
89#define FCS_CRYPTO_CBC_CTR_BUFFER_SIZE 28U
90#define FCS_CRYPTO_BLOCK_MODE_MASK 0x07
91#define FCS_CRYPTO_ECB_MODE 0x00
92#define FCS_CRYPTO_CBC_MODE 0x01
93#define FCS_CRYPTO_CTR_MODE 0x02
94
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +080095/* FCS Payload Structure */
Sieu Mun Tange7a037f2022-05-10 17:18:19 +080096typedef struct fcs_rng_payload_t {
97 uint32_t session_id;
98 uint32_t context_id;
99 uint32_t crypto_header;
100 uint32_t size;
101} fcs_rng_payload;
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800102
Sieu Mun Tang128d2a72022-05-11 09:49:25 +0800103typedef struct fcs_encrypt_payload_t {
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800104 uint32_t first_word;
105 uint32_t src_addr;
106 uint32_t src_size;
107 uint32_t dst_addr;
108 uint32_t dst_size;
Sieu Mun Tang128d2a72022-05-11 09:49:25 +0800109} fcs_encrypt_payload;
110
111typedef struct fcs_decrypt_payload_t {
112 uint32_t first_word;
113 uint32_t owner_id[2];
114 uint32_t src_addr;
115 uint32_t src_size;
116 uint32_t dst_addr;
117 uint32_t dst_size;
118} fcs_decrypt_payload;
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800119
Sieu Mun Tang22322fb2022-05-09 16:05:58 +0800120typedef struct fcs_encrypt_ext_payload_t {
121 uint32_t session_id;
122 uint32_t context_id;
123 uint32_t crypto_header;
124 uint32_t src_addr;
125 uint32_t src_size;
126 uint32_t dst_addr;
127 uint32_t dst_size;
128} fcs_encrypt_ext_payload;
129
130typedef struct fcs_decrypt_ext_payload_t {
131 uint32_t session_id;
132 uint32_t context_id;
133 uint32_t crypto_header;
134 uint32_t owner_id[2];
135 uint32_t src_addr;
136 uint32_t src_size;
137 uint32_t dst_addr;
138 uint32_t dst_size;
139} fcs_decrypt_ext_payload;
140
Sieu Mun Tang2a820b92022-05-11 09:59:55 +0800141typedef struct psgsigma_teardown_msg_t {
142 uint32_t reserved_word;
143 uint32_t magic_word;
144 uint32_t session_id;
145} psgsigma_teardown_msg;
146
Sieu Mun Tanga068fdf2022-05-11 10:01:54 +0800147typedef struct fcs_cntr_set_preauth_payload_t {
148 uint32_t first_word;
149 uint32_t counter_value;
150} fcs_cntr_set_preauth_payload;
Sieu Mun Tang2a820b92022-05-11 09:59:55 +0800151
Sieu Mun Tangfb1f6e92022-05-09 14:16:14 +0800152typedef struct fcs_cs_key_payload_t {
153 uint32_t session_id;
154 uint32_t reserved0;
155 uint32_t reserved1;
156 uint32_t key_id;
157} fcs_cs_key_payload;
158
Sieu Mun Tangd907cc32022-05-10 17:24:05 +0800159typedef struct fcs_crypto_service_data_t {
160 uint32_t session_id;
161 uint32_t context_id;
162 uint32_t key_id;
163 uint32_t crypto_param_size;
164 uint64_t crypto_param;
Sieu Mun Tange77d37d2022-04-28 16:23:20 +0800165 uint8_t is_updated;
Sieu Mun Tangd907cc32022-05-10 17:24:05 +0800166} fcs_crypto_service_data;
167
Sieu Mun Tangb0c1d112022-05-10 17:30:00 +0800168typedef struct fcs_crypto_service_aes_data_t {
169 uint32_t session_id;
170 uint32_t context_id;
171 uint32_t param_size;
172 uint32_t key_id;
173 uint32_t crypto_param[7];
Sieu Mun Tang9bea8152022-04-28 16:15:54 +0800174 uint8_t is_updated;
Sieu Mun Tangb0c1d112022-05-10 17:30:00 +0800175} fcs_crypto_service_aes_data;
176
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800177/* Functions Definitions */
178
179uint32_t intel_fcs_random_number_gen(uint64_t addr, uint64_t *ret_size,
180 uint32_t *mbox_error);
Sieu Mun Tange7a037f2022-05-10 17:18:19 +0800181int intel_fcs_random_number_gen_ext(uint32_t session_id, uint32_t context_id,
182 uint32_t size, uint32_t *send_id);
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800183uint32_t intel_fcs_send_cert(uint64_t addr, uint64_t size,
184 uint32_t *send_id);
185uint32_t intel_fcs_get_provision_data(uint32_t *send_id);
Sieu Mun Tanga068fdf2022-05-11 10:01:54 +0800186uint32_t intel_fcs_cntr_set_preauth(uint8_t counter_type,
187 int32_t counter_value,
188 uint32_t test_bit,
189 uint32_t *mbox_error);
Sieu Mun Tang128d2a72022-05-11 09:49:25 +0800190uint32_t intel_fcs_encryption(uint32_t src_addr, uint32_t src_size,
191 uint32_t dst_addr, uint32_t dst_size,
192 uint32_t *send_id);
193
194uint32_t intel_fcs_decryption(uint32_t src_addr, uint32_t src_size,
195 uint32_t dst_addr, uint32_t dst_size,
196 uint32_t *send_id);
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800197
Sieu Mun Tang22322fb2022-05-09 16:05:58 +0800198int intel_fcs_encryption_ext(uint32_t session_id, uint32_t context_id,
199 uint32_t src_addr, uint32_t src_size,
200 uint32_t dst_addr, uint32_t *dst_size,
201 uint32_t *mbox_error);
202int intel_fcs_decryption_ext(uint32_t sesion_id, uint32_t context_id,
203 uint32_t src_addr, uint32_t src_size,
204 uint32_t dst_addr, uint32_t *dst_size,
205 uint32_t *mbox_error);
206
Sieu Mun Tang2a820b92022-05-11 09:59:55 +0800207int intel_fcs_sigma_teardown(uint32_t session_id, uint32_t *mbox_error);
208int intel_fcs_chip_id(uint32_t *id_low, uint32_t *id_high, uint32_t *mbox_error);
209int intel_fcs_attestation_subkey(uint64_t src_addr, uint32_t src_size,
210 uint64_t dst_addr, uint32_t *dst_size,
211 uint32_t *mbox_error);
212int intel_fcs_get_measurement(uint64_t src_addr, uint32_t src_size,
213 uint64_t dst_addr, uint32_t *dst_size,
214 uint32_t *mbox_error);
Sieu Mun Tanga34b8812022-03-17 03:11:55 +0800215uint32_t intel_fcs_get_rom_patch_sha384(uint64_t addr, uint64_t *ret_size,
216 uint32_t *mbox_error);
217
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800218int intel_fcs_create_cert_on_reload(uint32_t cert_request,
219 uint32_t *mbox_error);
220int intel_fcs_get_attestation_cert(uint32_t cert_request, uint64_t dst_addr,
221 uint32_t *dst_size, uint32_t *mbox_error);
222
Sieu Mun Tang16754e12022-05-09 12:08:42 +0800223int intel_fcs_open_crypto_service_session(uint32_t *session_id,
224 uint32_t *mbox_error);
225int intel_fcs_close_crypto_service_session(uint32_t session_id,
226 uint32_t *mbox_error);
227
Sieu Mun Tangfb1f6e92022-05-09 14:16:14 +0800228int intel_fcs_import_crypto_service_key(uint64_t src_addr, uint32_t src_size,
229 uint32_t *mbox_error);
230int intel_fcs_export_crypto_service_key(uint32_t session_id, uint32_t key_id,
231 uint64_t dst_addr, uint32_t *dst_size,
232 uint32_t *mbox_error);
233int intel_fcs_remove_crypto_service_key(uint32_t session_id, uint32_t key_id,
234 uint32_t *mbox_error);
235int intel_fcs_get_crypto_service_key_info(uint32_t session_id, uint32_t key_id,
236 uint64_t dst_addr, uint32_t *dst_size,
237 uint32_t *mbox_error);
238
Sieu Mun Tangd907cc32022-05-10 17:24:05 +0800239int intel_fcs_get_digest_init(uint32_t session_id, uint32_t context_id,
240 uint32_t key_id, uint32_t param_size,
241 uint64_t param_data, uint32_t *mbox_error);
Sieu Mun Tang527df9f2022-04-28 16:28:48 +0800242int intel_fcs_get_digest_update_finalize(uint32_t session_id, uint32_t context_id,
Sieu Mun Tangd907cc32022-05-10 17:24:05 +0800243 uint32_t src_addr, uint32_t src_size,
244 uint64_t dst_addr, uint32_t *dst_size,
Sieu Mun Tang527df9f2022-04-28 16:28:48 +0800245 uint8_t is_finalised, uint32_t *mbox_error);
Sieu Mun Tangbd8da632022-09-28 15:58:28 +0800246int intel_fcs_get_digest_smmu_update_finalize(uint32_t session_id, uint32_t context_id,
247 uint32_t src_addr, uint32_t src_size,
248 uint64_t dst_addr, uint32_t *dst_size,
249 uint8_t is_finalised, uint32_t *mbox_error,
250 uint32_t *send_id);
Sieu Mun Tangd907cc32022-05-10 17:24:05 +0800251
Sieu Mun Tang583149a2022-05-10 17:27:12 +0800252int intel_fcs_mac_verify_init(uint32_t session_id, uint32_t context_id,
253 uint32_t key_id, uint32_t param_size,
254 uint64_t param_data, uint32_t *mbox_error);
Sieu Mun Tang527df9f2022-04-28 16:28:48 +0800255int intel_fcs_mac_verify_update_finalize(uint32_t session_id, uint32_t context_id,
Sieu Mun Tang583149a2022-05-10 17:27:12 +0800256 uint32_t src_addr, uint32_t src_size,
257 uint64_t dst_addr, uint32_t *dst_size,
Sieu Mun Tang527df9f2022-04-28 16:28:48 +0800258 uint32_t data_size, uint8_t is_finalised,
259 uint32_t *mbox_error);
Sieu Mun Tangbd8da632022-09-28 15:58:28 +0800260int intel_fcs_mac_verify_smmu_update_finalize(uint32_t session_id, uint32_t context_id,
261 uint32_t src_addr, uint32_t src_size,
262 uint64_t dst_addr, uint32_t *dst_size,
263 uint32_t data_size, uint8_t is_finalised,
264 uint32_t *mbox_error, uint32_t *send_id);
Sieu Mun Tang583149a2022-05-10 17:27:12 +0800265
Sieu Mun Tang8aa05ad2022-05-10 17:50:30 +0800266int intel_fcs_ecdsa_hash_sign_init(uint32_t session_id, uint32_t context_id,
267 uint32_t key_id, uint32_t param_size,
268 uint64_t param_data, uint32_t *mbox_error);
269int intel_fcs_ecdsa_hash_sign_finalize(uint32_t session_id, uint32_t context_id,
270 uint32_t src_addr, uint32_t src_size,
271 uint64_t dst_addr, uint32_t *dst_size,
272 uint32_t *mbox_error);
273
Sieu Mun Tang59357e82022-05-10 17:53:32 +0800274int intel_fcs_ecdsa_hash_sig_verify_init(uint32_t session_id, uint32_t context_id,
275 uint32_t key_id, uint32_t param_size,
276 uint64_t param_data, uint32_t *mbox_error);
277int intel_fcs_ecdsa_hash_sig_verify_finalize(uint32_t session_id, uint32_t context_id,
278 uint32_t src_addr, uint32_t src_size,
279 uint64_t dst_addr, uint32_t *dst_size,
280 uint32_t *mbox_error);
281
Sieu Mun Tang153ecfb2022-05-10 17:39:26 +0800282int intel_fcs_ecdsa_sha2_data_sign_init(uint32_t session_id,
283 uint32_t context_id, uint32_t key_id,
284 uint32_t param_size, uint64_t param_data,
285 uint32_t *mbox_error);
Sieu Mun Tange77d37d2022-04-28 16:23:20 +0800286int intel_fcs_ecdsa_sha2_data_sign_update_finalize(uint32_t session_id,
Sieu Mun Tang153ecfb2022-05-10 17:39:26 +0800287 uint32_t context_id, uint32_t src_addr,
288 uint32_t src_size, uint64_t dst_addr,
Sieu Mun Tange77d37d2022-04-28 16:23:20 +0800289 uint32_t *dst_size, uint8_t is_finalised,
290 uint32_t *mbox_error);
Sieu Mun Tangbd8da632022-09-28 15:58:28 +0800291int intel_fcs_ecdsa_sha2_data_sign_smmu_update_finalize(uint32_t session_id,
292 uint32_t context_id, uint32_t src_addr,
293 uint32_t src_size, uint64_t dst_addr,
294 uint32_t *dst_size, uint8_t is_finalised,
295 uint32_t *mbox_error, uint32_t *send_id);
Sieu Mun Tang153ecfb2022-05-10 17:39:26 +0800296
Sieu Mun Tangdcaab772022-05-11 10:16:40 +0800297int intel_fcs_ecdsa_sha2_data_sig_verify_init(uint32_t session_id,
298 uint32_t context_id, uint32_t key_id,
299 uint32_t param_size, uint64_t param_data,
300 uint32_t *mbox_error);
Sieu Mun Tange77d37d2022-04-28 16:23:20 +0800301int intel_fcs_ecdsa_sha2_data_sig_verify_update_finalize(uint32_t session_id,
Sieu Mun Tangdcaab772022-05-11 10:16:40 +0800302 uint32_t context_id, uint32_t src_addr,
303 uint32_t src_size, uint64_t dst_addr,
304 uint32_t *dst_size, uint32_t data_size,
Sieu Mun Tange77d37d2022-04-28 16:23:20 +0800305 uint8_t is_finalised, uint32_t *mbox_error);
Sieu Mun Tangbd8da632022-09-28 15:58:28 +0800306int intel_fcs_ecdsa_sha2_data_sig_verify_smmu_update_finalize(uint32_t session_id,
307 uint32_t context_id, uint32_t src_addr,
308 uint32_t src_size, uint64_t dst_addr,
309 uint32_t *dst_size, uint32_t data_size,
310 uint8_t is_finalised, uint32_t *mbox_error,
311 uint32_t *send_id);
Sieu Mun Tangdcaab772022-05-11 10:16:40 +0800312
Sieu Mun Tange2f3ede2022-05-10 17:36:32 +0800313int intel_fcs_ecdsa_get_pubkey_init(uint32_t session_id, uint32_t context_id,
314 uint32_t key_id, uint32_t param_size,
315 uint64_t param_data, uint32_t *mbox_error);
316int intel_fcs_ecdsa_get_pubkey_finalize(uint32_t session_id, uint32_t context_id,
317 uint64_t dst_addr, uint32_t *dst_size,
318 uint32_t *mbox_error);
319
Sieu Mun Tang0675c222022-05-10 17:48:11 +0800320int intel_fcs_ecdh_request_init(uint32_t session_id, uint32_t context_id,
321 uint32_t key_id, uint32_t param_size,
322 uint64_t param_data, uint32_t *mbox_error);
323int intel_fcs_ecdh_request_finalize(uint32_t session_id, uint32_t context_id,
324 uint32_t src_addr, uint32_t src_size,
325 uint64_t dst_addr, uint32_t *dst_size,
326 uint32_t *mbox_error);
327
Sieu Mun Tangb0c1d112022-05-10 17:30:00 +0800328int intel_fcs_aes_crypt_init(uint32_t session_id, uint32_t context_id,
329 uint32_t key_id, uint64_t param_addr,
330 uint32_t param_size, uint32_t *mbox_error);
Sieu Mun Tang9bea8152022-04-28 16:15:54 +0800331int intel_fcs_aes_crypt_update_finalize(uint32_t session_id,
332 uint32_t context_id, uint64_t src_addr,
333 uint32_t src_size, uint64_t dst_addr,
334 uint32_t dst_size, uint8_t is_finalised,
Sieu Mun Tangb0c1d112022-05-10 17:30:00 +0800335 uint32_t *send_id);
336
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800337#endif /* SOCFPGA_FCS_H */