ta/wallet_ta.c
/**
  * Multiplies (r = (op1 x op2) modulo #n) two 32 byte multi-precision
  * numbers under the current prime finite field. 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 r The 32 byte result will be written into here.
  * \param op1 The first 32 byte operand to multiply. This may alias r.
  * \param op2 The second 32 byte operand to multiply. This may alias r or
  *            op1.
  */
Multiplies (r = (op1 x op2) modulo #n) two 32 byte multi-precision
numbers under the current prime finite field. 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 r The 32 byte result will be written into here.
\param op1 The first 32 byte operand to multiply. This may alias r.
\param op2 The second 32 byte operand to multiply. This may alias r or
op1.
Multiplies ( r = ( op1 x op2 ) modulo #n ) two 32 byte multi - precision numbers under the current prime finite field . 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 r The 32 byte result will be written into here . \ param op1 The first 32 byte operand to multiply . This may alias r . \ param op2 The second 32 byte operand to multiply . This may alias r or op1 .
static void big_multiply_internal(Session_data * session_data, BigNum256 r, BigNum256 op1, BigNum256 op2)
{
	uint8_t temp[64];
	uint8_t full_r[64];
	uint8_t remaining;
	big_multiply_variable_size_no_modulo_internal(full_r, op1, 32, op2, 32);
	remaining = 64;
	while (remaining > 32)
	{
		TEE_MemFill((uint8_t*)temp, (uint32_t)0, (uint32_t)64);
		big_multiply_variable_size_no_modulo_internal(\
			temp,
			session_data->complement_n, session_data->size_complement_n,
			&(full_r[32]), (uint8_t)(remaining - 32));
		TEE_MemFill((uint8_t*)&(full_r[32]), (uint32_t)0, (uint32_t)32);
		big_add_variable_size_no_modulo_internal(full_r,
												full_r,
												temp,
												remaining);
		remaining = (uint8_t)(remaining - 32 + session_data->size_complement_n);
	}
	big_modulo_internal(session_data, full_r, full_r);
	big_assign_internal(r, full_r);
}
static void big_multiply_internal ( Session_data * session_data , BigNum256 r , BigNum256 op1 , BigNum256 op2 ) { uint8_t temp [ 64 ] ; uint8_t full_r [ 64 ] ; uint8_t remaining ; big_multiply_variable_size_no_modulo_internal ( full_r , op1 , 32 , op2 , 32 ) ; remaining = 64 ; while ( remaining > 32 ) { TEE_MemFill ( ( uint8_t * ) temp , ( uint32_t ) 0 , ( uint32_t ) 64 ) ; big_multiply_variable_size_no_modulo_internal ( temp , session_data -> complement_n , session_data -> size_complement_n , & ( full_r [ 32 ] ) , ( uint8_t ) ( remaining - 32 ) ) ; TEE_MemFill ( ( uint8_t * ) & ( full_r [ 32 ] ) , ( uint32_t ) 0 , ( uint32_t ) 32 ) ; big_add_variable_size_no_modulo_internal ( full_r , full_r , temp , remaining ) ; remaining = ( uint8_t ) ( remaining - 32 + session_data -> size_complement_n ) ; } big_modulo_internal ( session_data , full_r , full_r ) ; big_assign_internal ( r , full_r ) ; }
Multiplies (r = (op1 x op2) modulo #n) two 32 byte multi-precision
 numbers under the current prime finite field.
Multiplies ( r = ( op1 x op2 ) modulo #n ) two 32 byte multi - precision numbers under the current prime finite field .
/*
	 * The modular reduction is done by subtracting off some multiple of
	 * n. The upper 256 bits of r are used as an estimate for that multiple.
	 * As long as n is close to 2 ^ 256, this estimate should be very close.
	 * However, since n < 2 ^ 256, the estimate will always be an
	 * underestimate. That's okay, because the algorithm can be applied
	 * repeatedly, until the upper 256 bits of r are zero.
	 * remaining denotes the maximum number of possible non-zero bytes left in
	 * the result.
	 */ /*
		 * n should be equal to 2 ^ 256 - complement_n. Therefore, subtracting
		 * off (upper 256 bits of r) * n is equivalent to setting the
		 * upper 256 bits of r to 0 and
		 * adding (upper 256 bits of r) * complement_n.
		 */ /* This update of the bound is only valid for remaining > 32. */ /*
	 * The upper 256 bits of r should now be 0. But r could still be >= n.
	 * As long as n > 2 ^ 255, at most one subtraction is
	 * required to ensure that r < n.
	 */