ta/wallet_ta.c
/** Just like sha256_final() except this does a double SHA-256 hash. A
  * double SHA-256 hash is sometimes used in the Bitcoin protocol.
  * \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 TEE Client API Specification - 4.4.2
  *         published by GlobalPlatform.
  */
Just like sha256_final() except this does a double SHA-256 hash. A
double SHA-256 hash is sometimes used in the Bitcoin protocol.
\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 TEE Client API Specification - 4.4.2
published by GlobalPlatform.
Just like sha256_final () except this does a double SHA - 256 hash . A double SHA - 256 hash is sometimes used in the Bitcoin protocol . \ 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 TEE Client API Specification - 4 . 4 . 2 published by GlobalPlatform .
static TEE_Result sha256_final_double(Session_data * session_data, uint32_t param_types, TEE_Param params[4])
{
	TEE_Result result = TEE_SUCCESS;
	TEE_OperationHandle * sha_op_handle;
	int sha_op_selc;
	uint32_t exp_param_types;
	uint32_t written_hash_length;
	uint32_t hash_u32[8];
	uint8_t * hash_u8;
	uint8_t temp[32];
	exp_param_types = TEE_PARAM_TYPES(
							TEE_PARAM_TYPE_MEMREF_OUTPUT,
							TEE_PARAM_TYPE_VALUE_INPUT,
							TEE_PARAM_TYPE_NONE,
							TEE_PARAM_TYPE_NONE);
	if (exp_param_types != param_types)
		return TEE_ERROR_BAD_PARAMETERS;
	sha_op_selc = (int)(params[1].value.a);
	switch (sha_op_selc)
    {
        case 1:
            sha_op_handle = session_data->sha_op1;
            break;
        case 2:
            sha_op_handle = session_data->sha_op2;
            break;
        case 3:
            sha_op_handle = session_data->sha_op3;
            break;
        case 4:
            sha_op_handle = session_data->sha_op4;
            break;
        default:
            return TEE_ERROR_BAD_PARAMETERS;
    };
	hash_u8 = (uint8_t*)(params[0].memref.buffer);
	written_hash_length = (uint32_t)params[0].memref.size;
	result = TEE_DigestDoFinal(*sha_op_handle, NULL, 0, (uint8_t*)hash_u8, &written_hash_length);
	if(result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to finalize the hashing operation (SHA-256): 0x%x", result);
		#endif
		goto cleanup1;
	}
	convert_from8_to32_BE_internal(hash_u8, hash_u32);
	write_hash_to_byte_array_internal(temp, hash_u32, true);
	TEE_ResetOperation(*sha_op_handle);
	TEE_DigestUpdate(*sha_op_handle, (uint8_t*)temp, (uint32_t)32);
	result = TEE_DigestDoFinal(*sha_op_handle, NULL, 0, (uint8_t*)hash_u8, &written_hash_length);
	if(result != TEE_SUCCESS)
	{
		#ifdef OP_TEE_TA
		DMSG("Failed to finalize the hashing operation (SHA-256): 0x%x", result);
		#endif
		goto cleanup1;
	}
	params[0].memref.size = (uint32_t)written_hash_length;
	cleanup1:
		return result;
}
static TEE_Result sha256_final_double ( Session_data * session_data , uint32_t param_types , TEE_Param params [ 4 ] ) { TEE_Result result = TEE_SUCCESS ; TEE_OperationHandle * sha_op_handle ; int sha_op_selc ; uint32_t exp_param_types ; uint32_t written_hash_length ; uint32_t hash_u32 [ 8 ] ; uint8_t * hash_u8 ; uint8_t temp [ 32 ] ; exp_param_types = TEE_PARAM_TYPES ( TEE_PARAM_TYPE_MEMREF_OUTPUT , TEE_PARAM_TYPE_VALUE_INPUT , TEE_PARAM_TYPE_NONE , TEE_PARAM_TYPE_NONE ) ; if ( exp_param_types != param_types ) return TEE_ERROR_BAD_PARAMETERS ; sha_op_selc = ( int ) ( params [ 1 ] . value . a ) ; switch ( sha_op_selc ) { case 1 : sha_op_handle = session_data -> sha_op1 ; break ; case 2 : sha_op_handle = session_data -> sha_op2 ; break ; case 3 : sha_op_handle = session_data -> sha_op3 ; break ; case 4 : sha_op_handle = session_data -> sha_op4 ; break ; default : return TEE_ERROR_BAD_PARAMETERS ; } ; hash_u8 = ( uint8_t * ) ( params [ 0 ] . memref . buffer ) ; written_hash_length = ( uint32_t ) params [ 0 ] . memref . size ; result = TEE_DigestDoFinal ( * sha_op_handle , NULL , 0 , ( uint8_t * ) hash_u8 , & written_hash_length ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } convert_from8_to32_BE_internal ( hash_u8 , hash_u32 ) ; write_hash_to_byte_array_internal ( temp , hash_u32 , true ) ; TEE_ResetOperation ( * sha_op_handle ) ; TEE_DigestUpdate ( * sha_op_handle , ( uint8_t * ) temp , ( uint32_t ) 32 ) ; result = TEE_DigestDoFinal ( * sha_op_handle , NULL , 0 , ( uint8_t * ) hash_u8 , & written_hash_length ) ; if ( result != TEE_SUCCESS ) { #ifdef OP_TEE_TA DMSG ( " " , result ) ; #endif goto cleanup1 ; } params [ 0 ] . memref . size = ( uint32_t ) written_hash_length ; cleanup1 : return result ; }
Just like sha256_final() except this does a double SHA-256 hash.
Just like sha256_final () except this does a double SHA - 256 hash .
/*
	 * Expected:
	 * [OUT] params[0].memref.buffer -> Hash buffer.
	 * [OUT] params[0].memref.size   -> Length of the hash buffer.
	 */ /* Sanity check on the parameters received */ /* Get the desired SHA-256 operation handle number */ /* Choose the operation handle accordingly */ /* Do the first digest final */ /* Initialize the operation */ /* Update the content to hash */ /* Do the last digest final */ /* Update size to the one actually hashed */