aboutsummaryrefslogtreecommitdiff
path: root/src/include/ipxe
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2024-01-19 12:34:02 +0000
committerMichael Brown <mcb30@ipxe.org>2024-01-19 12:34:02 +0000
commitbac13ba1f658a1e742b9ceb958e670086affebe7 (patch)
tree912fd8cd64b62fc7b6eb2242b97a0f68dec0a0d5 /src/include/ipxe
parent13e390d54edde17c8e22b0f6d8897c273a91c5d0 (diff)
downloadipxe-bac13ba1f658a1e742b9ceb958e670086affebe7.zip
ipxe-bac13ba1f658a1e742b9ceb958e670086affebe7.tar.gz
ipxe-bac13ba1f658a1e742b9ceb958e670086affebe7.tar.bz2
[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/ipxe')
-rw-r--r--src/include/ipxe/bigint.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/include/ipxe/bigint.h b/src/include/ipxe/bigint.h
index 820d306..3dc344d 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,