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 
13 #ifndef LIBTEEC_TEE_CLIENT_APP_LOAD_H
14 #define LIBTEEC_TEE_CLIENT_APP_LOAD_H
15 
16 #include <stdint.h>
17 #include <stdio.h>
18 #include "tc_ns_client.h"
19 #include "tee_client_inner.h"
20 #include "tee_client_type.h"
21 
22 #define MAX_FILE_PATH_LEN 20
23 #define MAX_FILE_NAME_LEN 40
24 #define MAX_FILE_EXT_LEN  6
25 
26 #define MAX_IMAGE_LEN          0x800000 /* max image len */
27 #define MAX_SHARE_BUF_LEN      0x100000 /* max share buf len */
28 #define LOAD_IMAGE_FLAG_OFFSET 0x4
29 #define SEND_IMAGE_LEN         (MAX_SHARE_BUF_LEN - LOAD_IMAGE_FLAG_OFFSET)
30 
31 #define TA_HEAD_MAGIC1         0xA5A55A5A
32 #define TA_HEAD_MAGIC2         0x55AA
33 #define NUM_OF_RESERVED_BITMAP 16
34 
35 enum TA_VERSION {
36     TA_SIGN_VERSION        = 1, /* first version */
37     TA_RSA2048_VERSION     = 2, /* use rsa 2048, and use right crypt mode */
38     CIPHER_LAYER_VERSION   = 3,
39     CONFIG_SEGMENT_VERSION = 4,
40     TA_SIGN_VERSION_MAX
41 };
42 
43 /* start: keep same with tee */
44 typedef struct {
45     uint32_t contextLen;         /* manifest_crypto_len + cipher_bin_len */
46     uint32_t manifestCryptoLen;  /* manifest crypto len */
47     uint32_t manifestPlainLen;   /* manfiest str + manifest binary */
48     uint32_t manifestStrLen;     /* manifest str len */
49     uint32_t cipherBinLen;       /* cipher elf len */
50     uint32_t signLen;            /* sign file len, now rsa 2048 this len is 256 */
51 } TeecImageHead;
52 
53 typedef struct {
54     uint32_t magicNum1;
55     uint16_t magicNum2;
56     uint16_t versionNum;
57 } TeecImageIdentity;
58 
59 typedef struct {
60     TeecImageIdentity imgIdentity;
61     uint32_t contextLen;
62     uint32_t taKeyVersion;
63 } TaImageHdrV3;
64 
65 typedef struct {
66     TeecImageHead imgHd;
67     TeecImageIdentity imgIdentity;
68     uint8_t reserved[NUM_OF_RESERVED_BITMAP];
69 } TeecTaHead;
70 /* end */
71 
72 int32_t TEEC_GetApp(const TaFileInfo *taFile, const TEEC_UUID *srvUuid, TC_NS_ClientContext *cliContext);
73 int32_t TEEC_LoadSecfile(const char *filePath, int tzFd, FILE *fp);
74 
75 #endif
76