ta/wallet_ta.c
/**
  * Calculate the checksum (SHA-256 hash) of the current wallet's contents.
  * \param session_data A data pointer to a session context.  It is to be
  * used internally (only by the functions of the TA itself).
  * \param checksum The resulting SHA-256 hash will be written here. This must
  *                 be a byte array with space for #CHECKSUM_LENGTH bytes.
  * \return TEE_SUCCESS in case of success otherwise returns the result
  *         received from the failed operation. The information about all
  *         possible returns is present in TEE Client API Specification - 4.4.2
  *         published by GlobalPlatform.
  */
Calculate the checksum (SHA-256 hash) of the current wallet's contents.
\param session_data A data pointer to a session context.  It is to be
used internally (only by the functions of the TA itself).
\param checksum The resulting SHA-256 hash will be written here. This must
be a byte array with space for #CHECKSUM_LENGTH bytes.
\return TEE_SUCCESS in case of success otherwise returns the result
received from the failed operation. The information about all
possible returns is present in TEE Client API Specification - 4.4.2
published by GlobalPlatform.
Calculate the checksum ( SHA - 256 hash ) of the current wallet ' s contents . \ param session_data A data pointer to a session context . It is to be used internally ( only by the functions of the TA itself ) . \ param checksum The resulting SHA - 256 hash will be written here . This must be a byte array with space for #CHECKSUM_LENGTH bytes . \ return TEE_SUCCESS in case of success otherwise returns the result received from the failed operation . The information about all possible returns is present in TEE Client API Specification - 4 . 4 . 2 published by GlobalPlatform .
static TEE_Result calculate_wallet_checksum_internal(Session_data * session_data, uint8_t * checksum)
{
	TEE_Result result = TEE_SUCCESS;
	uint8_t * ptr;
	unsigned int i;
	uint32_t hash[8];
	if (checksum == NULL)
		return TEE_ERROR_BAD_PARAMETERS;
	sha256_init_internal(session_data);
	ptr = (uint8_t*)(session_data->current_wallet);
	for (i = 0; i < sizeof(WalletRecord); i++)
	{
		if (i == offsetof(WalletRecord, encrypted.checksum))
			i += sizeof(session_data->current_wallet->encrypted.checksum);
		if (i < sizeof(WalletRecord))
			sha256_update_internal(session_data,
									&(ptr[i]),
									(uint32_t)sizeof(ptr[i]));
	}
	result = sha256_final_internal(session_data, hash, (uint32_t)32);
	if(result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to do calculate_wallet_checksum operation : 0x%x", result);
		#endif
		goto cleanup1;
	}
	write_hash_to_byte_array_internal(checksum, hash, true);
	cleanup1:
		return result;
}
static TEE_Result calculate_wallet_checksum_internal ( Session_data * session_data , uint8_t * checksum ) { TEE_Result result = TEE_SUCCESS ; uint8_t * ptr ; unsigned int i ; uint32_t hash [ 8 ] ; if ( checksum == NULL ) return TEE_ERROR_BAD_PARAMETERS ; sha256_init_internal ( session_data ) ; ptr = ( uint8_t * ) ( session_data -> current_wallet ) ; for ( i = 0 ; i < sizeof ( WalletRecord ) ; i ++ ) { if ( i == offsetof ( WalletRecord , encrypted . checksum ) ) i += sizeof ( session_data -> current_wallet -> encrypted . checksum ) ; if ( i < sizeof ( WalletRecord ) ) sha256_update_internal ( session_data , & ( ptr [ i ] ) , ( uint32_t ) sizeof ( ptr [ i ] ) ) ; } result = sha256_final_internal ( session_data , hash , ( uint32_t ) 32 ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } write_hash_to_byte_array_internal ( checksum , hash , true ) ; cleanup1 : return result ; }
Calculate the checksum (SHA-256 hash) of the current wallet's contents.
Calculate the checksum ( SHA - 256 hash ) of the current wallet ' s contents .
/* Sanity check */ /* Go trough every byte of the wallet record */ /* Skip the checksum field */ /* Finalize the hashing operation */ /* Convert the hash to an byte array */ /* Resources cleanup */