Lines Matching full:img

65 static u32 check_ie(struct fsl_secboot_img_priv *img)  in check_ie()  argument
67 if (img->hdr.ie_flag & IE_FLAG_MASK) in check_ie()
183 static u32 check_srk(struct fsl_secboot_img_priv *img) in check_srk() argument
188 return !check_ie(img); in check_srk()
192 if (img->hdr.len_kr.srk_table_flag & SRK_FLAG) in check_srk()
220 static u32 read_validate_srk_tbl(struct fsl_secboot_img_priv *img) in read_validate_srk_tbl() argument
224 struct fsl_secboot_img_hdr *hdr = &img->hdr; in read_validate_srk_tbl()
225 void *esbc = (u8 *)(uintptr_t)img->ehdrloc; in read_validate_srk_tbl()
243 memcpy(&img->srk_tbl, esbc + hdr->srk_tbl_off, size); in read_validate_srk_tbl()
246 if (!CHECK_KEY_LEN(img->srk_tbl[i].key_len)) in read_validate_srk_tbl()
250 img->key_len = img->srk_tbl[key_num - 1].key_len; in read_validate_srk_tbl()
252 memcpy(&img->img_key, &(img->srk_tbl[key_num - 1].pkey), in read_validate_srk_tbl()
253 img->key_len); in read_validate_srk_tbl()
260 static u32 read_validate_single_key(struct fsl_secboot_img_priv *img) in read_validate_single_key() argument
262 struct fsl_secboot_img_hdr *hdr = &img->hdr; in read_validate_single_key()
263 void *esbc = (u8 *)(uintptr_t)img->ehdrloc; in read_validate_single_key()
269 memcpy(&img->img_key, esbc + hdr->pkey, hdr->key_len); in read_validate_single_key()
271 img->key_len = hdr->key_len; in read_validate_single_key()
280 struct fsl_secboot_img_priv *img) in install_ie_tbl() argument
284 img->ie_addr = (uintptr_t)&glb.ie_tbl; in install_ie_tbl()
285 glb.ie_addr = img->ie_addr; in install_ie_tbl()
288 static u32 read_validate_ie_tbl(struct fsl_secboot_img_priv *img) in read_validate_ie_tbl() argument
290 struct fsl_secboot_img_hdr *hdr = &img->hdr; in read_validate_ie_tbl()
294 if (!img->ie_addr) { in read_validate_ie_tbl()
295 if (get_ie_info_addr(&img->ie_addr)) in read_validate_ie_tbl()
298 install_ie_tbl(img->ie_addr, img); in read_validate_ie_tbl()
301 ie_info = (struct ie_key_info *)(uintptr_t)img->ie_addr; in read_validate_ie_tbl()
318 memcpy(&img->img_key, &(ie_info->ie_key_tbl[ie_num - 1].pkey), in read_validate_ie_tbl()
321 img->key_len = ie_key_len; in read_validate_ie_tbl()
328 static inline u32 get_key_len(struct fsl_secboot_img_priv *img) in get_key_len() argument
330 return img->key_len; in get_key_len()
486 static int calc_img_key_hash(struct fsl_secboot_img_priv *img) in calc_img_key_hash() argument
505 if (check_srk(img)) { in calc_img_key_hash()
507 (u8 *)(uintptr_t)(img->ehdrloc + img->hdr.srk_tbl_off), in calc_img_key_hash()
508 img->hdr.len_kr.num_srk * sizeof(struct srk_table), 1); in calc_img_key_hash()
514 img->img_key, img->key_len, 1); in calc_img_key_hash()
524 img->img_key_hash[i] = hash_val[i]; in calc_img_key_hash()
534 static int calc_esbchdr_esbc_hash(struct fsl_secboot_img_priv *img) in calc_esbchdr_esbc_hash() argument
554 (u8 *)&img->hdr, sizeof(struct fsl_secboot_img_hdr), 0); in calc_esbchdr_esbc_hash()
564 if (check_srk(img)) { in calc_esbchdr_esbc_hash()
566 (u8 *)(uintptr_t)(img->ehdrloc + img->hdr.srk_tbl_off), in calc_esbchdr_esbc_hash()
567 img->hdr.len_kr.num_srk * sizeof(struct srk_table), 0); in calc_esbchdr_esbc_hash()
572 if (!key_hash && check_ie(img)) in calc_esbchdr_esbc_hash()
579 img->img_key, img->hdr.key_len, 0); in calc_esbchdr_esbc_hash()
590 (u8 *)(*(img->img_addr_ptr)), img->img_size, 1); in calc_esbchdr_esbc_hash()
608 static void construct_img_encoded_hash_second(struct fsl_secboot_img_priv *img) in construct_img_encoded_hash_second() argument
633 len = (get_key_len(img) / 2) - 1; in construct_img_encoded_hash_second()
634 representative = img->img_encoded_hash_second; in construct_img_encoded_hash_second()
664 static int read_validate_esbc_client_header(struct fsl_secboot_img_priv *img) in read_validate_esbc_client_header() argument
666 struct fsl_secboot_img_hdr *hdr = &img->hdr; in read_validate_esbc_client_header()
667 void *esbc = (u8 *)(uintptr_t)img->ehdrloc; in read_validate_esbc_client_header()
680 if (*(img->img_addr_ptr) == 0) { in read_validate_esbc_client_header()
682 *(img->img_addr_ptr) = hdr->pimg64; in read_validate_esbc_client_header()
684 *(img->img_addr_ptr) = hdr->pimg; in read_validate_esbc_client_header()
691 img->img_size = hdr->img_size; in read_validate_esbc_client_header()
695 if (check_srk(img)) { in read_validate_esbc_client_header()
696 ret = read_validate_srk_tbl(img); in read_validate_esbc_client_header()
704 if (!key_found && check_ie(img)) { in read_validate_esbc_client_header()
705 ret = read_validate_ie_tbl(img); in read_validate_esbc_client_header()
714 ret = read_validate_single_key(img); in read_validate_esbc_client_header()
724 if (get_key_len(img) == 2 * hdr->sign_len) { in read_validate_esbc_client_header()
734 memcpy(&img->img_sign, esbc + hdr->psign, hdr->sign_len); in read_validate_esbc_client_header()
743 k = (u8 *)&img->img_key; in read_validate_esbc_client_header()
749 if ((k[get_key_len(img) / 2 - 1] & 0x1) == 0) in read_validate_esbc_client_header()
753 s = (u8 *)&img->img_sign; in read_validate_esbc_client_header()
783 static int calculate_cmp_img_sig(struct fsl_secboot_img_priv *img) in calculate_cmp_img_sig() argument
791 ret = calc_esbchdr_esbc_hash(img); in calculate_cmp_img_sig()
796 construct_img_encoded_hash_second(img); in calculate_cmp_img_sig()
800 key_len = get_key_len(img) / 2; in calculate_cmp_img_sig()
801 prop.modulus = img->img_key; in calculate_cmp_img_sig()
802 prop.public_exponent = img->img_key + key_len; in calculate_cmp_img_sig()
812 ret = rsa_mod_exp(mod_exp_dev, img->img_sign, img->hdr.sign_len, in calculate_cmp_img_sig()
813 &prop, img->img_encoded_hash); in calculate_cmp_img_sig()
822 ret = memcmp(&img->img_encoded_hash_second, &img->img_encoded_hash, in calculate_cmp_img_sig()
823 img->hdr.sign_len); in calculate_cmp_img_sig()
830 /* Function to initialize img priv and global data structure
836 struct fsl_secboot_img_priv *img = *img_ptr; in secboot_init() local
838 if (!img) in secboot_init()
840 memset(img, 0, sizeof(struct fsl_secboot_img_priv)); in secboot_init()
844 img->ie_addr = glb.ie_addr; in secboot_init()
865 struct fsl_secboot_img_priv *img; in fsl_secboot_validate() local
903 ret = secboot_init(&img); in fsl_secboot_validate()
908 hdr = &img->hdr; in fsl_secboot_validate()
909 img->ehdrloc = haddr; in fsl_secboot_validate()
910 img->img_addr_ptr = img_addr_ptr; in fsl_secboot_validate()
911 esbc = (u8 *)img->ehdrloc; in fsl_secboot_validate()
916 ret = read_validate_esbc_client_header(img); in fsl_secboot_validate()
931 ret = calc_img_key_hash(img); in fsl_secboot_validate()
939 ret = memcmp(&hash, &img->img_key_hash, SHA256_BYTES); in fsl_secboot_validate()
941 ret = memcmp(srk_hash, img->img_key_hash, SHA256_BYTES); in fsl_secboot_validate()
944 if (!hash_cmd && check_ie(img)) in fsl_secboot_validate()
953 ret = calculate_cmp_img_sig(img); in fsl_secboot_validate()
960 /* Free Img as it was malloc'ed*/ in fsl_secboot_validate()
961 free(img); in fsl_secboot_validate()