bigint_shrink ( (source), (dest) ); \
} while ( 0 )
+/**
+ * Conditionally swap big integers (in constant time)
+ *
+ * @v first Big integer to be conditionally swapped
+ * @v second Big integer to be conditionally swapped
+ * @v swap Swap first and second big integers
+ */
+#define bigint_swap( first, second, swap ) do { \
+ unsigned int size = bigint_size (first); \
+ bigint_swap_raw ( (first)->element, (second)->element, size, \
+ (swap) ); \
+ } while ( 0 )
+
/**
* Multiply big integers
*
void bigint_shrink_raw ( const bigint_element_t *source0,
unsigned int source_size, bigint_element_t *dest0,
unsigned int dest_size );
+void bigint_swap_raw ( bigint_element_t *first0, bigint_element_t *second0,
+ unsigned int size, int swap );
void bigint_multiply_raw ( const bigint_element_t *multiplicand0,
unsigned int multiplicand_size,
const bigint_element_t *multiplier0,
bigint_copy ( source, dest );
}
+void bigint_swap_sample ( bigint_element_t *first0, bigint_element_t *second0,
+ unsigned int size, int swap ) {
+ bigint_t ( size ) *first __attribute__ (( may_alias ))
+ = ( ( void * ) first0 );
+ bigint_t ( size ) *second __attribute__ (( may_alias ))
+ = ( ( void * ) second0 );
+
+ bigint_swap ( first, second, swap );
+}
+
void bigint_multiply_sample ( const bigint_element_t *multiplicand0,
unsigned int multiplicand_size,
const bigint_element_t *multiplier0,
ok ( max_set_bit == (expected) ); \
} while ( 0 )
+/**
+ * Report result of big integer swap test
+ *
+ * @v first Big integer to be conditionally swapped
+ * @v second Big integer to be conditionally swapped
+ */
+#define bigint_swap_ok( first, second ) do { \
+ static const uint8_t first_raw[] = first; \
+ static const uint8_t second_raw[] = second; \
+ uint8_t temp[ sizeof ( first_raw ) ]; \
+ unsigned int size = bigint_required_size ( sizeof ( temp) ); \
+ bigint_t ( size ) first_temp; \
+ bigint_t ( size ) second_temp; \
+ {} /* Fix emacs alignment */ \
+ \
+ assert ( sizeof ( first_raw ) == sizeof ( temp ) ); \
+ assert ( sizeof ( second_raw ) == sizeof ( temp ) ); \
+ bigint_init ( &first_temp, first_raw, sizeof ( first_raw ) ); \
+ bigint_init ( &second_temp, second_raw, sizeof ( second_raw ) );\
+ bigint_swap ( &first_temp, &second_temp, 0 ); \
+ bigint_done ( &first_temp, temp, sizeof ( temp ) ); \
+ ok ( memcmp ( temp, first_raw, sizeof ( temp ) ) == 0 ); \
+ bigint_done ( &second_temp, temp, sizeof ( temp ) ); \
+ ok ( memcmp ( temp, second_raw, sizeof ( temp ) ) == 0 ); \
+ bigint_swap ( &first_temp, &second_temp, 1 ); \
+ bigint_done ( &first_temp, temp, sizeof ( temp ) ); \
+ ok ( memcmp ( temp, second_raw, sizeof ( temp ) ) == 0 ); \
+ bigint_done ( &second_temp, temp, sizeof ( temp ) ); \
+ ok ( memcmp ( temp, first_raw, sizeof ( temp ) ) == 0 ); \
+ bigint_swap ( &first_temp, &second_temp, 1 ); \
+ bigint_done ( &first_temp, temp, sizeof ( temp ) ); \
+ ok ( memcmp ( temp, first_raw, sizeof ( temp ) ) == 0 ); \
+ bigint_done ( &second_temp, temp, sizeof ( temp ) ); \
+ ok ( memcmp ( temp, second_raw, sizeof ( temp ) ) == 0 ); \
+ } while ( 0 )
+
/**
* Report result of big integer multiplication test
*
0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff ),
1024 );
+ bigint_swap_ok ( BIGINT ( 0x68, 0x65, 0x6c, 0x6c, 0x6f ),
+ BIGINT ( 0x77, 0x6f, 0x72, 0x6c, 0x64 ) );
+ bigint_swap_ok ( BIGINT ( 0xc8, 0x1c, 0x31, 0xd7, 0x13, 0x69, 0x47,
+ 0x32, 0xb0, 0x0a, 0xf7, 0x2d, 0xb9, 0xc3,
+ 0x35, 0x96 ),
+ BIGINT ( 0x8b, 0x1d, 0x8f, 0x21, 0x76, 0x16, 0x4c,
+ 0xf8, 0xb2, 0x63, 0xed, 0x89, 0x5e, 0x6b,
+ 0x35, 0x7c ) );
bigint_multiply_ok ( BIGINT ( 0xf0 ),
BIGINT ( 0xeb ),
BIGINT ( 0xdc, 0x50 ) );