xref: /rk3399_ARM-atf/include/lib/psa/rse_crypto_defs.h (revision 697290a9166a4d62f757eeefcb7376817b0f0e4a)
13857898fSTamas Ban /*
23857898fSTamas Ban  * Copyright (c) 2023-2024, Arm Limited. All rights reserved.
33857898fSTamas Ban  *
43857898fSTamas Ban  * SPDX-License-Identifier: BSD-3-Clause
53857898fSTamas Ban  *
63857898fSTamas Ban  */
73857898fSTamas Ban 
8d797665cSTamas Ban #ifndef RSE_CRYPTO_DEFS_H
9d797665cSTamas Ban #define RSE_CRYPTO_DEFS_H
103857898fSTamas Ban 
113857898fSTamas Ban /* Declares types that encode errors, algorithms, key types, policies, etc. */
123857898fSTamas Ban #include "psa/crypto_types.h"
133857898fSTamas Ban 
14*1147a470SLeo Yan /* Value identifying random number generating API */
15*1147a470SLeo Yan #define RSE_CRYPTO_GENERATE_RANDOM_SID		(uint16_t)(0x100)
16*1147a470SLeo Yan 
173857898fSTamas Ban /*
183857898fSTamas Ban  * Value identifying export public key function API, used to dispatch the request
193857898fSTamas Ban  * to the corresponding API implementation in the Crypto service backend.
203857898fSTamas Ban  *
213857898fSTamas Ban  */
22759994aaSLeo Yan #define RSE_CRYPTO_EXPORT_PUBLIC_KEY_SID	(uint16_t)(0x206)
233857898fSTamas Ban 
243857898fSTamas Ban /*
25d797665cSTamas Ban  * The persistent key identifiers for RSE builtin keys.
263857898fSTamas Ban  */
27d797665cSTamas Ban enum rse_key_id_builtin_t {
28d797665cSTamas Ban 	RSE_BUILTIN_KEY_ID_HOST_S_ROTPK = 0x7FFF816Cu,
29d797665cSTamas Ban 	RSE_BUILTIN_KEY_ID_HOST_NS_ROTPK,
30d797665cSTamas Ban 	RSE_BUILTIN_KEY_ID_HOST_CCA_ROTPK,
313857898fSTamas Ban };
323857898fSTamas Ban 
333857898fSTamas Ban /*
34d797665cSTamas Ban  * This type is used to overcome a limitation within RSE firmware in the number of maximum
353857898fSTamas Ban  * IOVECs it can use especially in psa_aead_encrypt and psa_aead_decrypt.
363857898fSTamas Ban  */
37d797665cSTamas Ban #define RSE_CRYPTO_MAX_NONCE_LENGTH (16u)
38d797665cSTamas Ban struct rse_crypto_aead_pack_input {
39d797665cSTamas Ban 	uint8_t nonce[RSE_CRYPTO_MAX_NONCE_LENGTH];
403857898fSTamas Ban 	uint32_t nonce_length;
413857898fSTamas Ban };
423857898fSTamas Ban 
433857898fSTamas Ban /*
443857898fSTamas Ban  * Structure used to pack non-pointer types in a call to PSA Crypto APIs
453857898fSTamas Ban  */
46d797665cSTamas Ban struct rse_crypto_pack_iovec {
473857898fSTamas Ban 	psa_key_id_t key_id;		/* !< Key id */
483857898fSTamas Ban 	psa_algorithm_t alg;		/* !< Algorithm */
493857898fSTamas Ban 	uint32_t op_handle;		/*
503857898fSTamas Ban 					 * !< Frontend context handle
513857898fSTamas Ban 					 * associated to a multipart operation
523857898fSTamas Ban 					 */
533857898fSTamas Ban 	uint32_t ad_length;		/*
543857898fSTamas Ban 					 * !< Additional Data length for
553857898fSTamas Ban 					 *    multipart AEAD
563857898fSTamas Ban 					 */
573857898fSTamas Ban 	uint32_t plaintext_length;	/*
583857898fSTamas Ban 					 * !< Plaintext length for multipart
593857898fSTamas Ban 					 *    AEAD
603857898fSTamas Ban 					 */
613857898fSTamas Ban 
62d797665cSTamas Ban 	struct rse_crypto_aead_pack_input aead_in; /*
633857898fSTamas Ban 						    * !< Packs AEAD-related
643857898fSTamas Ban 						    *    inputs
653857898fSTamas Ban 						    */
663857898fSTamas Ban 
673857898fSTamas Ban 	uint16_t function_id;	/*
683857898fSTamas Ban 				 * !< Used to identify the function in the
693857898fSTamas Ban 				 *    API dispatcher to the service backend
70d797665cSTamas Ban 				 *    See rse_crypto_func_sid for detail
713857898fSTamas Ban 				 */
723857898fSTamas Ban 	uint16_t step;		/* !< Key derivation step */
733857898fSTamas Ban 	union {
743857898fSTamas Ban 		size_t capacity;	/* !< Key derivation capacity */
753857898fSTamas Ban 		uint64_t value;		/*
763857898fSTamas Ban 					 * !< Key derivation integer for
773857898fSTamas Ban 					 *    update
783857898fSTamas Ban 					 */
793857898fSTamas Ban 	};
803857898fSTamas Ban };
813857898fSTamas Ban 
82d797665cSTamas Ban #endif /* RSE_CRYPTO_DEFS_H */
83