[crypto] Expose carry flag from big integer addition and subtraction

Expose the effective carry (or borrow) out flag from big integer
addition and subtraction, and use this to elide an explicit bit test
when performing x25519 reduction.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2024-11-26 12:53:01 +00:00
parent da6da6eb3b
commit 167a08f089
8 changed files with 140 additions and 85 deletions
+3 -2
View File
@@ -564,6 +564,7 @@ void x25519_invert ( const union x25519_oct258 *invertend,
*/
static void x25519_reduce_by ( const x25519_t *subtrahend, x25519_t *value ) {
x25519_t tmp;
int underflow;
/* Conditionally subtract subtrahend
*
@@ -571,8 +572,8 @@ static void x25519_reduce_by ( const x25519_t *subtrahend, x25519_t *value ) {
* time) if the subtraction underflows.
*/
bigint_copy ( value, &tmp );
bigint_subtract ( subtrahend, value );
bigint_swap ( value, &tmp, bigint_msb_is_set ( value ) );
underflow = bigint_subtract ( subtrahend, value );
bigint_swap ( value, &tmp, underflow );
}
/**