blob: fe4387824fd599c4d6ec2dc73bd747aba096e1c3 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 * Filename:
38 * ---------
39 * custom_nvram_sec.h
40 *
41 * Project:
42 * --------
43 * MAUI
44 *
45 * Description:
46 * ------------
47 * This file is intends for NVRAM security customization.
48 *
49 * Author:
50 * -------
51 * -------
52 *
53 *==============================================================================
54 * HISTORY
55 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
56 *------------------------------------------------------------------------------
57 * removed!
58 *
59 * removed!
60 * removed!
61 * removed!
62 *
63 * removed!
64 * removed!
65 *
66 * removed!
67 * removed!
68 * removed!
69 *
70 * removed!
71 * removed!
72 *
73 * removed!
74 * removed!
75 * removed!
76 *
77 * removed!
78 * removed!
79 *
80 * removed!
81 * removed!
82 * removed!
83 *
84 * removed!
85 * removed!
86 * removed!
87 *
88 * removed!
89 * removed!
90 * removed!
91 *
92 * removed!
93 * removed!
94 * removed!
95 *
96 * removed!
97 * removed!
98 * removed!
99 *
100 * removed!
101 * removed!
102 * removed!
103 *
104 * removed!
105 * removed!
106 * removed!
107 *
108 * removed!
109 * removed!
110 * removed!
111 *
112 * removed!
113 * removed!
114 * removed!
115 * removed!
116 *
117 * removed!
118 * removed!
119 * removed!
120 *
121 * removed!
122 * removed!
123 * removed!
124 *
125 * removed!
126 * removed!
127 * removed!
128 *
129 * removed!
130 * removed!
131 *
132 * removed!
133 * removed!
134 * removed!
135 * removed!
136 *
137 * removed!
138 * removed!
139 * removed!
140 *
141 * removed!
142 * removed!
143 * removed!
144 *
145 * removed!
146 * removed!
147 * removed!
148 *
149 * removed!
150 * removed!
151 * removed!
152 *
153 * removed!
154 * removed!
155 * removed!
156 *
157 * removed!
158 * removed!
159 * removed!
160 *
161 * removed!
162 * removed!
163 * removed!
164 *
165 * removed!
166 * removed!
167 * removed!
168 *
169 * removed!
170 * removed!
171 * removed!
172 *
173 * removed!
174 * removed!
175 * removed!
176 * removed!
177 * removed!
178 * removed!
179 * removed!
180 *
181 * removed!
182 * removed!
183 * removed!
184 *
185 * removed!
186 * removed!
187 * removed!
188 *
189 * removed!
190 * removed!
191 * removed!
192 *
193 * removed!
194 * removed!
195 * removed!
196 *
197 * removed!
198 * removed!
199 * removed!
200 *
201 * removed!
202 * removed!
203 * removed!
204 *
205 * removed!
206 * removed!
207 * removed!
208 *
209 * removed!
210 * removed!
211 * removed!
212 *
213 * removed!
214 * removed!
215 * removed!
216 *
217 * removed!
218 * removed!
219 *
220 *
221 * removed!
222 * removed!
223 *
224 *
225 * removed!
226 * removed!
227 *
228 *
229 * removed!
230 * removed!
231 *
232 *
233 * removed!
234 * removed!
235 *
236 *
237 * removed!
238 * removed!
239 *
240 *
241 * removed!
242 * removed!
243 *
244 *
245 * removed!
246 * removed!
247 *
248 *
249 * removed!
250 * removed!
251 *
252 *
253 * removed!
254 * removed!
255 *
256 *
257 * removed!
258 * removed!
259 *
260 *
261 * removed!
262 * removed!
263 *
264 *
265 * removed!
266 * removed!
267 *
268 *
269 * removed!
270 * removed!
271 *
272 *
273 * removed!
274 * removed!
275 *
276 *
277 * removed!
278 * removed!
279 *
280 *
281 * removed!
282 * removed!
283 * removed!
284 *
285 * removed!
286 * removed!
287 *
288 *
289 * removed!
290 * removed!
291 *
292 *
293 * removed!
294 * removed!
295 *
296 *
297 * removed!
298 * removed!
299 *
300 *
301 *------------------------------------------------------------------------------
302 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
303 *==============================================================================
304 *******************************************************************************/
305#ifndef CUSTOM_NVRAM_SEC_H
306#define CUSTOM_NVRAM_SEC_H
307
308#include "kal_general_types.h"
309#include "sml_public_def.h"
310
311#include "sml_nvram_ver.h"
312
313typedef enum
314{
315 NVRAM_MD5 = 1, /* MD5 */
316 NVRAM_HMAC_SHA256 /* HMAC SHA256 */
317
318} NVRAM_ALGO_TYPE;
319
320typedef struct
321{
322 kal_uint32 enhance_algo_size;
323 kal_uint32 enhance_algo_type;
324 kal_uint32 default_algo_size;
325 kal_uint32 default_algo_type;
326} nvram_checksum_config;
327
328typedef struct
329{
330 kal_uint8 security_indication;
331 kal_uint8 phone_key[NVRAM_EDITOR_NUM_OF_BYTE_KEY];
332 kal_uint8 last_imsi[NVRAM_EDITOR_NUM_OF_BYTE_IMSI];
333 kal_uint8 pin1[NVRAM_EDITOR_NUM_PIN1];
334 kal_uint8 pin1_valid;
335 kal_uint8 phone_lock_verified;
336 kal_uint8 iccid[NVRAM_EDITOR_NUM_OF_BYTE_ICCID];
337} smu_security_info_struct;
338
339/* --------------------------
340 * Beginning of SML Configuration
341 * --------------------------- */
342#define NVRAM_SECRET_KEY_SIZE 8
343#define NVRAM_CUSTOM_KEY_SEED_SIZE 32
344
345/* General control key structure */
346typedef struct {
347 kal_uint8 state; /* Default Value or NULL */
348 kal_uint8 key[NVRAM_SML_MAX_SUPPORT_KEY_LEN]; //actual data length is SML_MAX_SUPPORT_KEY_LEN
349} sml_control_key_struct;
350
351/* General lock structure */
352typedef struct {
353 kal_uint8 state; /* sml_state_enum */
354 kal_uint8 retry_count; /* SML_RETRY_COUNT_X_CAT */
355 kal_uint8 autolock_count; /* SML_AUTOLOCK_NUM_X_CAT */
356 kal_uint8 num; /* num of valid sets */
357} sml_category_meta_struct;
358
359typedef struct {
360 kal_uint32 magic_head; /* 4 */
361 sml_category_meta_struct cat[SML_SUPPORT_CAT_SIZE]; /* (4 * 7) */
362 sml_control_key_struct key[SML_SUPPORT_CAT_SIZE]; /* (9 * 7) */
363 kal_uint8 code_cat_n[SML_CFG_CAT_N_SIZE]; /* (30 * 3)*/
364 kal_uint8 code_cat_ns[SML_CFG_CAT_NS_SIZE]; /* (30 * 4)*/
365 kal_uint8 code_cat_sp[SML_CFG_CAT_SP_SIZE]; /* (30 * 4)*/
366 kal_uint8 code_cat_c[SML_CFG_CAT_C_SIZE]; /* (30 * 5)*/
367 kal_uint8 code_cat_sim[SML_CFG_CAT_SIM_SIZE]; /* (30 * 8)*/
368 kal_uint8 code_cat_ns_sp[SML_CFG_CAT_NS_SP_SIZE]; /* (5 * 10)*/
369 kal_uint8 code_cat_sim_c[SML_CFG_CAT_SIM_C_SIZE]; /* (10 * 10)*/
370 kal_uint8 range_cat_ns[SML_CAT_NS_RANGE_SIZE]; /* 2 */
371 kal_uint32 magic_tail; /* 4 */
372} sml_context_struct; /* 971 */
373typedef sml_context_struct nvram_sml_context_struct;
374
375typedef struct {
376 kal_uint8 state; /* Default Value or NULL */
377 kal_uint8 algo;
378 kal_uint8 salt[NVRAM_SML_S_MAX_SUPPORT_SALT_LEN];
379 kal_uint8 inter_cnt[NVRAM_SML_S_MAX_SUPPORT_INTER_CNT_LEN];
380 kal_uint8 key[NVRAM_SML_S_MAX_SUPPORT_HCK_LEN];
381} sml_control_key_s_struct;
382
383#if SML_S_LID_VER >= 2
384typedef struct {
385 kal_uint8 state; // sml_puk_key_state_enum
386 kal_uint32 max_retry_count;
387 kal_uint32 retry_count;
388
389 kal_uint8 algo;
390 kal_uint8 salt[NVRAM_SML_S_MAX_SUPPORT_SALT_LEN];
391 kal_uint8 iter_cnt[NVRAM_SML_S_MAX_SUPPORT_INTER_CNT_LEN];
392 kal_uint8 key[NVRAM_SML_S_MAX_SUPPORT_HCK_LEN];
393} sml_puk_key_s_struct;
394#endif
395
396typedef struct {
397 kal_uint8 state; /* sml_state_enum */
398 kal_uint32 max_retry_count; /* SML_MAX_RETRY_COUNT_X_CAT */
399 kal_uint32 retry_count; /* SML_RETRY_COUNT_X_CAT */
400 kal_uint8 autolock_count; /* SML_AUTOLOCK_NUM_X_CAT */
401 kal_uint8 num; /* num of valid sets */
402} sml_category_meta_s_struct;
403
404typedef struct {
405 kal_uint32 magic_head;
406 sml_category_meta_s_struct cat[SML_SUPPORT_CAT_SIZE];
407 sml_control_key_s_struct key[SML_SUPPORT_CAT_SIZE];
408#if SML_S_LID_VER >= 2
409 sml_puk_key_s_struct puk_key[SML_SUPPORT_CAT_SIZE];
410#endif
411 kal_uint8 code_cat_n[SML_CFG_CAT_N_SIZE];
412 kal_uint8 code_cat_ns[SML_CFG_CAT_NS_SIZE];
413 kal_uint8 code_cat_sp[SML_CFG_CAT_SP_SIZE];
414 kal_uint8 code_cat_c[SML_CFG_CAT_C_SIZE];
415 kal_uint8 code_cat_sim[SML_CFG_CAT_SIM_SIZE];
416 kal_uint8 code_cat_ns_sp[SML_CFG_CAT_NS_SP_SIZE];
417 kal_uint8 code_cat_sim_c[SML_CFG_CAT_SIM_C_SIZE];
418 kal_uint8 range_cat_ns[SML_CAT_NS_RANGE_SIZE];
419 kal_uint32 magic_tail;
420} sml_context_s_struct;
421typedef sml_context_s_struct nvram_sml_context_s_struct;
422
423typedef struct
424{
425 kal_uint8 data[3072];
426} smu_op129_sim_lock_rawdata_struct;
427typedef smu_op129_sim_lock_rawdata_struct nvram_sml_op129_sim_lock_rawdata_struct;
428
429/* the magic number of file header and tail */
430#define SML_MAGIC_HEAD_VALUE (sizeof(sml_context_struct))
431#define SML_MAGIC_TAIL_VALUE 0x26598088
432
433/* --------------------------
434 * End of SML Configuration
435 * --------------------------- */
436
437#if !defined(NVRAM_NOT_PRESENT)
438#ifdef __cplusplus
439extern "C"
440{
441#endif /* __cplusplus */
442
443#include "nvram_defs.h" /* NVRAM_MSP_ALIGNMENT */
444
445/*
446 * CUST PARA Configuration
447 */
448
449
450/*
451 * Secure RO Version
452 * Whenever nvram_sml_context_struct's size or members are changed,
453 * be sure to assign an unique version number to SEC_RO_STRUCT_VER.
454 * Otherwise, PC side tool has no idea how to compose it
455 */
456#ifndef __SECURE_USB_DOWNLOAD__
457#define SEC_RO_STRUCT_VER 1
458#else
459#define SEC_RO_STRUCT_VER 2
460#endif
461
462/*
463 * Secure RO
464 */
465typedef enum
466{
467 SEC_RO_PARA_DBG_PORT,
468 SEC_RO_PARA_TOTAL
469}sec_ro_para_enum;
470
471extern const kal_uint8 NVRAM_SECUPACK_DEFAULT[];
472extern const kal_uint8 NVRAM_CUSTOM_KEY[];
473extern const kal_uint8 NVRAM_CUSTOM_KEY_SEED[];
474
475extern kal_uint32 secupack_total_to_verify;
476extern void custom_nvram_get_key(char *init_key, unsigned char *keys);
477extern void custom_nvram_encrypt(unsigned char const *keys, unsigned char *buffer, unsigned int length, int scrambleIndex);
478extern void custom_nvram_decrypt(unsigned char const *keys, unsigned char *buffer, unsigned int length, int scrambleIndex);
479extern void nvram_AES_encrypt(unsigned char *buffer, unsigned int length);
480extern void nvram_AES_decrypt(unsigned char *buffer, unsigned int length);
481extern void nvram_calculate_checksum(NVRAM_ALGO_TYPE type, kal_uint8 *source, kal_uint32 source_length, kal_uint8 *dest);
482
483extern kal_uint32 custom_nvram_sec_ro_size(void);
484extern kal_uint32 custom_nvram_secupack_size(void);
485extern kal_uint32 custom_nvram_secupack_total(void);
486extern kal_uint32 custom_nvram_key_len(void);
487
488extern nvram_lid_enum custom_nvram_get_signed_critical_data_lid();
489extern kal_bool custom_nvram_check_signed_critical_data_before_write(kal_uint8 *wr_dat, kal_uint32 len);
490extern kal_bool custom_nvram_read_and_check_signed_critical_data();
491
492#if defined(NVRAM_AUTO_GEN)
493extern const nvram_sml_context_struct NVRAM_EF_SML_DEFAULT;
494extern const nvram_sml_context_s_struct NVRAM_EF_SML_S_DEFAULT;
495extern const kal_uint8 custom_secret_key[];
496extern const kal_uint8 custom_key_seed[];
497extern const kal_uint8 NVRAM_SECURE_PARA[];
498#ifdef __SECURE_USB_DOWNLOAD__
499extern const kal_uint8 custom_symmetric_key[];
500extern const T_Customer_Public_Key custom_asymmetric_key;
501#endif
502#endif
503
504
505#ifdef __cplusplus
506}
507#endif
508#endif /* !defined(NVRAM_NOT_PRESENT) */
509#endif /* CUSTOM_NVRAM_SEC_H */
510