xref: /rk3399_ARM-atf/include/lib/psa/rse_crypto_defs.h (revision 79e7aae82dd173d1ccc63e5d553222f1d58f12f5)
1 /*
2  * Copyright (c) 2023-2024, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef RSE_CRYPTO_DEFS_H
9 #define RSE_CRYPTO_DEFS_H
10 
11 /* Declares types that encode errors, algorithms, key types, policies, etc. */
12 #include "psa/crypto_types.h"
13 
14 /* Value identifying random number generating API */
15 #define RSE_CRYPTO_GENERATE_RANDOM_SID		(uint16_t)(0x100)
16 
17 /*
18  * Value identifying export public key function API, used to dispatch the request
19  * to the corresponding API implementation in the Crypto service backend.
20  *
21  */
22 #define RSE_CRYPTO_EXPORT_PUBLIC_KEY_SID	(uint16_t)(0x206)
23 
24 /*
25  * The persistent key identifiers for RSE builtin keys.
26  */
27 enum rse_key_id_builtin_t {
28 	RSE_BUILTIN_KEY_ID_HOST_S_ROTPK = 0x7FFF816Cu,
29 	RSE_BUILTIN_KEY_ID_HOST_NS_ROTPK,
30 	RSE_BUILTIN_KEY_ID_HOST_CCA_ROTPK,
31 };
32 
33 /*
34  * This type is used to overcome a limitation within RSE firmware in the number of maximum
35  * IOVECs it can use especially in psa_aead_encrypt and psa_aead_decrypt.
36  */
37 #define RSE_CRYPTO_MAX_NONCE_LENGTH (16u)
38 struct rse_crypto_aead_pack_input {
39 	uint8_t nonce[RSE_CRYPTO_MAX_NONCE_LENGTH];
40 	uint32_t nonce_length;
41 };
42 
43 /*
44  * Structure used to pack non-pointer types in a call to PSA Crypto APIs
45  */
46 struct rse_crypto_pack_iovec {
47 	psa_key_id_t key_id;		/* !< Key id */
48 	psa_algorithm_t alg;		/* !< Algorithm */
49 	uint32_t op_handle;		/*
50 					 * !< Frontend context handle
51 					 * associated to a multipart operation
52 					 */
53 	uint32_t ad_length;		/*
54 					 * !< Additional Data length for
55 					 *    multipart AEAD
56 					 */
57 	uint32_t plaintext_length;	/*
58 					 * !< Plaintext length for multipart
59 					 *    AEAD
60 					 */
61 
62 	struct rse_crypto_aead_pack_input aead_in; /*
63 						    * !< Packs AEAD-related
64 						    *    inputs
65 						    */
66 
67 	uint16_t function_id;	/*
68 				 * !< Used to identify the function in the
69 				 *    API dispatcher to the service backend
70 				 *    See rse_crypto_func_sid for detail
71 				 */
72 	uint16_t step;		/* !< Key derivation step */
73 	union {
74 		size_t capacity;	/* !< Key derivation capacity */
75 		uint64_t value;		/*
76 					 * !< Key derivation integer for
77 					 *    update
78 					 */
79 	};
80 };
81 
82 #endif /* RSE_CRYPTO_DEFS_H */
83