diff options
| author | Michael Brown | 2024-01-19 13:34:02 +0100 |
|---|---|---|
| committer | Michael Brown | 2024-01-19 13:34:02 +0100 |
| commit | bac13ba1f658a1e742b9ceb958e670086affebe7 (patch) | |
| tree | 912fd8cd64b62fc7b6eb2242b97a0f68dec0a0d5 /src/include | |
| parent | [crypto] Add bigint_copy() as a convenient wrapper macro (diff) | |
| download | ipxe-bac13ba1f658a1e742b9ceb958e670086affebe7.tar.gz ipxe-bac13ba1f658a1e742b9ceb958e670086affebe7.tar.xz ipxe-bac13ba1f658a1e742b9ceb958e670086affebe7.zip | |
[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>
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/ipxe/bigint.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/include/ipxe/bigint.h b/src/include/ipxe/bigint.h index 820d306b8..3dc344dff 100644 --- a/src/include/ipxe/bigint.h +++ b/src/include/ipxe/bigint.h @@ -190,6 +190,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); } 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 * * @v multiplicand Big integer to be multiplied @@ -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, |
