rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 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! |
rjw | 8e44aab | 2022-11-30 16:42:16 +0800 | [diff] [blame^] | 62 | * removed! |
| 63 | * |
| 64 | * removed! |
| 65 | * removed! |
| 66 | * removed! |
rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 67 | * |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * removed! |
| 74 | * |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * |
| 85 | * removed! |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * |
| 89 | * removed! |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * |
| 93 | * removed! |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * |
| 97 | * removed! |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * |
| 101 | * removed! |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * |
| 109 | * removed! |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * removed! |
| 116 | * |
| 117 | * removed! |
| 118 | * removed! |
| 119 | * removed! |
| 120 | * removed! |
| 121 | * |
| 122 | * removed! |
| 123 | * removed! |
| 124 | * removed! |
| 125 | * |
| 126 | * removed! |
| 127 | * removed! |
| 128 | * removed! |
| 129 | * |
| 130 | * removed! |
| 131 | * removed! |
| 132 | * removed! |
| 133 | * |
| 134 | * removed! |
| 135 | * removed! |
| 136 | * |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * removed! |
| 140 | * removed! |
| 141 | * |
| 142 | * removed! |
| 143 | * removed! |
| 144 | * removed! |
| 145 | * |
| 146 | * removed! |
| 147 | * removed! |
| 148 | * removed! |
| 149 | * |
| 150 | * removed! |
| 151 | * removed! |
| 152 | * removed! |
| 153 | * |
| 154 | * removed! |
| 155 | * removed! |
| 156 | * removed! |
| 157 | * |
| 158 | * removed! |
| 159 | * removed! |
| 160 | * removed! |
| 161 | * |
| 162 | * removed! |
| 163 | * removed! |
| 164 | * removed! |
| 165 | * |
| 166 | * removed! |
| 167 | * removed! |
| 168 | * removed! |
| 169 | * |
| 170 | * removed! |
| 171 | * removed! |
| 172 | * removed! |
| 173 | * |
| 174 | * removed! |
| 175 | * removed! |
| 176 | * removed! |
| 177 | * |
| 178 | * removed! |
| 179 | * removed! |
| 180 | * removed! |
| 181 | * removed! |
| 182 | * removed! |
| 183 | * removed! |
| 184 | * removed! |
| 185 | * |
| 186 | * removed! |
| 187 | * removed! |
| 188 | * removed! |
| 189 | * |
| 190 | * removed! |
| 191 | * removed! |
| 192 | * removed! |
| 193 | * |
| 194 | * removed! |
| 195 | * removed! |
| 196 | * removed! |
| 197 | * |
| 198 | * removed! |
| 199 | * removed! |
| 200 | * removed! |
| 201 | * |
| 202 | * removed! |
| 203 | * removed! |
| 204 | * removed! |
| 205 | * |
| 206 | * removed! |
| 207 | * removed! |
| 208 | * removed! |
| 209 | * |
| 210 | * removed! |
| 211 | * removed! |
| 212 | * removed! |
| 213 | * |
| 214 | * removed! |
| 215 | * removed! |
| 216 | * removed! |
| 217 | * |
| 218 | * removed! |
| 219 | * removed! |
| 220 | * removed! |
| 221 | * |
| 222 | * removed! |
| 223 | * removed! |
| 224 | * |
| 225 | * |
| 226 | * removed! |
| 227 | * removed! |
| 228 | * |
| 229 | * |
| 230 | * removed! |
| 231 | * removed! |
| 232 | * |
| 233 | * |
| 234 | * removed! |
| 235 | * removed! |
| 236 | * |
| 237 | * |
| 238 | * removed! |
| 239 | * removed! |
| 240 | * |
| 241 | * |
| 242 | * removed! |
| 243 | * removed! |
| 244 | * |
| 245 | * |
| 246 | * removed! |
| 247 | * removed! |
| 248 | * |
| 249 | * |
| 250 | * removed! |
| 251 | * removed! |
| 252 | * |
| 253 | * |
| 254 | * removed! |
| 255 | * removed! |
| 256 | * |
| 257 | * |
| 258 | * removed! |
| 259 | * removed! |
| 260 | * |
| 261 | * |
| 262 | * removed! |
| 263 | * removed! |
| 264 | * |
| 265 | * |
| 266 | * removed! |
| 267 | * removed! |
| 268 | * |
| 269 | * |
| 270 | * removed! |
| 271 | * removed! |
| 272 | * |
| 273 | * |
| 274 | * removed! |
| 275 | * removed! |
| 276 | * |
| 277 | * |
| 278 | * removed! |
| 279 | * removed! |
| 280 | * |
| 281 | * |
| 282 | * removed! |
| 283 | * removed! |
| 284 | * |
| 285 | * |
| 286 | * removed! |
| 287 | * removed! |
| 288 | * removed! |
| 289 | * |
| 290 | * removed! |
| 291 | * removed! |
| 292 | * |
| 293 | * |
| 294 | * removed! |
| 295 | * removed! |
| 296 | * |
| 297 | * |
| 298 | * removed! |
| 299 | * removed! |
| 300 | * |
| 301 | * |
| 302 | * removed! |
| 303 | * removed! |
| 304 | * |
| 305 | * |
| 306 | *------------------------------------------------------------------------------ |
| 307 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 308 | *============================================================================== |
| 309 | *******************************************************************************/ |
| 310 | #ifndef CUSTOM_NVRAM_SEC_H |
| 311 | #define CUSTOM_NVRAM_SEC_H |
| 312 | |
| 313 | #include "kal_general_types.h" |
| 314 | #include "sml_public_def.h" |
| 315 | |
| 316 | #include "sml_nvram_ver.h" |
| 317 | |
| 318 | typedef enum |
| 319 | { |
| 320 | NVRAM_MD5 = 1, /* MD5 */ |
| 321 | NVRAM_HMAC_SHA256 /* HMAC SHA256 */ |
| 322 | |
| 323 | } NVRAM_ALGO_TYPE; |
| 324 | |
| 325 | typedef struct |
| 326 | { |
| 327 | kal_uint32 enhance_algo_size; |
| 328 | kal_uint32 enhance_algo_type; |
| 329 | kal_uint32 default_algo_size; |
| 330 | kal_uint32 default_algo_type; |
| 331 | } nvram_checksum_config; |
| 332 | |
| 333 | typedef struct |
| 334 | { |
| 335 | kal_uint8 security_indication; |
| 336 | kal_uint8 phone_key[NVRAM_EDITOR_NUM_OF_BYTE_KEY]; |
| 337 | kal_uint8 last_imsi[NVRAM_EDITOR_NUM_OF_BYTE_IMSI]; |
| 338 | kal_uint8 pin1[NVRAM_EDITOR_NUM_PIN1]; |
| 339 | kal_uint8 pin1_valid; |
| 340 | kal_uint8 phone_lock_verified; |
| 341 | kal_uint8 iccid[NVRAM_EDITOR_NUM_OF_BYTE_ICCID]; |
| 342 | } smu_security_info_struct; |
| 343 | |
| 344 | /* -------------------------- |
| 345 | * Beginning of SML Configuration |
| 346 | * --------------------------- */ |
| 347 | #define NVRAM_SECRET_KEY_SIZE 8 |
| 348 | #define NVRAM_CUSTOM_KEY_SEED_SIZE 32 |
| 349 | |
| 350 | /* General control key structure */ |
| 351 | typedef struct { |
| 352 | kal_uint8 state; /* Default Value or NULL */ |
| 353 | kal_uint8 key[NVRAM_SML_MAX_SUPPORT_KEY_LEN]; //actual data length is SML_MAX_SUPPORT_KEY_LEN |
| 354 | } sml_control_key_struct; |
| 355 | |
| 356 | /* General lock structure */ |
| 357 | typedef struct { |
| 358 | kal_uint8 state; /* sml_state_enum */ |
| 359 | kal_uint8 retry_count; /* SML_RETRY_COUNT_X_CAT */ |
| 360 | kal_uint8 autolock_count; /* SML_AUTOLOCK_NUM_X_CAT */ |
| 361 | kal_uint8 num; /* num of valid sets */ |
| 362 | } sml_category_meta_struct; |
| 363 | |
| 364 | typedef struct { |
| 365 | kal_uint32 magic_head; /* 4 */ |
| 366 | sml_category_meta_struct cat[SML_SUPPORT_CAT_SIZE]; /* (4 * 7) */ |
| 367 | sml_control_key_struct key[SML_SUPPORT_CAT_SIZE]; /* (9 * 7) */ |
| 368 | kal_uint8 code_cat_n[SML_CFG_CAT_N_SIZE]; /* (30 * 3)*/ |
| 369 | kal_uint8 code_cat_ns[SML_CFG_CAT_NS_SIZE]; /* (30 * 4)*/ |
| 370 | kal_uint8 code_cat_sp[SML_CFG_CAT_SP_SIZE]; /* (30 * 4)*/ |
| 371 | kal_uint8 code_cat_c[SML_CFG_CAT_C_SIZE]; /* (30 * 5)*/ |
| 372 | kal_uint8 code_cat_sim[SML_CFG_CAT_SIM_SIZE]; /* (30 * 8)*/ |
| 373 | kal_uint8 code_cat_ns_sp[SML_CFG_CAT_NS_SP_SIZE]; /* (5 * 10)*/ |
| 374 | kal_uint8 code_cat_sim_c[SML_CFG_CAT_SIM_C_SIZE]; /* (10 * 10)*/ |
| 375 | kal_uint8 range_cat_ns[SML_CAT_NS_RANGE_SIZE]; /* 2 */ |
| 376 | kal_uint32 magic_tail; /* 4 */ |
| 377 | } sml_context_struct; /* 971 */ |
| 378 | typedef sml_context_struct nvram_sml_context_struct; |
| 379 | |
| 380 | typedef struct { |
| 381 | kal_uint8 state; /* Default Value or NULL */ |
| 382 | kal_uint8 algo; |
| 383 | kal_uint8 salt[NVRAM_SML_S_MAX_SUPPORT_SALT_LEN]; |
| 384 | kal_uint8 inter_cnt[NVRAM_SML_S_MAX_SUPPORT_INTER_CNT_LEN]; |
| 385 | kal_uint8 key[NVRAM_SML_S_MAX_SUPPORT_HCK_LEN]; |
| 386 | } sml_control_key_s_struct; |
| 387 | |
| 388 | #if SML_S_LID_VER >= 2 |
| 389 | typedef struct { |
| 390 | kal_uint8 state; // sml_puk_key_state_enum |
| 391 | kal_uint32 max_retry_count; |
| 392 | kal_uint32 retry_count; |
| 393 | |
| 394 | kal_uint8 algo; |
| 395 | kal_uint8 salt[NVRAM_SML_S_MAX_SUPPORT_SALT_LEN]; |
| 396 | kal_uint8 iter_cnt[NVRAM_SML_S_MAX_SUPPORT_INTER_CNT_LEN]; |
| 397 | kal_uint8 key[NVRAM_SML_S_MAX_SUPPORT_HCK_LEN]; |
| 398 | } sml_puk_key_s_struct; |
| 399 | #endif |
| 400 | |
| 401 | typedef struct { |
| 402 | kal_uint8 state; /* sml_state_enum */ |
| 403 | kal_uint32 max_retry_count; /* SML_MAX_RETRY_COUNT_X_CAT */ |
| 404 | kal_uint32 retry_count; /* SML_RETRY_COUNT_X_CAT */ |
| 405 | kal_uint8 autolock_count; /* SML_AUTOLOCK_NUM_X_CAT */ |
| 406 | kal_uint8 num; /* num of valid sets */ |
| 407 | } sml_category_meta_s_struct; |
| 408 | |
| 409 | typedef struct { |
| 410 | kal_uint32 magic_head; |
| 411 | sml_category_meta_s_struct cat[SML_SUPPORT_CAT_SIZE]; |
| 412 | sml_control_key_s_struct key[SML_SUPPORT_CAT_SIZE]; |
| 413 | #if SML_S_LID_VER >= 2 |
| 414 | sml_puk_key_s_struct puk_key[SML_SUPPORT_CAT_SIZE]; |
| 415 | #endif |
| 416 | kal_uint8 code_cat_n[SML_CFG_CAT_N_SIZE]; |
| 417 | kal_uint8 code_cat_ns[SML_CFG_CAT_NS_SIZE]; |
| 418 | kal_uint8 code_cat_sp[SML_CFG_CAT_SP_SIZE]; |
| 419 | kal_uint8 code_cat_c[SML_CFG_CAT_C_SIZE]; |
| 420 | kal_uint8 code_cat_sim[SML_CFG_CAT_SIM_SIZE]; |
| 421 | kal_uint8 code_cat_ns_sp[SML_CFG_CAT_NS_SP_SIZE]; |
| 422 | kal_uint8 code_cat_sim_c[SML_CFG_CAT_SIM_C_SIZE]; |
| 423 | kal_uint8 range_cat_ns[SML_CAT_NS_RANGE_SIZE]; |
| 424 | kal_uint32 magic_tail; |
| 425 | } sml_context_s_struct; |
| 426 | typedef sml_context_s_struct nvram_sml_context_s_struct; |
| 427 | |
| 428 | typedef struct |
| 429 | { |
| 430 | kal_uint8 data[3072]; |
| 431 | } smu_op129_sim_lock_rawdata_struct; |
| 432 | typedef smu_op129_sim_lock_rawdata_struct nvram_sml_op129_sim_lock_rawdata_struct; |
| 433 | |
| 434 | /* the magic number of file header and tail */ |
| 435 | #define SML_MAGIC_HEAD_VALUE (sizeof(sml_context_struct)) |
| 436 | #define SML_MAGIC_TAIL_VALUE 0x26598088 |
| 437 | |
| 438 | /* -------------------------- |
| 439 | * End of SML Configuration |
| 440 | * --------------------------- */ |
| 441 | |
| 442 | #if !defined(NVRAM_NOT_PRESENT) |
| 443 | #ifdef __cplusplus |
| 444 | extern "C" |
| 445 | { |
| 446 | #endif /* __cplusplus */ |
| 447 | |
| 448 | #include "nvram_defs.h" /* NVRAM_MSP_ALIGNMENT */ |
| 449 | |
| 450 | /* |
| 451 | * CUST PARA Configuration |
| 452 | */ |
| 453 | |
| 454 | |
| 455 | /* |
| 456 | * Secure RO Version |
| 457 | * Whenever nvram_sml_context_struct's size or members are changed, |
| 458 | * be sure to assign an unique version number to SEC_RO_STRUCT_VER. |
| 459 | * Otherwise, PC side tool has no idea how to compose it |
| 460 | */ |
| 461 | #ifndef __SECURE_USB_DOWNLOAD__ |
| 462 | #define SEC_RO_STRUCT_VER 1 |
| 463 | #else |
| 464 | #define SEC_RO_STRUCT_VER 2 |
| 465 | #endif |
| 466 | |
| 467 | /* |
| 468 | * Secure RO |
| 469 | */ |
| 470 | typedef enum |
| 471 | { |
| 472 | SEC_RO_PARA_DBG_PORT, |
| 473 | SEC_RO_PARA_TOTAL |
| 474 | }sec_ro_para_enum; |
| 475 | |
| 476 | extern const kal_uint8 NVRAM_SECUPACK_DEFAULT[]; |
| 477 | extern const kal_uint8 NVRAM_CUSTOM_KEY[]; |
| 478 | extern const kal_uint8 NVRAM_CUSTOM_KEY_SEED[]; |
| 479 | |
| 480 | extern kal_uint32 secupack_total_to_verify; |
| 481 | extern void custom_nvram_get_key(char *init_key, unsigned char *keys); |
| 482 | extern void custom_nvram_encrypt(unsigned char const *keys, unsigned char *buffer, unsigned int length, int scrambleIndex); |
| 483 | extern void custom_nvram_decrypt(unsigned char const *keys, unsigned char *buffer, unsigned int length, int scrambleIndex); |
| 484 | extern void nvram_AES_encrypt(unsigned char *buffer, unsigned int length); |
| 485 | extern void nvram_AES_decrypt(unsigned char *buffer, unsigned int length); |
| 486 | extern void nvram_calculate_checksum(NVRAM_ALGO_TYPE type, kal_uint8 *source, kal_uint32 source_length, kal_uint8 *dest); |
| 487 | |
| 488 | extern kal_uint32 custom_nvram_sec_ro_size(void); |
| 489 | extern kal_uint32 custom_nvram_secupack_size(void); |
| 490 | extern kal_uint32 custom_nvram_secupack_total(void); |
| 491 | extern kal_uint32 custom_nvram_key_len(void); |
| 492 | |
| 493 | extern nvram_lid_enum custom_nvram_get_signed_critical_data_lid(); |
| 494 | extern kal_bool custom_nvram_check_signed_critical_data_before_write(kal_uint8 *wr_dat, kal_uint32 len); |
| 495 | extern kal_bool custom_nvram_read_and_check_signed_critical_data(); |
| 496 | |
rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 497 | extern const nvram_sml_context_struct NVRAM_EF_SML_DEFAULT; |
| 498 | extern const nvram_sml_context_s_struct NVRAM_EF_SML_S_DEFAULT; |
rjw | 8e44aab | 2022-11-30 16:42:16 +0800 | [diff] [blame^] | 499 | #if defined(NVRAM_AUTO_GEN) |
rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 500 | extern const kal_uint8 custom_secret_key[]; |
| 501 | extern const kal_uint8 custom_key_seed[]; |
| 502 | extern const kal_uint8 NVRAM_SECURE_PARA[]; |
| 503 | #ifdef __SECURE_USB_DOWNLOAD__ |
| 504 | extern const kal_uint8 custom_symmetric_key[]; |
| 505 | extern const T_Customer_Public_Key custom_asymmetric_key; |
| 506 | #endif |
| 507 | #endif |
| 508 | |
| 509 | |
| 510 | #ifdef __cplusplus |
| 511 | } |
| 512 | #endif |
| 513 | #endif /* !defined(NVRAM_NOT_PRESENT) */ |
| 514 | #endif /* CUSTOM_NVRAM_SEC_H */ |
| 515 | |