ta/wallet_ta.c
/** Generate a new address using the deterministic private key generator.
  * \param session_data A data pointer to a session context.
  * \param param_types The types of the four parameters.
  * \param params A pointer to an array of four parameters.
  * \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
  */
Generate a new address using the deterministic private key generator.
\param session_data A data pointer to a session context.
\param param_types The types of the four parameters.
\param params A pointer to an array of four parameters.
\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
Generate a new address using the deterministic private key generator . \ param session_data A data pointer to a session context . \ param param_types The types of the four parameters . \ param params A pointer to an array of four parameters . \ 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
static TEE_Result make_new_address(Session_data * session_data, uint32_t param_types, TEE_Param params[4])
{
	AddressHandle ah_return = BAD_ADDRESS_HANDLE;
	WalletErrors wallet_error = WALLET_NO_ERROR;
	TEE_Result result = TEE_SUCCESS;
	uint32_t exp_param_types;
	TEE_Param wcwr_params[4];
	uint32_t wcwr_param_types;
	TEE_Param gaapk_params[4];
	uint32_t gaapk_param_types;
	exp_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_OUTPUT,
							TEE_PARAM_TYPE_MEMREF_OUTPUT,
							TEE_PARAM_TYPE_VALUE_OUTPUT,
							TEE_PARAM_TYPE_NONE);
	wcwr_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_VALUE_INPUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	gaapk_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_OUTPUT,
							TEE_PARAM_TYPE_MEMREF_OUTPUT,
							TEE_PARAM_TYPE_VALUE_INOUT,
							TEE_PARAM_TYPE_NONE);
	if (param_types != exp_param_types
		|| params[0].memref.buffer == NULL
		|| params[1].memref.buffer == NULL)
		return TEE_ERROR_BAD_PARAMETERS;
	if (!(session_data->wallet_loaded))
	{
		result = TEE_ERROR_BAD_STATE;
		wallet_error = WALLET_NOT_LOADED;
		goto cleanup1;
	}
	if (session_data->current_wallet->encrypted.num_addresses >= MAX_ADDRESSES)
	{
		result = TEE_ERROR_BAD_STATE;
		wallet_error = WALLET_FULL;
		goto cleanup1;
	}
	(session_data->current_wallet->encrypted.num_addresses)++;
	result = calculate_wallet_checksum_internal(
							session_data,
							session_data->current_wallet->encrypted.checksum);
	if(result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to do calculate_wallet_checksum_internal operation : 0x%x", result);
		#endif
		result = TEE_ERROR_CANCEL;
		wallet_error = WALLET_INVALID_OPERATION;
		goto cleanup1;
	}
	wcwr_params[0].value.a = session_data->wallet_nv_address;
	result = write_current_wallet_record(session_data,
										wcwr_param_types,
										wcwr_params);
	if(result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to do write_current_wallet_record operation : 0x%x", result);
		#endif
		wallet_error = WALLET_WRITE_ERROR;
		goto cleanup1;
	}
	gaapk_params[0].memref.buffer = (uint8_t*)(params[0].memref.buffer);
	gaapk_params[0].memref.size = params[0].memref.size;
	gaapk_params[1].memref.buffer = (PointAffine*)(params[1].memref.buffer);
	gaapk_params[1].memref.size = params[1].memref.size;
	gaapk_params[2].value.a = (uint32_t)(session_data->current_wallet->encrypted.num_addresses);
	result = get_address_and_public_key(session_data,
										gaapk_param_types,
										gaapk_params);
	wallet_error = (WalletErrors)(gaapk_params[2].value.b);
	if (wallet_error != WALLET_NO_ERROR)
		ah_return = BAD_ADDRESS_HANDLE;
	else
		ah_return = session_data->current_wallet->encrypted.num_addresses;
	cleanup1:
		params[2].value.a = (uint32_t)ah_return;
		params[2].value.b = (uint32_t)wallet_error;
		return result;
}
static TEE_Result make_new_address ( Session_data * session_data , uint32_t param_types , TEE_Param params [ 4 ] ) { AddressHandle ah_return = BAD_ADDRESS_HANDLE ; WalletErrors wallet_error = WALLET_NO_ERROR ; TEE_Result result = TEE_SUCCESS ; uint32_t exp_param_types ; TEE_Param wcwr_params [ 4 ] ; uint32_t wcwr_param_types ; TEE_Param gaapk_params [ 4 ] ; uint32_t gaapk_param_types ; exp_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_OUTPUT , TEE_PARAM_TYPE_MEMREF_OUTPUT , TEE_PARAM_TYPE_VALUE_OUTPUT , TEE_PARAM_TYPE_NONE ) ; wcwr_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_VALUE_INPUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; gaapk_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_OUTPUT , TEE_PARAM_TYPE_MEMREF_OUTPUT , TEE_PARAM_TYPE_VALUE_INOUT , TEE_PARAM_TYPE_NONE ) ; if ( param_types != exp_param_types || params [ 0 ] . memref . buffer == NULL || params [ 1 ] . memref . buffer == NULL ) return TEE_ERROR_BAD_PARAMETERS ; if ( ! ( session_data -> wallet_loaded ) ) { result = TEE_ERROR_BAD_STATE ; wallet_error = WALLET_NOT_LOADED ; goto cleanup1 ; } if ( session_data -> current_wallet -> encrypted . num_addresses >= MAX_ADDRESSES ) { result = TEE_ERROR_BAD_STATE ; wallet_error = WALLET_FULL ; goto cleanup1 ; } ( session_data -> current_wallet -> encrypted . num_addresses ) ++ ; result = calculate_wallet_checksum_internal ( session_data , session_data -> current_wallet -> encrypted . checksum ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif result = TEE_ERROR_CANCEL ; wallet_error = WALLET_INVALID_OPERATION ; goto cleanup1 ; } wcwr_params [ 0 ] . value . a = session_data -> wallet_nv_address ; result = write_current_wallet_record ( session_data , wcwr_param_types , wcwr_params ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif wallet_error = WALLET_WRITE_ERROR ; goto cleanup1 ; } gaapk_params [ 0 ] . memref . buffer = ( uint8_t * ) ( params [ 0 ] . memref . buffer ) ; gaapk_params [ 0 ] . memref . size = params [ 0 ] . memref . size ; gaapk_params [ 1 ] . memref . buffer = ( PointAffine * ) ( params [ 1 ] . memref . buffer ) ; gaapk_params [ 1 ] . memref . size = params [ 1 ] . memref . size ; gaapk_params [ 2 ] . value . a = ( uint32_t ) ( session_data -> current_wallet -> encrypted . num_addresses ) ; result = get_address_and_public_key ( session_data , gaapk_param_types , gaapk_params ) ; wallet_error = ( WalletErrors ) ( gaapk_params [ 2 ] . value . b ) ; if ( wallet_error != WALLET_NO_ERROR ) ah_return = BAD_ADDRESS_HANDLE ; else ah_return = session_data -> current_wallet -> encrypted . num_addresses ; cleanup1 : params [ 2 ] . value . a = ( uint32_t ) ah_return ; params [ 2 ] . value . b = ( uint32_t ) wallet_error ; return result ; }
Generate a new address using the deterministic private key generator.
Generate a new address using the deterministic private key generator .
/* Declare writeCurrentWallet operation parameters */ /*
	 * Expected:
	 * [OUT] params[0].memref.buffer -> Buffer to write the address.
	 * [OUT] params[0].memref.size   -> Size of the buffer.
	 * [OUT] params[1].memref.buffer -> Buffer to write the public key.
	 * [OUT] params[1].memref.size   -> Size of the buffer.
	 * [OUT] params[2].value.a 		 -> AddressHandle return.
	 * [OUT] params[2].value.b 		 -> WalletErros return.
	 */ /*
	 * writeCurrentWallet parameters:
	 * [IN]  params[0].value.a    -> Address to write the current wallet record.
	 */ /*
	 * Expected:
	 * [OUT] params[0].memref.buffer -> Buffer with the address hashed with sha256.
	 * [OUT] params[0].memref.size   -> Size of the buffer.
	 * [OUT] params[1].memref.buffer -> Buffer to write the public key.
	 * [OUT] params[1].memref.size   -> Size of the buffer.
	 * [IN]  params[2].value.a 		 -> Address handle.
	 * [OUT] params[2].value.b 		 -> WalletErrors return.
	 */ /* Some sanity checks */ /* Calculate the wallet checksum */ /*
		 * Just to guarantee that the result is different than
		 * TEE_ERROR_BAD_STRATE
		 */ /*
		 * Here we needed an wallet_error because otherwise even if the operation
		 * failed it would say that there wasn't any error (because the default
		 * value is WALLET_NO_ERROR) so the value chosen was invalid operation
		 */ /* Write the current wallet record into the storage */ /* Define the parameters for the getAddressAndPublicKey function */ /* Resources cleanup */