Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | #include <mach/mt_sec_hal.h> |
2 | #include "sec_boot_lib.h" | |
3 | #include "sec_ccci.h" | |
4 | ||
5 | /************************************************************************** | |
6 | * MODULE NAME | |
7 | **************************************************************************/ | |
8 | #define MOD "SEC_CCCI" | |
9 | ||
10 | int masp_ccci_signfmt_verify_file(char *file_path, unsigned int *data_offset, unsigned int *data_sec_len) | |
11 | { | |
12 | unsigned int ret = SEC_OK; | |
13 | SEC_IMG_HEADER img_hdr; | |
14 | ||
15 | *data_offset = 0; | |
16 | *data_sec_len = 0; | |
17 | ||
18 | ret = sec_signfmt_verify_file(file_path, &img_hdr, data_offset, data_sec_len); | |
19 | ||
20 | /* image is not signed */ | |
21 | if( ret == ERR_SIGN_FORMAT_MAGIC_WRONG ) | |
22 | { | |
23 | if((sec_modem_auth_enabled() == 0) && (sec_schip_enabled() == 0)) | |
24 | { | |
25 | SMSG(true,"[%s] image has no sec header\n",MOD); | |
26 | ret = SEC_OK; | |
27 | goto _out; | |
28 | } | |
29 | else | |
30 | { | |
31 | SMSG(true,"[%s] (img not signed) sec_modem_auth_enabled() = %d\n",MOD,sec_modem_auth_enabled()); | |
32 | SMSG(true,"[%s] (img not signed) sec_schip_enabled() = %d\n",MOD,sec_schip_enabled()); | |
33 | ret = ERR_SIGN_FORMAT_MAGIC_WRONG; | |
34 | goto _out; | |
35 | } | |
36 | } | |
37 | ||
38 | if( ret != SEC_OK ) | |
39 | { | |
40 | SMSG(true,"[%s] file '%s' verify failed\n",MOD,file_path); | |
41 | goto _out; | |
42 | } | |
43 | ||
44 | SMSG(true,"[%s] data_offset is %d\n",MOD,*data_offset); | |
45 | SMSG(true,"[%s] data_sec_len is %d\n",MOD,*data_sec_len); | |
46 | ||
47 | _out: | |
48 | ||
49 | return ret; | |
50 | } | |
51 | ||
52 | int masp_ccci_version_info(void) | |
53 | { | |
54 | return CCCI_VERSION; | |
55 | } | |
56 | ||
57 | int sec_ccci_file_open(char *file_path) | |
58 | { | |
59 | int fp_id; | |
60 | ||
61 | fp_id = osal_filp_open_read_only(file_path); | |
62 | ||
63 | if(fp_id != OSAL_FILE_NULL) | |
64 | { | |
65 | return fp_id; | |
66 | } | |
67 | ||
68 | return -1; | |
69 | } | |
70 | ||
71 | int sec_ccci_file_close(int fp_id) | |
72 | { | |
73 | return osal_filp_close(fp_id); | |
74 | } | |
75 | ||
76 | ||
77 | int masp_ccci_is_cipherfmt(int fp_id, unsigned int start_off, unsigned int *img_len) | |
78 | { | |
79 | if( SEC_OK != sec_cipherfmt_check_cipher(fp_id, start_off, img_len) ) | |
80 | { | |
81 | *img_len = 0; | |
82 | return 0; | |
83 | } | |
84 | ||
85 | return 1; | |
86 | } | |
87 | ||
88 | int masp_ccci_decrypt_cipherfmt(int fp_id, unsigned int start_off, char *buf, unsigned int buf_len, unsigned int *data_offset) | |
89 | { | |
90 | return sec_cipherfmt_decrypted(fp_id, start_off, buf, buf_len, data_offset); | |
91 | } | |
92 | ||
93 | void masp_secure_algo(unsigned char Direction, unsigned int ContentAddr, unsigned int ContentLen, unsigned char *CustomSeed, unsigned char *ResText) | |
94 | { | |
95 | return masp_hal_secure_algo(Direction, ContentAddr, ContentLen, CustomSeed, ResText); | |
96 | } | |
97 | ||
98 | /* return the result of hwEnableClock ( ) | |
99 | - TRUE (1) means crypto engine init success | |
100 | - FALSE (0) means crypto engine init fail */ | |
101 | unsigned char masp_secure_algo_init(void) | |
102 | { | |
103 | return masp_hal_secure_algo_init(); | |
104 | } | |
105 | ||
106 | /* return the result of hwDisableClock ( ) | |
107 | - TRUE (1) means crypto engine de-init success | |
108 | - FALSE (0) means crypto engine de-init fail */ | |
109 | unsigned char masp_secure_algo_deinit(void) | |
110 | { | |
111 | return masp_hal_secure_algo_deinit(); | |
112 | } | |
113 | ||
114 |