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