ta/wallet_ta.c
/** Performs the encryption/decryption of data using AES-XTS.
  * \param session_data A data pointer to a session context.
  * \param mode To decrypt, use TEE_MODE_ENCRYPT. To encrypt, use TEE_MODE_DECRYPT.
  * \param src_data A pointer to an array which contain the data to decrypt or encrypt.
  * \param src_len Size of the array pointed by src_data.
  * \param dest_data A pointer to an array which contain the data decrypted or encrypted.
  * \param dest_len Size of the array pointed by dest_data.
  * \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.
  */
Performs the encryption/decryption of data using AES-XTS.
\param session_data A data pointer to a session context.
\param mode To decrypt, use TEE_MODE_ENCRYPT. To encrypt, use TEE_MODE_DECRYPT.
\param src_data A pointer to an array which contain the data to decrypt or encrypt.
\param src_len Size of the array pointed by src_data.
\param dest_data A pointer to an array which contain the data decrypted or encrypted.
\param dest_len Size of the array pointed by dest_data.
\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.
Performs the encryption / decryption of data using AES - XTS . \ param session_data A data pointer to a session context . \ param mode To decrypt use TEE_MODE_ENCRYPT . To encrypt use TEE_MODE_DECRYPT . \ param src_data A pointer to an array which contain the data to decrypt or encrypt . \ param src_len Size of the array pointed by src_data . \ param dest_data A pointer to an array which contain the data decrypted or encrypted . \ param dest_len Size of the array pointed by dest_data . \ 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 aes_xts_internal(Session_data * session_data, TEE_OperationMode mode, uint8_t * src_data, uint32_t src_len, uint8_t * dest_data, uint32_t dest_len)
{
	TEE_Result result = TEE_SUCCESS;
	uint32_t written_bytes = dest_len;
	if (mode == TEE_MODE_ENCRYPT)
	{
		TEE_CipherInit(*(session_data->aes_encrypt_op),
						(uint8_t*)dummy_iv,
						(uint32_t)16);
		result = TEE_CipherDoFinal(*(session_data->aes_encrypt_op),
									(uint8_t*)src_data, src_len,
									(uint8_t*)dest_data,
									&written_bytes);
		if (result != TEE_SUCCESS)
		{
			#ifdef OP_TEE_TA
			DMSG("Failed to finalize the ciphering operation : 0x%x", result);
    		#endif
			goto cleanup1;
		}
		if (written_bytes != dest_len)
		{
			#ifdef OP_TEE_TA
			DMSG("Cipher operation didn't encrypt all the bytes requested : 0x%x", result);
    		#endif
			return TEE_ERROR_BAD_STATE;
		}
	}
	else if (mode == TEE_MODE_DECRYPT)
	{
		TEE_CipherInit(*(session_data->aes_decrypt_op),
						(uint8_t*)dummy_iv,
						(uint32_t)16);
		result = TEE_CipherDoFinal(*(session_data->aes_decrypt_op),
									(uint8_t*)src_data,
									src_len,
									(uint8_t*)dest_data,
									&written_bytes);
		if (result != TEE_SUCCESS)
		{
			#ifdef OP_TEE_TA
			DMSG("Cipher operation Do final failed : 0x%x", result);
			#endif
			goto cleanup1;
		}
		if (written_bytes != dest_len)
		{
			#ifdef OP_TEE_TA
			DMSG("Cipher operation didn't decrypt all the bytes requested : 0x%x", result);
			#endif
			return TEE_ERROR_BAD_STATE;
		}
	}
	else
		return TEE_ERROR_BAD_PARAMETERS;
	cleanup1:
		return result;
}
static TEE_Result aes_xts_internal ( Session_data * session_data , TEE_OperationMode mode , uint8_t * src_data , uint32_t src_len , uint8_t * dest_data , uint32_t dest_len ) { TEE_Result result = TEE_SUCCESS ; uint32_t written_bytes = dest_len ; if ( mode == TEE_MODE_ENCRYPT ) { TEE_CipherInit ( * ( session_data -> aes_encrypt_op ) , ( uint8_t * ) dummy_iv , ( uint32_t ) 16 ) ; result = TEE_CipherDoFinal ( * ( session_data -> aes_encrypt_op ) , ( uint8_t * ) src_data , src_len , ( uint8_t * ) dest_data , & written_bytes ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } if ( written_bytes != dest_len ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif return TEE_ERROR_BAD_STATE ; } } else if ( mode == TEE_MODE_DECRYPT ) { TEE_CipherInit ( * ( session_data -> aes_decrypt_op ) , ( uint8_t * ) dummy_iv , ( uint32_t ) 16 ) ; result = TEE_CipherDoFinal ( * ( session_data -> aes_decrypt_op ) , ( uint8_t * ) src_data , src_len , ( uint8_t * ) dest_data , & written_bytes ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } if ( written_bytes != dest_len ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif return TEE_ERROR_BAD_STATE ; } } else return TEE_ERROR_BAD_PARAMETERS ; cleanup1 : return result ; }
Performs the encryption/decryption of data using AES-XTS.
Performs the encryption / decryption of data using AES - XTS .
/* If it is an encryption operation */ /* Initialize the cipher operation */ /*
		 * Here we could do TEE_CipherUpdate() but as we will encrypt in only
		 * one operation it will not be needed
		 */ /* Finalize cipher operation */ /* Confirm that all bytes were written */ /*
			 * Here the return should be return TEE_ERROR_EXCESS_DATA;
			 * but as this will be treated as an error by the CA the most safest
			 * way is to set as TEE_ERROR_BAD_STATE to signal an operation that
			 * failed but without the needing to exit the program
			 */ /* If it is an decryption operation */ /* Initialize the cipher operation */ /*
		 * Here we could do TEE_CipherUpdate() but as we will encrypt in only
		 * one operation it will not be needed
		 */ /* Finalize cipher operation */ /* Confirm that all bytes were written */ /*
			 * Here the return should be return TEE_ERROR_EXCESS_DATA;
			 * but as this will be treated as an error by the CA the most safest
			 * way is to set as TEE_ERROR_BAD_STATE to signal an operation that
			 * failed but without the needing to exit the program
			 */