mirror of
https://github.com/ipxe/ipxe
synced 2025-12-14 16:01:38 +03:00
[crypto] Separate out bigint_reduce() from bigint_mod_multiply()
Faster modular multiplication algorithms such as Montgomery multiplication will still require the ability to perform a single direct modular reduction. Neaten up the implementation of direct reduction and split it out into a separate bigint_reduce() function, complete with its own unit tests. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -217,6 +217,35 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
multiplier_size, (result)->element ); \
|
||||
} while ( 0 )
|
||||
|
||||
/**
|
||||
* Reduce big integer
|
||||
*
|
||||
* @v minuend Big integer to be reduced
|
||||
* @v modulus Big integer modulus
|
||||
* @v result Big integer to hold result
|
||||
* @v tmp Temporary working space
|
||||
*/
|
||||
#define bigint_reduce( minuend, modulus, result, tmp ) do { \
|
||||
unsigned int minuend_size = bigint_size (minuend); \
|
||||
unsigned int modulus_size = bigint_size (modulus); \
|
||||
bigint_reduce_raw ( (minuend)->element, minuend_size, \
|
||||
(modulus)->element, modulus_size, \
|
||||
(result)->element, tmp ); \
|
||||
} while ( 0 )
|
||||
|
||||
/**
|
||||
* Calculate temporary working space required for reduction
|
||||
*
|
||||
* @v minuend Big integer to be reduced
|
||||
* @ret len Length of temporary working space
|
||||
*/
|
||||
#define bigint_reduce_tmp_len( minuend ) ( { \
|
||||
unsigned int size = bigint_size (minuend); \
|
||||
sizeof ( struct { \
|
||||
bigint_t ( size ) temp_minuend; \
|
||||
bigint_t ( size ) temp_modulus; \
|
||||
} ); } )
|
||||
|
||||
/**
|
||||
* Perform modular multiplication of big integers
|
||||
*
|
||||
@@ -339,6 +368,11 @@ void bigint_multiply_raw ( const bigint_element_t *multiplicand0,
|
||||
const bigint_element_t *multiplier0,
|
||||
unsigned int multiplier_size,
|
||||
bigint_element_t *result0 );
|
||||
void bigint_reduce_raw ( const bigint_element_t *minuend0,
|
||||
unsigned int minuend_size,
|
||||
const bigint_element_t *modulus0,
|
||||
unsigned int modulus_size,
|
||||
bigint_element_t *result0, void *tmp );
|
||||
void bigint_mod_multiply_raw ( const bigint_element_t *multiplicand0,
|
||||
const bigint_element_t *multiplier0,
|
||||
const bigint_element_t *modulus0,
|
||||
|
||||
Reference in New Issue
Block a user