xref: /rk3399_rockchip-uboot/include/optee_include/OpteeClientInterface.h (revision 9deb34f60c696b35f58b914c019f52de1aa0d773)
1ae8ec5e1SHisping Lin /*
2ae8ec5e1SHisping Lin  * Copyright 2017, Rockchip Electronics Co., Ltd
3ae8ec5e1SHisping Lin  * hisping lin, <hisping.lin@rock-chips.com>
4ae8ec5e1SHisping Lin  *
5ae8ec5e1SHisping Lin  * SPDX-License-Identifier:	GPL-2.0+
6ae8ec5e1SHisping Lin  */
7ae8ec5e1SHisping Lin #ifndef _OPTEECLIENTTEST_H_
8ae8ec5e1SHisping Lin #define _OPTEECLIENTTEST_H_
9ae8ec5e1SHisping Lin 
1078ef5fbdSqiujian #include <optee_include/tee_client_api.h>
1178ef5fbdSqiujian 
1290e849a0Sxb.wang enum RK_OEM_OTP_KEYID {
1390e849a0Sxb.wang 	RK_OEM_OTP_KEY0 = 0,
1490e849a0Sxb.wang 	RK_OEM_OTP_KEY1 = 1,
1590e849a0Sxb.wang 	RK_OEM_OTP_KEY2 = 2,
1690e849a0Sxb.wang 	RK_OEM_OTP_KEY3 = 3,
172f8c34bdSxb.wang 	RK_OEM_OTP_KEY_FW = 10,	//keyid of fw_encryption_key
1890e849a0Sxb.wang 	RK_OEM_OTP_KEYMAX
19bb1ba6acSHisping Lin };
20bb1ba6acSHisping Lin 
21fc3694d6Sxb.wang /* Crypto mode */
22fc3694d6Sxb.wang enum RK_CIPIHER_MODE {
23fc3694d6Sxb.wang 	RK_CIPHER_MODE_ECB = 0,
24fc3694d6Sxb.wang 	RK_CIPHER_MODE_CBC = 1,
25fc3694d6Sxb.wang 	RK_CIPHER_MODE_CTS = 2,
26fc3694d6Sxb.wang 	RK_CIPHER_MODE_CTR = 3,
27fc3694d6Sxb.wang 	RK_CIPHER_MODE_CFB = 4,
28fc3694d6Sxb.wang 	RK_CIPHER_MODE_OFB = 5,
29fc3694d6Sxb.wang 	RK_CIPHER_MODE_XTS = 6,
30fc3694d6Sxb.wang 	RK_CIPHER_MODE_CCM = 7,
31fc3694d6Sxb.wang 	RK_CIPHER_MODE_GCM = 8,
32fc3694d6Sxb.wang 	RK_CIPHER_MODE_CMAC = 9,
33fc3694d6Sxb.wang 	RK_CIPHER_MODE_CBC_MAC = 10,
34fc3694d6Sxb.wang 	RK_CIPHER_MODE_MAX
35fc3694d6Sxb.wang };
36fc3694d6Sxb.wang 
37fc3694d6Sxb.wang /* Crypto algorithm */
38fc3694d6Sxb.wang enum RK_CRYPTO_ALGO {
39fc3694d6Sxb.wang 	RK_ALGO_AES = 1,
40fc3694d6Sxb.wang 	RK_ALGO_DES,
41fc3694d6Sxb.wang 	RK_ALGO_TDES,
42fc3694d6Sxb.wang 	RK_ALGO_SM4,
43fc3694d6Sxb.wang 	RK_ALGO_ALGO_MAX
44fc3694d6Sxb.wang };
45fc3694d6Sxb.wang 
46fc3694d6Sxb.wang typedef struct {
47fc3694d6Sxb.wang 	uint32_t	algo;
48fc3694d6Sxb.wang 	uint32_t	mode;
49fc3694d6Sxb.wang 	uint32_t	operation;
50fc3694d6Sxb.wang 	uint8_t		key[64];
51fc3694d6Sxb.wang 	uint32_t	key_len;
52fc3694d6Sxb.wang 	uint8_t		iv[16];
53fc3694d6Sxb.wang 	void		*reserved;
54fc3694d6Sxb.wang } rk_cipher_config;
55fc3694d6Sxb.wang 
56fc3694d6Sxb.wang /* Crypto operation */
57fc3694d6Sxb.wang #define RK_MODE_ENCRYPT			1
58fc3694d6Sxb.wang #define RK_MODE_DECRYPT			0
59fc3694d6Sxb.wang 
60fc3694d6Sxb.wang #define AES_BLOCK_SIZE			16
61fc3694d6Sxb.wang #define SM4_BLOCK_SIZE			16
62fc3694d6Sxb.wang #define RK_CRYPTO_MAX_DATA_LEN		(1 * 1024 * 1024)
63fc3694d6Sxb.wang 
642e40c2c1SJason Zhu #define ATAP_HEX_UUID_LEN 32
652e40c2c1SJason Zhu #define ATTEST_DH_SIZE     8
662e40c2c1SJason Zhu #define ATTEST_UUID_SIZE     (ATAP_HEX_UUID_LEN+1)
672e40c2c1SJason Zhu #define ATTEST_CA_OUT_SIZE     256
682e40c2c1SJason Zhu 
69ae8ec5e1SHisping Lin uint32_t trusty_read_rollback_index(uint32_t slot, uint64_t *value);
70ae8ec5e1SHisping Lin uint32_t trusty_write_rollback_index(uint32_t slot, uint64_t value);
71ae8ec5e1SHisping Lin uint32_t trusty_read_permanent_attributes(uint8_t *attributes, uint32_t size);
72ae8ec5e1SHisping Lin uint32_t trusty_write_permanent_attributes(uint8_t *attributes, uint32_t size);
73564654ebSJason Zhu uint32_t trusty_read_permanent_attributes_cer(uint8_t *attributes,
74564654ebSJason Zhu 					      uint32_t size);
75564654ebSJason Zhu uint32_t trusty_write_permanent_attributes_cer(uint8_t *attributes,
76564654ebSJason Zhu 					       uint32_t size);
77ae8ec5e1SHisping Lin uint32_t trusty_read_lock_state(uint8_t *lock_state);
78ae8ec5e1SHisping Lin uint32_t trusty_write_lock_state(uint8_t lock_state);
79ae8ec5e1SHisping Lin uint32_t trusty_read_flash_lock_state(uint8_t *flash_lock_state);
80ae8ec5e1SHisping Lin uint32_t trusty_write_flash_lock_state(uint8_t flash_lock_state);
8178ef5fbdSqiujian 
826ef445a4SHisping Lin uint32_t trusty_read_attribute_hash(uint32_t *buf, uint32_t length);
836ef445a4SHisping Lin uint32_t trusty_write_attribute_hash(uint32_t *buf, uint32_t length);
8416539616SHisping Lin uint32_t trusty_notify_optee_uboot_end(void);
852cd27853SHisping Lin uint32_t trusty_read_vbootkey_hash(uint32_t *buf, uint32_t length);
862cd27853SHisping Lin uint32_t trusty_write_vbootkey_hash(uint32_t *buf, uint32_t length);
87468df3b2SHisping Lin uint32_t trusty_read_vbootkey_enable_flag(uint8_t *flag);
881ef63c75SHisping Lin uint32_t trusty_write_ta_encryption_key(uint32_t *buf, uint32_t length);
89fbf29bfbSHisping Lin uint32_t trusty_check_security_level_flag(uint8_t flag);
90f39d4289SHisping Lin uint32_t trusty_write_oem_huk(uint32_t *buf, uint32_t length);
917504da74SHisping Lin void trusty_select_security_level(void);
92095e2a82SHisping Lin uint32_t trusty_read_permanent_attributes_flag(uint8_t *attributes);
93095e2a82SHisping Lin uint32_t trusty_write_permanent_attributes_flag(uint8_t attributes);
94d5913350SHisping Lin uint32_t trusty_write_oem_ns_otp(uint32_t byte_off, uint8_t *byte_buf, uint32_t byte_len);
95d5913350SHisping Lin uint32_t trusty_read_oem_ns_otp(uint32_t byte_off, uint8_t *byte_buf, uint32_t byte_len);
9690e849a0Sxb.wang uint32_t trusty_write_oem_otp_key(enum RK_OEM_OTP_KEYID key_id,
97bb1ba6acSHisping Lin 				  uint8_t *byte_buf, uint32_t byte_len);
98*9deb34f6SHisping Lin uint32_t trusty_oem_otp_key_is_written(enum RK_OEM_OTP_KEYID key_id, uint8_t *value);
9990e849a0Sxb.wang uint32_t trusty_set_oem_hr_otp_read_lock(enum RK_OEM_OTP_KEYID key_id);
1002f8c34bdSxb.wang uint32_t trusty_oem_otp_key_cipher(enum RK_OEM_OTP_KEYID key_id, rk_cipher_config *config,
1012f8c34bdSxb.wang 				   uint32_t src_phys_addr, uint32_t dst_phys_addr,
1022f8c34bdSxb.wang 				   uint32_t len);
1034aa61755SAndy Ye uint32_t trusty_attest_dh(uint8_t *dh, uint32_t *dh_size);
1044aa61755SAndy Ye uint32_t trusty_attest_uuid(uint8_t *uuid, uint32_t *uuid_size);
1054aa61755SAndy Ye uint32_t trusty_attest_get_ca
1064aa61755SAndy Ye 	(uint8_t *operation_start, uint32_t *operation_size,
1074aa61755SAndy Ye 	 uint8_t *out, uint32_t *out_len);
1084aa61755SAndy Ye uint32_t trusty_attest_set_ca(uint8_t *ca_response, uint32_t *ca_response_size);
10978ef5fbdSqiujian 
110ae8ec5e1SHisping Lin #endif
111