hc
2024-08-19 a51341d8c7882adfad4f167bc7c3ca616908b53d
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
/*
 * Copyright 2017, Rockchip Electronics Co., Ltd
 * hisping lin, <hisping.lin@rock-chips.com>
 *
 * SPDX-License-Identifier:    GPL-2.0+
 */
#ifndef _OPTEECLIENTTEST_H_
#define _OPTEECLIENTTEST_H_
 
#include <optee_include/tee_client_api.h>
 
enum RK_OEM_OTP_KEYID {
   RK_OEM_OTP_KEY0 = 0,
   RK_OEM_OTP_KEY1 = 1,
   RK_OEM_OTP_KEY2 = 2,
   RK_OEM_OTP_KEY3 = 3,
   RK_OEM_OTP_KEY_FW = 10,    //keyid of fw_encryption_key
   RK_OEM_OTP_KEYMAX
};
 
enum RK_HDCP_KEYID {
   RK_HDCP_KEY0 = 0,
   RK_HDCP_KEY1 = 1,
   RK_HDCP_KEYMAX
};
 
/* Crypto mode */
enum RK_CIPIHER_MODE {
   RK_CIPHER_MODE_ECB = 0,
   RK_CIPHER_MODE_CBC = 1,
   RK_CIPHER_MODE_CTS = 2,
   RK_CIPHER_MODE_CTR = 3,
   RK_CIPHER_MODE_CFB = 4,
   RK_CIPHER_MODE_OFB = 5,
   RK_CIPHER_MODE_XTS = 6,
   RK_CIPHER_MODE_CCM = 7,
   RK_CIPHER_MODE_GCM = 8,
   RK_CIPHER_MODE_CMAC = 9,
   RK_CIPHER_MODE_CBC_MAC = 10,
   RK_CIPHER_MODE_MAX
};
 
/* Crypto algorithm */
enum RK_CRYPTO_ALGO {
   RK_ALGO_AES = 1,
   RK_ALGO_DES,
   RK_ALGO_TDES,
   RK_ALGO_SM4,
   RK_ALGO_ALGO_MAX
};
 
typedef struct {
   uint32_t    algo;
   uint32_t    mode;
   uint32_t    operation;
   uint8_t        key[64];
   uint32_t    key_len;
   uint8_t        iv[16];
   void        *reserved;
} rk_cipher_config;
 
/* Crypto operation */
#define RK_MODE_ENCRYPT            1
#define RK_MODE_DECRYPT            0
 
#define AES_BLOCK_SIZE            16
#define SM4_BLOCK_SIZE            16
#define RK_CRYPTO_MAX_DATA_LEN        (1 * 1024 * 1024)
 
#define ATAP_HEX_UUID_LEN 32
#define ATTEST_DH_SIZE     8
#define ATTEST_UUID_SIZE     (ATAP_HEX_UUID_LEN+1)
#define ATTEST_CA_OUT_SIZE     256
 
void optee_client_init(void);
uint32_t trusty_read_rollback_index(uint32_t slot, uint64_t *value);
uint32_t trusty_write_rollback_index(uint32_t slot, uint64_t value);
uint32_t trusty_read_permanent_attributes(uint8_t *attributes, uint32_t size);
uint32_t trusty_write_permanent_attributes(uint8_t *attributes, uint32_t size);
uint32_t trusty_read_permanent_attributes_cer(uint8_t *attributes,
                         uint32_t size);
uint32_t trusty_write_permanent_attributes_cer(uint8_t *attributes,
                          uint32_t size);
uint32_t trusty_read_lock_state(uint8_t *lock_state);
uint32_t trusty_write_lock_state(uint8_t lock_state);
uint32_t trusty_read_flash_lock_state(uint8_t *flash_lock_state);
uint32_t trusty_write_flash_lock_state(uint8_t flash_lock_state);
 
uint32_t trusty_read_attribute_hash(uint32_t *buf, uint32_t length);
uint32_t trusty_write_attribute_hash(uint32_t *buf, uint32_t length);
uint32_t trusty_notify_optee_uboot_end(void);
uint32_t trusty_read_vbootkey_hash(uint32_t *buf, uint32_t length);
uint32_t trusty_write_vbootkey_hash(uint32_t *buf, uint32_t length);
uint32_t trusty_read_vbootkey_enable_flag(uint8_t *flag);
uint32_t trusty_write_ta_encryption_key(uint32_t *buf, uint32_t length);
uint32_t trusty_ta_encryption_key_is_written(uint8_t *value);
uint32_t trusty_write_oem_encrypt_data(uint32_t *buf, uint32_t length);
uint32_t trusty_oem_encrypt_data_is_written(uint8_t *value);
uint32_t trusty_check_security_level_flag(uint8_t flag);
uint32_t trusty_write_oem_huk(uint32_t *buf, uint32_t length);
uint32_t trusty_read_permanent_attributes_flag(uint8_t *attributes);
uint32_t trusty_write_permanent_attributes_flag(uint8_t attributes);
uint32_t trusty_write_oem_ns_otp(uint32_t byte_off, uint8_t *byte_buf, uint32_t byte_len);
uint32_t trusty_read_oem_ns_otp(uint32_t byte_off, uint8_t *byte_buf, uint32_t byte_len);
uint32_t trusty_write_oem_otp_key(enum RK_OEM_OTP_KEYID key_id,
                 uint8_t *byte_buf, uint32_t byte_len);
uint32_t trusty_oem_otp_key_is_written(enum RK_OEM_OTP_KEYID key_id, uint8_t *value);
uint32_t trusty_set_oem_hr_otp_read_lock(enum RK_OEM_OTP_KEYID key_id);
uint32_t trusty_oem_otp_key_cipher(enum RK_OEM_OTP_KEYID key_id, rk_cipher_config *config,
                  uint32_t src_phys_addr, uint32_t dst_phys_addr,
                  uint32_t len);
uint32_t trusty_oem_user_ta_transfer(void);
uint32_t trusty_oem_user_ta_storage(void);
uint32_t trusty_write_oem_hdcp_key(enum RK_HDCP_KEYID key_id,
                 uint8_t *byte_buf, uint32_t byte_len);
uint32_t trusty_oem_hdcp_key_is_written(enum RK_HDCP_KEYID key_id, uint8_t *value);
uint32_t trusty_set_oem_hdcp_key_mask(enum RK_HDCP_KEYID key_id);
uint32_t trusty_attest_dh(uint8_t *dh, uint32_t *dh_size);
uint32_t trusty_attest_uuid(uint8_t *uuid, uint32_t *uuid_size);
uint32_t trusty_attest_get_ca
   (uint8_t *operation_start, uint32_t *operation_size,
    uint8_t *out, uint32_t *out_len);
uint32_t trusty_attest_set_ca(uint8_t *ca_response, uint32_t *ca_response_size);
 
#endif