diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-11-26 14:45:51 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-11-26 14:45:51 +0000 |
commit | 9cbf5c4f86b45773badec2498fac22e8bc6d7dd1 (patch) | |
tree | 47973e724494dab3cf4569570bc723ebee3e4a72 /src/include/ipxe/bigint.h | |
parent | 167a08f08928c7e469f50d5d364287abb784e99c (diff) | |
download | ipxe-9cbf5c4f86b45773badec2498fac22e8bc6d7dd1.tar.gz |
[crypto] Eliminate temporary working space for bigint_reduce()
Direct modular reduction is expected to be used in situations where
there is no requirement to retain the original (unreduced) value.
Modify the API for bigint_reduce() to reduce the value in place,
(removing the separate result buffer), impose a constraint that the
modulus and value have the same size, and require the modulus to be
passed in writable memory (to allow for scaling in place). This
removes the requirement for additional temporary working space.
Reverse the order of arguments so that the constant input is first,
to match the usage pattern for bigint_add() et al.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/bigint.h')
-rw-r--r-- | src/include/ipxe/bigint.h | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/src/include/ipxe/bigint.h b/src/include/ipxe/bigint.h index 2a0a200c5..330d7deec 100644 --- a/src/include/ipxe/bigint.h +++ b/src/include/ipxe/bigint.h @@ -232,33 +232,16 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** * 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 + * @v value Big integer to be reduced */ -#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 ); \ +#define bigint_reduce( modulus, value ) do { \ + unsigned int size = bigint_size (modulus); \ + bigint_reduce_raw ( (modulus)->element, \ + (value)->element, size ); \ } 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; \ - } ); } ) - -/** * Compute inverse of odd big integer modulo its own size * * @v invertend Odd big integer to be inverted @@ -422,11 +405,8 @@ 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_reduce_raw ( bigint_element_t *modulus0, bigint_element_t *value0, + unsigned int size ); void bigint_mod_invert_raw ( const bigint_element_t *invertend0, bigint_element_t *inverse0, unsigned int size, void *tmp ); |