ta/wallet_ta.c
/**
  * Perform scalar multiplication (p = k x p) of the point p by the scalar k.
  * The result will be stored back into p. The multiplication is
  * accomplished by repeated point doubling and adding of the
  * original point. All multi-precision integer operations are done under
  * the prime finite field specified by #secp256k1_p. 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 p The point (in affine coordinates) to multiply.
  * \param k The 32 byte multi-precision scalar to multiply p by.
  */
Perform scalar multiplication (p = k x p) of the point p by the scalar k.
The result will be stored back into p. The multiplication is
accomplished by repeated point doubling and adding of the
original point. All multi-precision integer operations are done under
the prime finite field specified by #secp256k1_p. 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 p The point (in affine coordinates) to multiply.
\param k The 32 byte multi-precision scalar to multiply p by.
Perform scalar multiplication ( p = k x p ) of the point p by the scalar k . The result will be stored back into p . The multiplication is accomplished by repeated point doubling and adding of the original point . All multi - precision integer operations are done under the prime finite field specified by #secp256k1_p . 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 p The point ( in affine coordinates ) to multiply . \ param k The 32 byte multi - precision scalar to multiply p by .
static void point_multiply_internal(Session_data *session_data, PointAffine *p, BigNum256 k)
{
	PointJacobian accumulator;
	PointJacobian junk;
	PointAffine always_point_at_infinity; 
	uint8_t i;
	uint8_t j;
	uint8_t one_byte;
	uint8_t one_bit;
	PointAffine *lookup_affine[2];
	TEE_MemFill((PointJacobian*)&accumulator,
				(uint32_t)0,
				(uint32_t)sizeof(PointJacobian));
	TEE_MemFill((PointJacobian*)&junk,
				(uint32_t)0,
				(uint32_t)sizeof(PointJacobian));
	TEE_MemFill((PointAffine*)&always_point_at_infinity,
				(uint32_t)0,
				(uint32_t)sizeof(PointAffine));
	set_field_to_p_internal(session_data);
	accumulator.is_point_at_infinity = 1;
	always_point_at_infinity.is_point_at_infinity = 1;
	lookup_affine[1] = p;
	lookup_affine[0] = &always_point_at_infinity;
	for (i = 31; i < 32; i--)
	{
		one_byte = k[i];
		for (j = 0; j < 8; j++)
		{
			point_double_internal(session_data, &accumulator);
			one_bit = (uint8_t)((one_byte & 0x80) >> 7);
			point_add_internal(session_data,
								&accumulator,
								&junk,
								lookup_affine[one_bit]);
			one_byte = (uint8_t)(one_byte << 1);
		}
	}
	jacobian_to_affine_internal(session_data, p, &accumulator);
}
static void point_multiply_internal ( Session_data * session_data , PointAffine * p , BigNum256 k ) { PointJacobian accumulator ; PointJacobian junk ; PointAffine always_point_at_infinity ; uint8_t i ; uint8_t j ; uint8_t one_byte ; uint8_t one_bit ; PointAffine * lookup_affine [ 2 ] ; TEE_MemFill ( ( PointJacobian * ) & accumulator , ( uint32_t ) 0 , ( uint32_t ) sizeof ( PointJacobian ) ) ; TEE_MemFill ( ( PointJacobian * ) & junk , ( uint32_t ) 0 , ( uint32_t ) sizeof ( PointJacobian ) ) ; TEE_MemFill ( ( PointAffine * ) & always_point_at_infinity , ( uint32_t ) 0 , ( uint32_t ) sizeof ( PointAffine ) ) ; set_field_to_p_internal ( session_data ) ; accumulator . is_point_at_infinity = 1 ; always_point_at_infinity . is_point_at_infinity = 1 ; lookup_affine [ 1 ] = p ; lookup_affine [ 0 ] = & always_point_at_infinity ; for ( i = 31 ; i < 32 ; i -- ) { one_byte = k [ i ] ; for ( j = 0 ; j < 8 ; j ++ ) { point_double_internal ( session_data , & accumulator ) ; one_bit = ( uint8_t ) ( ( one_byte & 0x80 ) >> 7 ) ; point_add_internal ( session_data , & accumulator , & junk , lookup_affine [ one_bit ] ) ; one_byte = ( uint8_t ) ( one_byte << 1 ) ; } } jacobian_to_affine_internal ( session_data , p , & accumulator ) ; }
Perform scalar multiplication (p = k x p) of the point p by the scalar k.
 The result will be stored back into p. The multiplication is
 accomplished by repeated point doubling and adding of the
 original point.
Perform scalar multiplication ( p = k x p ) of the point p by the scalar k . The result will be stored back into p . The multiplication is accomplished by repeated point doubling and adding of the original point .
/* for dummy operations */ /*
	* The Montgomery ladder method can't be used here because it requires
	* point addition to be done in pure Jacobian coordinates. Point addition
	* in pure Jacobian coordinates would make point multiplication about
	* 26% slower. Instead, dummy operations are used to make point
	* multiplication a constant time operation. However, the use of dummy
	* operations does make this code more susceptible to fault analysis -
	* by introducing faults where dummy operations may occur, an attacker
	* can determine whether bits in the private key are set or not.
	* So the use of this code is not appropriate in situations where fault
	* analysis can occur.
	*/