diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-10-15 13:50:51 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-10-15 13:50:51 +0100 |
commit | 2bf16c6ffca1e294bb8233d19c9c36e43b31f041 (patch) | |
tree | d685c77f9e63e709ec80b84439e17f16ee5b5a40 /src/include/ipxe | |
parent | f78c5a763cc7bb2e2b7b437e7cc74a3efb876960 (diff) | |
download | ipxe-2bf16c6ffca1e294bb8233d19c9c36e43b31f041.tar.gz |
[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>
Diffstat (limited to 'src/include/ipxe')
-rw-r--r-- | src/include/ipxe/bigint.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/include/ipxe/bigint.h b/src/include/ipxe/bigint.h index c556afbc1..c56b2155f 100644 --- a/src/include/ipxe/bigint.h +++ b/src/include/ipxe/bigint.h @@ -218,6 +218,35 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); } 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 * * @v multiplicand Big integer to be multiplied @@ -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, |