tools/header_generation/create_hdr_common.c
/***************************************************************************
 * Function	:	create_srk_calc_hash
 * Arguments	:	max_keys - Maximum Number of entries in SRK Table
 * Return	:	SUCCESS or FAILURE
 * Description	:	Creates the SRK Table and calculate the hash
 ***************************************************************************/
Function     :       create_srk_calc_hash
Arguments    :       max_keys - Maximum Number of entries in SRK Table
Return       :       SUCCESS or FAILURE
Description  :       Creates the SRK Table and calculate the hash
Function : create_srk_calc_hash Arguments : max_keys - Maximum Number of entries in SRK Table Return : SUCCESS or FAILURE Description : Creates the SRK Table and calculate the hash
int create_srk_calc_hash(uint32_t max_keys)
{
	int i, ret;
	uint32_t key_len;
	uint8_t ctx[CRYPTO_HASH_CTX_SIZE];
	if (gd.srk_flag == 0)
		max_keys = 1;
	if ((gd.num_srk_entries > max_keys) ||
	(gd.num_srk_entries == 0)) {
		printf("Invalid Number of Keys\n");
		return FAILURE;
	}
	if ((gd.srk_sel > gd.num_srk_entries) ||
	    (gd.srk_sel == 0)) {
		printf("Invalid Key Select\n");
		return FAILURE;
	}
	if (gd.option_img_hash == 0) {
		if (gd.num_srk_entries != gd.num_pri_key) {
			printf("Public and Private Key Count Mismatch\n");
			return FAILURE;
		}
	}
	for (i = 0; i < gd.num_srk_entries; i++) {
		key_len = 0;
		ret = crypto_extract_pub_key(gd.pub_fname[i],
					&key_len,
					gd.key_table[i].pkey);
		if (gd.hton_flag == 0)
			gd.key_table[i].key_len = key_len;
		else
			gd.key_table[i].key_len = htonl(key_len);
		if (ret != SUCCESS)
			break;
	}
	gd.srk_size = gd.num_srk_entries * sizeof(struct srk_table_t);
	crypto_hash_init(ctx);
	if (gd.srk_flag == 1)
		crypto_hash_update(ctx, gd.key_table, gd.srk_size);
	else {
		gd.pkey = gd.key_table[0].pkey;
		if (gd.hton_flag == 0)
			gd.key_len = gd.key_table[0].key_len;
		else
			gd.key_len = htonl(gd.key_table[0].key_len);
		crypto_hash_update(ctx, gd.pkey, gd.key_len);
	}
	crypto_hash_final(gd.srk_hash, ctx);
	gd.srk_hash_flag = 1;
	return ret;
}
int create_srk_calc_hash ( uint32_t max_keys ) { int i , ret ; uint32_t key_len ; uint8_t ctx [ CRYPTO_HASH_CTX_SIZE ] ; if ( gd . srk_flag == 0 ) max_keys = 1 ; if ( ( gd . num_srk_entries > max_keys ) || ( gd . num_srk_entries == 0 ) ) { printf ( " \n " ) ; return FAILURE ; } if ( ( gd . srk_sel > gd . num_srk_entries ) || ( gd . srk_sel == 0 ) ) { printf ( " \n " ) ; return FAILURE ; } if ( gd . option_img_hash == 0 ) { if ( gd . num_srk_entries != gd . num_pri_key ) { printf ( " \n " ) ; return FAILURE ; } } for ( i = 0 ; i < gd . num_srk_entries ; i ++ ) { key_len = 0 ; ret = crypto_extract_pub_key ( gd . pub_fname [ i ] , & key_len , gd . key_table [ i ] . pkey ) ; if ( gd . hton_flag == 0 ) gd . key_table [ i ] . key_len = key_len ; else gd . key_table [ i ] . key_len = htonl ( key_len ) ; if ( ret != SUCCESS ) break ; } gd . srk_size = gd . num_srk_entries * sizeof ( struct srk_table_t ) ; crypto_hash_init ( ctx ) ; if ( gd . srk_flag == 1 ) crypto_hash_update ( ctx , gd . key_table , gd . srk_size ) ; else { gd . pkey = gd . key_table [ 0 ] . pkey ; if ( gd . hton_flag == 0 ) gd . key_len = gd . key_table [ 0 ] . key_len ; else gd . key_len = htonl ( gd . key_table [ 0 ] . key_len ) ; crypto_hash_update ( ctx , gd . pkey , gd . key_len ) ; } crypto_hash_final ( gd . srk_hash , ctx ) ; gd . srk_hash_flag = 1 ; return ret ; }
Function     :       create_srk_calc_hash
 Arguments    :       max_keys - Maximum Number of entries in SRK Table
 Return       :       SUCCESS or FAILURE
 Description  :       Creates the SRK Table and calculate the hash
Function : create_srk_calc_hash Arguments : max_keys - Maximum Number of entries in SRK Table Return : SUCCESS or FAILURE Description : Creates the SRK Table and calculate the hash
/* Check if Num of Entries and Key Select is Correct */ /* Read all the public Keys and Store in SRK Table */ /* Update the size of SRK Table */ /* Calculate the Hash if SRK/ Public Key */