mirror of
https://github.com/ipxe/ipxe
synced 2026-04-16 03:00:10 +03:00
[crypto] Add bigint_swap() to conditionally swap big integers
Add a helper function bigint_swap() that can be used to conditionally swap a pair of big integers in constant time. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -189,6 +189,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
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
|
||||
*
|
||||
@@ -296,6 +309,8 @@ void bigint_grow_raw ( const bigint_element_t *source0,
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user