aboutsummaryrefslogtreecommitdiffstats
path: root/src/crypto/bigint.c
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2024-11-07 14:43:56 +0000
committerMichael Brown <mcb30@ipxe.org>2024-11-20 14:39:49 +0000
commitda6da6eb3b83fe92002e9c8e245933498ba19a48 (patch)
treea5fce22e022b087771272aaa501abd5a7b2a7bf1 /src/crypto/bigint.c
parente9a23a5b394f40c1525c40416105eaaa1787f749 (diff)
downloadipxe-da6da6eb3b83fe92002e9c8e245933498ba19a48.tar.gz
[crypto] Add bigint_msb_is_set() to clarify code
Add a dedicated bigint_msb_is_set() to reduce the amount of open coding required in the common case of testing the sign of a two's complement big integer. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto/bigint.c')
-rw-r--r--src/crypto/bigint.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/crypto/bigint.c b/src/crypto/bigint.c
index 3f5db8517..35701a1d0 100644
--- a/src/crypto/bigint.c
+++ b/src/crypto/bigint.c
@@ -162,14 +162,13 @@ void bigint_reduce_raw ( const bigint_element_t *minuend0,
bigint_t ( minuend_size ) modulus;
} *temp = tmp;
const unsigned int width = ( 8 * sizeof ( bigint_element_t ) );
- const bigint_element_t msb_mask = ( 1UL << ( width - 1 ) );
bigint_element_t *element;
unsigned int minuend_max;
unsigned int modulus_max;
unsigned int subshift;
- bigint_element_t msb;
int offset;
int shift;
+ int msb;
int i;
/* Start profiling */
@@ -289,7 +288,7 @@ void bigint_reduce_raw ( const bigint_element_t *minuend0,
} else {
bigint_subtract ( &temp->modulus, &temp->minuend );
}
- msb = ( temp->minuend.element[ minuend_size - 1 ] & msb_mask );
+ msb = bigint_msb_is_set ( &temp->minuend );
if ( shift > 0 )
bigint_shr ( &temp->modulus );
}