1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __BOOT_UPG_CHECK_SECURE_H__ 17 #define __BOOT_UPG_CHECK_SECURE_H__ 18 19 #include <boot_upg_common.h> 20 21 #define RSA_2048_LEN 256 22 #define RSA_KEY_LEN 512 23 #define ECC_KEY_LEN 64 24 #define ECC_256_LEN 32 25 26 #if defined(CONFIG_FLASH_ENCRYPT_SUPPORT) 27 #define FLASH_ADDR_NUM 3 28 #define TOTAL_SIZE_NUM 3 29 #define FLASH_FLAG_NUM 3 30 #else 31 #define FLASH_ADDR_NUM 2 32 #define TOTAL_SIZE_NUM 2 33 #define FLASH_FLAG_NUM 2 34 #endif 35 36 #define UPG_SEC_BOOT_FLAG 0x42 37 38 extern hi_u32 __data_start; 39 extern hi_u32 __data_load; 40 41 typedef enum { 42 HI_MODE_PKCS_V15 = 0x00, 43 HI_MODE_PKCS_PSS = 0x01, 44 HI_MODE_ECC = 0x10, 45 } hi_padding_mode; 46 47 typedef struct { 48 uintptr_t flash_addr[FLASH_ADDR_NUM]; 49 uintptr_t total_size[TOTAL_SIZE_NUM]; 50 hi_u32 buffer_count; 51 hi_bool flash_flag[FLASH_FLAG_NUM]; 52 hi_u16 pad; 53 hi_u8 *key_n; 54 hi_u8 *key_e; 55 hi_u8 *sign; 56 hi_u32 key_len; 57 hi_padding_mode pad_mode; 58 } upg_verify_param; 59 60 hi_bool boot_upg_is_secure_efuse(hi_void); 61 hi_u32 boot_upg_check_secure_info(hi_u32 flash_addr, hi_upg_head *upg_head); 62 hi_u32 boot_upg_check_unsecure_info(hi_u32 flash_addr, hi_upg_head *upg_head); 63 hi_void boot_upg_save_key_pos(hi_void); 64 hi_u32 boot_upg_secure_verify_head(hi_upg_head *upg_head); 65 hi_u32 boot_upg_unsecure_verify_head(hi_upg_head *upg_head); 66 67 #endif 68 69