ta/wallet_ta.c
/** Wrapper around read_cache_wallet_storage() which also decrypts data
  * using aes_xts_internal(). Because this uses encryption, it is much slower
  * than read_cache_wallet_storage(). The parameters and return values are
  * identical to that of read_cache_wallet_storage(). It is to be
  * used internally (only by the functions of the TA itself).
  * \param session_data A data pointer to a session context.
  * \param data A pointer to the buffer which will receive the data.
  * \param length The number of bytes to read.
  * \param address Byte offset specifying where in the partition to
  *                start reading from.
  * \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.
  */
Wrapper around read_cache_wallet_storage() which also decrypts data
using aes_xts_internal(). Because this uses encryption, it is much slower
than read_cache_wallet_storage(). The parameters and return values are
identical to that of read_cache_wallet_storage(). It is to be
used internally (only by the functions of the TA itself).
\param session_data A data pointer to a session context.
\param data A pointer to the buffer which will receive the data.
\param length The number of bytes to read.
\param address Byte offset specifying where in the partition to
start reading from.
\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.
Wrapper around read_cache_wallet_storage () which also decrypts data using aes_xts_internal () . Because this uses encryption it is much slower than read_cache_wallet_storage () . The parameters and return values are identical to that of read_cache_wallet_storage () . It is to be used internally ( only by the functions of the TA itself ) . \ param session_data A data pointer to a session context . \ param data A pointer to the buffer which will receive the data . \ param length The number of bytes to read . \ param address Byte offset specifying where in the partition to start reading from . \ 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 encrypted_read_wallet_storage_internal(Session_data * session_data, uint8_t *data, uint32_t length, uint32_t address)
{
	TEE_Result result = TEE_SUCCESS;
	uint8_t ciphertext[length];
	uint8_t plaintext[length];
	TEE_Param read_params[4];
	uint32_t read_param_types;
	read_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_OUTPUT,
							TEE_PARAM_TYPE_VALUE_INOUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	if ((address + length) < address)
		return TEE_ERROR_BAD_PARAMETERS;
	read_params[0].memref.buffer = (uint8_t *)ciphertext;
	read_params[0].memref.size = length;
	read_params[1].value.a = address;
	result = read_cache_wallet_storage(session_data,
									read_param_types,
									read_params);
	if (result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Read wallet storage failed : 0x%x", result);
		#endif
		goto cleanup1;
	}
	result = aes_xts_internal(session_data,
							TEE_MODE_DECRYPT,
							ciphertext,
							length,
							plaintext,
							length);
	if (result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("AES XTS Decrypt failed : 0x%x", result);
		#endif
		goto cleanup1;
	}
	TEE_MemMove((uint8_t*)data, (uint8_t*)plaintext, length);
	cleanup1:
		return result;
}
static TEE_Result encrypted_read_wallet_storage_internal ( Session_data * session_data , uint8_t * data , uint32_t length , uint32_t address ) { TEE_Result result = TEE_SUCCESS ; uint8_t ciphertext [ length ] ; uint8_t plaintext [ length ] ; TEE_Param read_params [ 4 ] ; uint32_t read_param_types ; read_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_OUTPUT , TEE_PARAM_TYPE_VALUE_INOUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; if ( ( address + length ) < address ) return TEE_ERROR_BAD_PARAMETERS ; read_params [ 0 ] . memref . buffer = ( uint8_t * ) ciphertext ; read_params [ 0 ] . memref . size = length ; read_params [ 1 ] . value . a = address ; result = read_cache_wallet_storage ( session_data , read_param_types , read_params ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } result = aes_xts_internal ( session_data , TEE_MODE_DECRYPT , ciphertext , length , plaintext , length ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } TEE_MemMove ( ( uint8_t * ) data , ( uint8_t * ) plaintext , length ) ; cleanup1 : return result ; }
Wrapper around read_cache_wallet_storage() which also decrypts data
 using aes_xts_internal().
Wrapper around read_cache_wallet_storage () which also decrypts data using aes_xts_internal () .
/* Declare the read operation parameters */ /*
	 * Read parameters:
	 * [OUT] params[0].memref.buffer -> Buffer to store the read data.
	 * [OUT] params[0].memref.size   -> Size of the buffer.
	 * [IN]  params[1].value.a       -> Starting address of the reading.
	 * [OUT] params[1].value.b       -> Size actually read.
	 */ /* Check if the address overflows */ /* Define the read operation parameters */ /* Read the data from the storage */ /* Decrypt the data read */ /* Copy the plain text to the output buffer */