diff options
author | Michael Brown <mcb30@ipxe.org> | 2025-01-10 13:44:13 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2025-01-10 13:47:25 +0000 |
commit | d88eb0a1935942cdeccd3efee38f9765d2f1c235 (patch) | |
tree | 74c920dced82d2a576bcf7a034cd78c5136c89c6 /src/include | |
parent | 83ba34076ad4ca79be81a71f25303b340c60e7b8 (diff) | |
download | ipxe-d88eb0a1935942cdeccd3efee38f9765d2f1c235.tar.gz |
[crypto] Extract bigint_reduce_supremum() from bigint_mod_exp()
Calculating the Montgomery constant (R^2 mod N) is done in our
implementation by zeroing the double-width representation of N,
subtracting N once to give (R^2 - N) in order to obtain a positive
value, then reducing this value modulo N.
Extract this logic from bigint_mod_exp() to a separate function
bigint_reduce_supremum(), to allow for reuse by other code.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/ipxe/bigint.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/include/ipxe/bigint.h b/src/include/ipxe/bigint.h index db907f1cd..2dd99380d 100644 --- a/src/include/ipxe/bigint.h +++ b/src/include/ipxe/bigint.h @@ -236,9 +236,21 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @v value Big integer to be reduced */ #define bigint_reduce( modulus, value ) do { \ - unsigned int size = bigint_size (modulus); \ - bigint_reduce_raw ( (modulus)->element, \ - (value)->element, size ); \ + unsigned int size = bigint_size (modulus); \ + bigint_reduce_raw ( (modulus)->element, (value)->element, \ + size ); \ + } while ( 0 ) + +/** + * Reduce supremum of big integer representation + * + * @v modulus0 Big integer modulus + * @v result0 Big integer to hold result + */ +#define bigint_reduce_supremum( modulus, result ) do { \ + unsigned int size = bigint_size (modulus); \ + bigint_reduce_supremum_raw ( (modulus)->element, \ + (result)->element, size ); \ } while ( 0 ) /** @@ -385,6 +397,9 @@ void bigint_multiply_raw ( const bigint_element_t *multiplicand0, bigint_element_t *result0 ); void bigint_reduce_raw ( bigint_element_t *modulus0, bigint_element_t *value0, unsigned int size ); +void bigint_reduce_supremum_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 ); int bigint_montgomery_relaxed_raw ( const bigint_element_t *modulus0, |