/* Construct encoded hash EM' wrt PKCSv1.5. This function calculates the pointers for padding, DER value and hash. And finally, constructs EM' which includes hash of complete CSF header and ESBC image. If SG flag is on, hash of SG table and entries is also included.  */
static void construct_img_encoded_hash_second(struct fsl_secboot_img_priv *img)
/* Construct encoded hash EM' wrt PKCSv1.5. This function calculates the pointers for padding, DER value and hash. And finally, constructs EM' which includes hash of complete CSF header and ESBC image. If SG flag is on, hash of SG table and entries is also included.  */
static void construct_img_encoded_hash_second(struct fsl_secboot_img_priv *img)
{
	size_t len;
	u8 *representative;
	u8 *padding, *digest;
	u8 *hash_id, *separator;
	int i;
	len = (get_key_len(img) / 2) - 1;
	representative = img->img_encoded_hash_second;
	representative[0] = 0;
	representative[1] = 1;
	padding = &representative[2];
	digest = &representative[1] + len - 32;
	hash_id = digest - sizeof(hash_identifier);
	separator = hash_id - 1;
	memset(padding, 0xff, separator - padding);
	*separator = 0;
	memcpy(hash_id, hash_identifier, sizeof(hash_identifier));
	for (i = 0; i < SHA256_BYTES; i++)
		digest[i] = hash_val[i];
}