ta/wallet_ta.c
/**
  * Compare two multi-precision numbers of arbitrary size.It is
  * to be used internally (only by the functions of the TA itself).
  * \param op1 One of the numbers to compare.
  * \param op2 The other number to compare. This may alias op1.
  * \param size The size of the multi-precision numbers op1 and op2, in number
  *             of bytes.
  * \return #BIGCMP_GREATER if op1 > op2, #BIGCMP_EQUAL if they're equal
  *         and #BIGCMP_LESS if op1 < op2.
  */
Compare two multi-precision numbers of arbitrary size.It is
to be used internally (only by the functions of the TA itself).
\param op1 One of the numbers to compare.
\param op2 The other number to compare. This may alias op1.
\param size The size of the multi-precision numbers op1 and op2, in number
of bytes.
\return #BIGCMP_GREATER if op1 > op2, #BIGCMP_EQUAL if they're equal
and #BIGCMP_LESS if op1 < op2.
Compare two multi - precision numbers of arbitrary size . It is to be used internally ( only by the functions of the TA itself ) . \ param op1 One of the numbers to compare . \ param op2 The other number to compare . This may alias op1 . \ param size The size of the multi - precision numbers op1 and op2 in number of bytes . \ return #BIGCMP_GREATER if op1 > op2 #BIGCMP_EQUAL if they ' re equal and #BIGCMP_LESS if op1 < op2 .
static uint8_t big_compare_variable_size_internal(uint8_t *op1, uint8_t *op2, uint8_t size)
{
	uint8_t i;
	uint8_t r;
	uint8_t cmp;
	r = BIGCMP_EQUAL;
	for (i = (uint8_t)(size - 1); i < size; i--)
	{
		cmp = (uint8_t)((((uint16_t)((int)op2[i] - (int)op1[i])) >> 8) & BIGCMP_GREATER);
		r = (uint8_t)(((((uint16_t)(-(int)r)) >> 8) & (r ^ cmp)) ^ cmp);
		cmp = (uint8_t)((((uint16_t)((int)op1[i] - (int)op2[i])) >> 8) & BIGCMP_LESS);
		r = (uint8_t)(((((uint16_t)(-(int)r)) >> 8) & (r ^ cmp)) ^ cmp);
	}
	return r;
}
static uint8_t big_compare_variable_size_internal ( uint8_t * op1 , uint8_t * op2 , uint8_t size ) { uint8_t i ; uint8_t r ; uint8_t cmp ; r = BIGCMP_EQUAL ; for ( i = ( uint8_t ) ( size - 1 ) ; i < size ; i -- ) { cmp = ( uint8_t ) ( ( ( ( uint16_t ) ( ( int ) op2 [ i ] - ( int ) op1 [ i ] ) ) >> 8 ) & BIGCMP_GREATER ) ; r = ( uint8_t ) ( ( ( ( ( uint16_t ) ( - ( int ) r ) ) >> 8 ) & ( r ^ cmp ) ) ^ cmp ) ; cmp = ( uint8_t ) ( ( ( ( uint16_t ) ( ( int ) op1 [ i ] - ( int ) op2 [ i ] ) ) >> 8 ) & BIGCMP_LESS ) ; r = ( uint8_t ) ( ( ( ( ( uint16_t ) ( - ( int ) r ) ) >> 8 ) & ( r ^ cmp ) ) ^ cmp ) ; } return r ; }
Compare two multi-precision numbers of arbitrary size.It is
 to be used internally (only by the functions of the TA itself).
Compare two multi - precision numbers of arbitrary size . It is to be used internally ( only by the functions of the TA itself ) .
/*
		 * The following code is a branch free way of doing:
		 * if (r == BIGCMP_EQUAL)
		 * {
		 *     if (op1[i] > op2[i])
		 *     {
		 *         r = BIGCMP_GREATER;
		 *     }
		 * }
		 * if (r == BIGCMP_EQUAL)
		 * {
		 *     if (op2[i] > op1[i])
		 *     {
		 *         r = BIGCMP_LESS;
		 *     }
		 * }
		 * Note that it relies on BIGCMP_EQUAL having the value 0.
		 * It inspired by the code at:
		 * http://aggregate.ee.engr.uky.edu/MAGIC/#Integer%20Selection
		 */