Lines Matching refs:img

64 static u32 check_ie(struct fsl_secboot_img_priv *img)  in check_ie()  argument
66 if (img->hdr.ie_flag & IE_FLAG_MASK) in check_ie()
182 static u32 check_srk(struct fsl_secboot_img_priv *img) in check_srk() argument
187 return !check_ie(img); in check_srk()
191 if (img->hdr.len_kr.srk_table_flag & SRK_FLAG) in check_srk()
219 static u32 read_validate_srk_tbl(struct fsl_secboot_img_priv *img) in read_validate_srk_tbl() argument
223 struct fsl_secboot_img_hdr *hdr = &img->hdr; in read_validate_srk_tbl()
224 void *esbc = (u8 *)(uintptr_t)img->ehdrloc; in read_validate_srk_tbl()
242 memcpy(&img->srk_tbl, esbc + hdr->srk_tbl_off, size); in read_validate_srk_tbl()
245 if (!CHECK_KEY_LEN(img->srk_tbl[i].key_len)) in read_validate_srk_tbl()
249 img->key_len = img->srk_tbl[key_num - 1].key_len; in read_validate_srk_tbl()
251 memcpy(&img->img_key, &(img->srk_tbl[key_num - 1].pkey), in read_validate_srk_tbl()
252 img->key_len); in read_validate_srk_tbl()
259 static u32 read_validate_single_key(struct fsl_secboot_img_priv *img) in read_validate_single_key() argument
261 struct fsl_secboot_img_hdr *hdr = &img->hdr; in read_validate_single_key()
262 void *esbc = (u8 *)(uintptr_t)img->ehdrloc; in read_validate_single_key()
268 memcpy(&img->img_key, esbc + hdr->pkey, hdr->key_len); in read_validate_single_key()
270 img->key_len = hdr->key_len; in read_validate_single_key()
279 struct fsl_secboot_img_priv *img) in install_ie_tbl() argument
283 img->ie_addr = (uintptr_t)&glb.ie_tbl; in install_ie_tbl()
284 glb.ie_addr = img->ie_addr; in install_ie_tbl()
287 static u32 read_validate_ie_tbl(struct fsl_secboot_img_priv *img) in read_validate_ie_tbl() argument
289 struct fsl_secboot_img_hdr *hdr = &img->hdr; in read_validate_ie_tbl()
293 if (!img->ie_addr) { in read_validate_ie_tbl()
294 if (get_ie_info_addr(&img->ie_addr)) in read_validate_ie_tbl()
297 install_ie_tbl(img->ie_addr, img); in read_validate_ie_tbl()
300 ie_info = (struct ie_key_info *)(uintptr_t)img->ie_addr; in read_validate_ie_tbl()
317 memcpy(&img->img_key, &(ie_info->ie_key_tbl[ie_num - 1].pkey), in read_validate_ie_tbl()
320 img->key_len = ie_key_len; in read_validate_ie_tbl()
327 static inline u32 get_key_len(struct fsl_secboot_img_priv *img) in get_key_len() argument
329 return img->key_len; in get_key_len()
485 static int calc_img_key_hash(struct fsl_secboot_img_priv *img) in calc_img_key_hash() argument
504 if (check_srk(img)) { in calc_img_key_hash()
506 (u8 *)(uintptr_t)(img->ehdrloc + img->hdr.srk_tbl_off), in calc_img_key_hash()
507 img->hdr.len_kr.num_srk * sizeof(struct srk_table), 1); in calc_img_key_hash()
513 img->img_key, img->key_len, 1); in calc_img_key_hash()
523 img->img_key_hash[i] = hash_val[i]; in calc_img_key_hash()
533 static int calc_esbchdr_esbc_hash(struct fsl_secboot_img_priv *img) in calc_esbchdr_esbc_hash() argument
553 (u8 *)&img->hdr, sizeof(struct fsl_secboot_img_hdr), 0); in calc_esbchdr_esbc_hash()
563 if (check_srk(img)) { in calc_esbchdr_esbc_hash()
565 (u8 *)(uintptr_t)(img->ehdrloc + img->hdr.srk_tbl_off), in calc_esbchdr_esbc_hash()
566 img->hdr.len_kr.num_srk * sizeof(struct srk_table), 0); in calc_esbchdr_esbc_hash()
571 if (!key_hash && check_ie(img)) in calc_esbchdr_esbc_hash()
578 img->img_key, img->hdr.key_len, 0); in calc_esbchdr_esbc_hash()
589 (u8 *)(*(img->img_addr_ptr)), img->img_size, 1); in calc_esbchdr_esbc_hash()
607 static void construct_img_encoded_hash_second(struct fsl_secboot_img_priv *img) in construct_img_encoded_hash_second() argument
632 len = (get_key_len(img) / 2) - 1; in construct_img_encoded_hash_second()
633 representative = img->img_encoded_hash_second; in construct_img_encoded_hash_second()
663 static int read_validate_esbc_client_header(struct fsl_secboot_img_priv *img) in read_validate_esbc_client_header() argument
665 struct fsl_secboot_img_hdr *hdr = &img->hdr; in read_validate_esbc_client_header()
666 void *esbc = (u8 *)(uintptr_t)img->ehdrloc; in read_validate_esbc_client_header()
679 if (*(img->img_addr_ptr) == 0) { in read_validate_esbc_client_header()
681 *(img->img_addr_ptr) = hdr->pimg64; in read_validate_esbc_client_header()
683 *(img->img_addr_ptr) = hdr->pimg; in read_validate_esbc_client_header()
690 img->img_size = hdr->img_size; in read_validate_esbc_client_header()
694 if (check_srk(img)) { in read_validate_esbc_client_header()
695 ret = read_validate_srk_tbl(img); in read_validate_esbc_client_header()
703 if (!key_found && check_ie(img)) { in read_validate_esbc_client_header()
704 ret = read_validate_ie_tbl(img); in read_validate_esbc_client_header()
713 ret = read_validate_single_key(img); in read_validate_esbc_client_header()
723 if (get_key_len(img) == 2 * hdr->sign_len) { in read_validate_esbc_client_header()
733 memcpy(&img->img_sign, esbc + hdr->psign, hdr->sign_len); in read_validate_esbc_client_header()
742 k = (u8 *)&img->img_key; in read_validate_esbc_client_header()
748 if ((k[get_key_len(img) / 2 - 1] & 0x1) == 0) in read_validate_esbc_client_header()
752 s = (u8 *)&img->img_sign; in read_validate_esbc_client_header()
782 static int calculate_cmp_img_sig(struct fsl_secboot_img_priv *img) in calculate_cmp_img_sig() argument
790 ret = calc_esbchdr_esbc_hash(img); in calculate_cmp_img_sig()
795 construct_img_encoded_hash_second(img); in calculate_cmp_img_sig()
799 key_len = get_key_len(img) / 2; in calculate_cmp_img_sig()
800 prop.modulus = img->img_key; in calculate_cmp_img_sig()
801 prop.public_exponent = img->img_key + key_len; in calculate_cmp_img_sig()
811 ret = rsa_mod_exp(mod_exp_dev, img->img_sign, img->hdr.sign_len, in calculate_cmp_img_sig()
812 &prop, img->img_encoded_hash); in calculate_cmp_img_sig()
821 ret = memcmp(&img->img_encoded_hash_second, &img->img_encoded_hash, in calculate_cmp_img_sig()
822 img->hdr.sign_len); in calculate_cmp_img_sig()
835 struct fsl_secboot_img_priv *img = *img_ptr; in secboot_init() local
837 if (!img) in secboot_init()
839 memset(img, 0, sizeof(struct fsl_secboot_img_priv)); in secboot_init()
843 img->ie_addr = glb.ie_addr; in secboot_init()
864 struct fsl_secboot_img_priv *img; in fsl_secboot_validate() local
902 ret = secboot_init(&img); in fsl_secboot_validate()
907 hdr = &img->hdr; in fsl_secboot_validate()
908 img->ehdrloc = haddr; in fsl_secboot_validate()
909 img->img_addr_ptr = img_addr_ptr; in fsl_secboot_validate()
910 esbc = (u8 *)img->ehdrloc; in fsl_secboot_validate()
915 ret = read_validate_esbc_client_header(img); in fsl_secboot_validate()
930 ret = calc_img_key_hash(img); in fsl_secboot_validate()
938 ret = memcmp(&hash, &img->img_key_hash, SHA256_BYTES); in fsl_secboot_validate()
940 ret = memcmp(srk_hash, img->img_key_hash, SHA256_BYTES); in fsl_secboot_validate()
943 if (!hash_cmd && check_ie(img)) in fsl_secboot_validate()
952 ret = calculate_cmp_img_sig(img); in fsl_secboot_validate()
960 free(img); in fsl_secboot_validate()