• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #ifndef GTASK_TA_LOAD_KEY_H
13 #define GTASK_TA_LOAD_KEY_H
14 
15 #include <tee_defines.h>
16 #include "ta_verify_key.h"
17 
18 #define TAG_LEN 10
19 enum wb_tool_ver {
20     WB_TOOL_KEY_128 = 1, /* white box root key's len is 128 bits */
21     WB_TOOL_KEY_256, /* white box root key's len is 256 bits */
22 };
23 
24 struct wb_tool_key {
25     enum wb_tool_ver tool_ver;
26     const uint8_t *iv;
27     const uint32_t *table2;
28     uint32_t round_num;
29 };
30 
31 enum ta_type {
32     V1_TYPE = 1,
33     V2_TYPE, /* v2 ta's rsa key len is 2048bits */
34     V3_TYPE_2048, /* v3 ta's encrypt rsa key len is 2048bits */
35     V3_TYPE_3072, /* v3 ta's encrypt rsa key len is 3072bits */
36 };
37 
38 enum protect_type {
39     WB_KEY = 1,
40     ECIES_KEY,
41 };
42 
43 struct key_size_tag_info {
44     char key_len_tag[TAG_LEN];
45     enum verify_key_len key_len;
46 };
47 
48 struct key_style_tag_info {
49     char key_style_tag[TAG_LEN];
50     enum verify_key_style key_style;
51 };
52 
53 #define WB_2048_PRIV_LEN        144
54 #define WB_3072_PRIV_LEN        208
55 #define WB_PRIV_LEN             WB_3072_PRIV_LEN
56 
57 #define BYTE_LEN                8
58 #define PADDING_LEN             16
59 #define BASE_LEN                2
60 
61 #define WRAPPED_2048_PRIV_LEN   144
62 #define WRAPPED_2048_PUB_LEN_D  272
63 #define WRAPPED_3072_PRIV_LEN   208
64 #define WRAPPED_3072_PUB_LEN_D  400
65 
66 #define WRAPPED_PRIV_LEN        WRAPPED_3072_PRIV_LEN
67 #define WRAPPED_PUB_LEN_D       WRAPPED_3072_PUB_LEN_D
68 
69 struct wb_key_struct {
70     unsigned char wb_rsa_priv_p[WB_PRIV_LEN];
71     uint32_t wb_rsa_priv_p_len;
72     unsigned char wb_rsa_priv_q[WB_PRIV_LEN];
73     uint32_t wb_rsa_priv_q_len;
74     unsigned char wb_rsa_priv_dp[WB_PRIV_LEN];
75     uint32_t wb_rsa_priv_dp_len;
76     unsigned char wb_rsa_priv_dq[WB_PRIV_LEN];
77     uint32_t wb_rsa_priv_dq_len;
78     unsigned char wb_rsa_priv_qinv[WB_PRIV_LEN];
79     uint32_t wb_rsa_priv_qinv_len;
80 };
81 
82 #define ECC_PUB_SIZE      65
83 #define IV_LEN            16
84 #define WRAPPED_PUB_LEN_E 16
85 
86 struct ecies_key_struct {
87     unsigned char ecc_pub[ECC_PUB_SIZE];
88     unsigned char iv[IV_LEN];
89     unsigned char wrapped_rsa_priv_p[WRAPPED_PRIV_LEN];
90     uint32_t wrapped_rsa_priv_p_len;
91     unsigned char wrapped_rsa_priv_q[WRAPPED_PRIV_LEN];
92     uint32_t wrapped_rsa_priv_q_len;
93     unsigned char wrapped_rsa_priv_dq[WRAPPED_PRIV_LEN];
94     uint32_t wrapped_rsa_priv_dq_len;
95     unsigned char wrapped_rsa_priv_dp[WRAPPED_PRIV_LEN];
96     uint32_t wrapped_rsa_priv_dp_len;
97     unsigned char wrapped_rsa_priv_qinv[WRAPPED_PRIV_LEN];
98     uint32_t wrapped_rsa_priv_qinv_len;
99     unsigned char wrapped_rsa_pub_d[WRAPPED_PUB_LEN_D];
100     uint32_t wrapped_rsa_pub_d_len;
101     unsigned char wrapped_rsa_pub_e[WRAPPED_PUB_LEN_E];
102 };
103 
104 struct key_data {
105     enum protect_type pro_type;
106     enum ta_type ta_type;
107     uint8_t *key;
108     size_t key_len;
109 };
110 
111 struct key_protype_tag_info {
112     char key_type_str[TAG_LEN];
113     enum protect_type pro_type;
114 };
115 
116 struct key_type_tag_info {
117     char key_type_str[TAG_LEN];
118     enum ta_type ta_type;
119 };
120 
121 bool is_wb_protecd_ta_key(void);
122 TEE_Result get_ta_load_key(struct key_data *key);
123 TEE_Result query_ta_verify_pubkey(const struct ta_verify_key *all_key, size_t all_key_num,
124     struct ta_verify_key *query_key);
125 #endif
126