• 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 TEE_ELF_VERIFY_OPENSSL_H
13 #define TEE_ELF_VERIFY_OPENSSL_H
14 
15 #include "tee_defines.h"
16 #include "tee_perm_img.h"
17 #include "ta_load_key.h"
18 #include <openssl/rsa.h>
19 
20 #define AES_KEY_LEN         32
21 #define RSA_PRIV_SIZE       257
22 #define ECIES_PUB_LEN       65
23 #define ECIES_PRIV_LEN      32
24 #define ECIES_PRIV_ORIG_LEN 193
25 
26 #define WITH_ZERO    65
27 #define WITHOUT_ZERO 64
28 #define RESULT1      320
29 
30 struct rsa_priv_key {
31     uint8_t p[RSA_PRIV_SIZE];
32     uint32_t p_size;
33     uint8_t q[RSA_PRIV_SIZE];
34     uint32_t q_size;
35     uint8_t dq[RSA_PRIV_SIZE];
36     uint32_t dq_size;
37     uint8_t dp[RSA_PRIV_SIZE];
38     uint32_t dp_size;
39     uint8_t qinv[RSA_PRIV_SIZE];
40     uint32_t qinv_size;
41     uint8_t d[WRAPPED_PUB_LEN_D];
42     uint32_t d_size;
43     uint8_t e[WRAPPED_PUB_LEN_E];
44     uint32_t e_size;
45 };
46 
47 struct ecc_derive_data_st {
48     const uint8_t *ec1_priv;
49     uint32_t ec1_len;
50     const uint8_t *ec2_pub;
51     uint32_t ec2_len;
52 };
53 
54 TEE_Result tee_secure_img_decrypt_cipher_layer(const uint8_t *cipher_layer, uint32_t cipher_size,
55     uint8_t *plaintext_layer, uint32_t *plaintext_size);
56 RSA *get_ta_verify_key(void);
57 int32_t aes_cbc_256_decrypt(const uint8_t *key, const uint8_t *iv,
58     const uint8_t *in, uint32_t in_len, uint8_t *out);
59 int32_t ecies_kem_decrypt(const struct ecc_derive_data_st *ecc_data, uint8_t *key, uint32_t key_len);
60 const struct ecies_key_struct *get_ecies_key_data(int32_t img_version, enum ta_type type);
61 TEE_Result get_rsa_priv_aes_key(const struct ecies_key_struct *ecies_key_data, uint8_t *key_buff,
62     uint32_t buff_size);
63 TEE_Result aes_decrypt_rsa_private(const struct ecies_key_struct *ecies_data, const uint8_t *aes_key,
64     uint32_t key_size, struct rsa_priv_key *priv);
65 TEE_Result get_key_data(int32_t img_version, struct key_data *key_data);
66 #endif
67 
68