aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2024-10-07 12:13:42 +0100
committerMichael Brown <mcb30@ipxe.org>2024-10-07 13:13:43 +0100
commit7e0bf4ec5cb3dd608d97735575e3f62252455878 (patch)
tree0bb9aa58c73136dc4fa86c3f85d9d90bcafb6bb6 /src
parent3f4f843920afdc1d808a8b20354cf3eca481401a (diff)
downloadipxe-7e0bf4ec5cb3dd608d97735575e3f62252455878.tar.gz
[crypto] Rename bigint_rol()/bigint_ror() to bigint_shl()/bigint_shr()
The big integer shift operations are misleadingly described as rotations since the original x86 implementations are essentially trivial loops around the relevant rotate-through-carry instruction. The overall operation performed is a shift rather than a rotation. Update the function names and descriptions to reflect this. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r--src/arch/arm32/include/bits/bigint.h8
-rw-r--r--src/arch/arm64/include/bits/bigint.h8
-rw-r--r--src/arch/loong64/include/bits/bigint.h8
-rw-r--r--src/arch/riscv/include/bits/bigint.h8
-rw-r--r--src/arch/x86/include/bits/bigint.h8
-rw-r--r--src/crypto/bigint.c16
-rw-r--r--src/include/ipxe/bigint.h16
-rw-r--r--src/tests/bigint_test.c48
8 files changed, 60 insertions, 60 deletions
diff --git a/src/arch/arm32/include/bits/bigint.h b/src/arch/arm32/include/bits/bigint.h
index c148d6be2..f11ec906b 100644
--- a/src/arch/arm32/include/bits/bigint.h
+++ b/src/arch/arm32/include/bits/bigint.h
@@ -112,13 +112,13 @@ bigint_subtract_raw ( const uint32_t *subtrahend0, uint32_t *value0,
}
/**
- * Rotate big integer left
+ * Shift big integer left
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_rol_raw ( uint32_t *value0, unsigned int size ) {
+bigint_shl_raw ( uint32_t *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
uint32_t *discard_value;
@@ -141,13 +141,13 @@ bigint_rol_raw ( uint32_t *value0, unsigned int size ) {
}
/**
- * Rotate big integer right
+ * Shift big integer right
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_ror_raw ( uint32_t *value0, unsigned int size ) {
+bigint_shr_raw ( uint32_t *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
uint32_t *discard_value;
diff --git a/src/arch/arm64/include/bits/bigint.h b/src/arch/arm64/include/bits/bigint.h
index 6b62c809e..05095413b 100644
--- a/src/arch/arm64/include/bits/bigint.h
+++ b/src/arch/arm64/include/bits/bigint.h
@@ -111,13 +111,13 @@ bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0,
}
/**
- * Rotate big integer left
+ * Shift big integer left
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_rol_raw ( uint64_t *value0, unsigned int size ) {
+bigint_shl_raw ( uint64_t *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
uint64_t *discard_value;
@@ -140,13 +140,13 @@ bigint_rol_raw ( uint64_t *value0, unsigned int size ) {
}
/**
- * Rotate big integer right
+ * Shift big integer right
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_ror_raw ( uint64_t *value0, unsigned int size ) {
+bigint_shr_raw ( uint64_t *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
uint64_t *discard_value;
diff --git a/src/arch/loong64/include/bits/bigint.h b/src/arch/loong64/include/bits/bigint.h
index 23edaeea5..237275851 100644
--- a/src/arch/loong64/include/bits/bigint.h
+++ b/src/arch/loong64/include/bits/bigint.h
@@ -136,13 +136,13 @@ bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0,
}
/**
- * Rotate big integer left
+ * Shift big integer left
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_rol_raw ( uint64_t *value0, unsigned int size ) {
+bigint_shl_raw ( uint64_t *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
uint64_t *discard_value;
@@ -177,13 +177,13 @@ bigint_rol_raw ( uint64_t *value0, unsigned int size ) {
}
/**
- * Rotate big integer right
+ * Shift big integer right
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_ror_raw ( uint64_t *value0, unsigned int size ) {
+bigint_shr_raw ( uint64_t *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
uint64_t *discard_value;
diff --git a/src/arch/riscv/include/bits/bigint.h b/src/arch/riscv/include/bits/bigint.h
index 13fd16759..58351ac07 100644
--- a/src/arch/riscv/include/bits/bigint.h
+++ b/src/arch/riscv/include/bits/bigint.h
@@ -135,13 +135,13 @@ bigint_subtract_raw ( const unsigned long *subtrahend0, unsigned long *value0,
}
/**
- * Rotate big integer left
+ * Shift big integer left
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_rol_raw ( unsigned long *value0, unsigned int size ) {
+bigint_shl_raw ( unsigned long *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
unsigned long *valueN = ( value0 + size );
@@ -174,13 +174,13 @@ bigint_rol_raw ( unsigned long *value0, unsigned int size ) {
}
/**
- * Rotate big integer right
+ * Shift big integer right
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_ror_raw ( unsigned long *value0, unsigned int size ) {
+bigint_shr_raw ( unsigned long *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
unsigned long *valueN = ( value0 + size );
diff --git a/src/arch/x86/include/bits/bigint.h b/src/arch/x86/include/bits/bigint.h
index 320d49498..512b2724d 100644
--- a/src/arch/x86/include/bits/bigint.h
+++ b/src/arch/x86/include/bits/bigint.h
@@ -104,13 +104,13 @@ bigint_subtract_raw ( const uint32_t *subtrahend0, uint32_t *value0,
}
/**
- * Rotate big integer left
+ * Shift big integer left
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_rol_raw ( uint32_t *value0, unsigned int size ) {
+bigint_shl_raw ( uint32_t *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
long index;
@@ -127,13 +127,13 @@ bigint_rol_raw ( uint32_t *value0, unsigned int size ) {
}
/**
- * Rotate big integer right
+ * Shift big integer right
*
* @v value0 Element 0 of big integer
* @v size Number of elements
*/
static inline __attribute__ (( always_inline )) void
-bigint_ror_raw ( uint32_t *value0, unsigned int size ) {
+bigint_shr_raw ( uint32_t *value0, unsigned int size ) {
bigint_t ( size ) __attribute__ (( may_alias )) *value =
( ( void * ) value0 );
long discard_c;
diff --git a/src/crypto/bigint.c b/src/crypto/bigint.c
index b63f7ccc1..c7b6dafc9 100644
--- a/src/crypto/bigint.c
+++ b/src/crypto/bigint.c
@@ -171,7 +171,7 @@ void bigint_mod_multiply_raw ( const bigint_element_t *multiplicand0,
bigint_t ( size * 2 ) result;
bigint_t ( size * 2 ) modulus;
} *temp = tmp;
- int rotation;
+ int shift;
int i;
/* Start profiling */
@@ -188,18 +188,18 @@ void bigint_mod_multiply_raw ( const bigint_element_t *multiplicand0,
/* Rescale modulus to match result */
profile_start ( &bigint_mod_multiply_rescale_profiler );
bigint_grow ( modulus, &temp->modulus );
- rotation = ( bigint_max_set_bit ( &temp->result ) -
- bigint_max_set_bit ( &temp->modulus ) );
- for ( i = 0 ; i < rotation ; i++ )
- bigint_rol ( &temp->modulus );
+ shift = ( bigint_max_set_bit ( &temp->result ) -
+ bigint_max_set_bit ( &temp->modulus ) );
+ for ( i = 0 ; i < shift ; i++ )
+ bigint_shl ( &temp->modulus );
profile_stop ( &bigint_mod_multiply_rescale_profiler );
/* Subtract multiples of modulus */
profile_start ( &bigint_mod_multiply_subtract_profiler );
- for ( i = 0 ; i <= rotation ; i++ ) {
+ for ( i = 0 ; i <= shift ; i++ ) {
if ( bigint_is_geq ( &temp->result, &temp->modulus ) )
bigint_subtract ( &temp->modulus, &temp->result );
- bigint_ror ( &temp->modulus );
+ bigint_shr ( &temp->modulus );
}
profile_stop ( &bigint_mod_multiply_subtract_profiler );
@@ -255,7 +255,7 @@ void bigint_mod_exp_raw ( const bigint_element_t *base0,
bigint_mod_multiply ( result, &temp->base, modulus,
result, temp->mod_multiply );
}
- bigint_ror ( &temp->exponent );
+ bigint_shr ( &temp->exponent );
bigint_mod_multiply ( &temp->base, &temp->base, modulus,
&temp->base, temp->mod_multiply );
}
diff --git a/src/include/ipxe/bigint.h b/src/include/ipxe/bigint.h
index bcb7af5ec..19cd4e3dd 100644
--- a/src/include/ipxe/bigint.h
+++ b/src/include/ipxe/bigint.h
@@ -89,23 +89,23 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
} while ( 0 )
/**
- * Rotate big integer left
+ * Shift big integer left
*
* @v value Big integer
*/
-#define bigint_rol( value ) do { \
+#define bigint_shl( value ) do { \
unsigned int size = bigint_size (value); \
- bigint_rol_raw ( (value)->element, size ); \
+ bigint_shl_raw ( (value)->element, size ); \
} while ( 0 )
/**
- * Rotate big integer right
+ * Shift big integer right
*
* @v value Big integer
*/
-#define bigint_ror( value ) do { \
+#define bigint_shr( value ) do { \
unsigned int size = bigint_size (value); \
- bigint_ror_raw ( (value)->element, size ); \
+ bigint_shr_raw ( (value)->element, size ); \
} while ( 0 )
/**
@@ -293,8 +293,8 @@ void bigint_add_raw ( const bigint_element_t *addend0,
bigint_element_t *value0, unsigned int size );
void bigint_subtract_raw ( const bigint_element_t *subtrahend0,
bigint_element_t *value0, unsigned int size );
-void bigint_rol_raw ( bigint_element_t *value0, unsigned int size );
-void bigint_ror_raw ( bigint_element_t *value0, unsigned int size );
+void bigint_shl_raw ( bigint_element_t *value0, unsigned int size );
+void bigint_shr_raw ( bigint_element_t *value0, unsigned int size );
int bigint_is_zero_raw ( const bigint_element_t *value0, unsigned int size );
int bigint_is_geq_raw ( const bigint_element_t *value0,
const bigint_element_t *reference0,
diff --git a/src/tests/bigint_test.c b/src/tests/bigint_test.c
index 76aca1059..65f124f24 100644
--- a/src/tests/bigint_test.c
+++ b/src/tests/bigint_test.c
@@ -78,18 +78,18 @@ void bigint_subtract_sample ( const bigint_element_t *subtrahend0,
bigint_subtract ( subtrahend, value );
}
-void bigint_rol_sample ( bigint_element_t *value0, unsigned int size ) {
+void bigint_shl_sample ( bigint_element_t *value0, unsigned int size ) {
bigint_t ( size ) *value __attribute__ (( may_alias ))
= ( ( void * ) value0 );
- bigint_rol ( value );
+ bigint_shl ( value );
}
-void bigint_ror_sample ( bigint_element_t *value0, unsigned int size ) {
+void bigint_shr_sample ( bigint_element_t *value0, unsigned int size ) {
bigint_t ( size ) *value __attribute__ (( may_alias ))
= ( ( void * ) value0 );
- bigint_ror ( value );
+ bigint_shr ( value );
}
int bigint_is_zero_sample ( const bigint_element_t *value0,
@@ -290,12 +290,12 @@ void bigint_mod_exp_sample ( const bigint_element_t *base0,
} while ( 0 )
/**
- * Report result of big integer left rotation test
+ * Report result of big integer left shift test
*
* @v value Big integer
* @v expected Big integer expected result
*/
-#define bigint_rol_ok( value, expected ) do { \
+#define bigint_shl_ok( value, expected ) do { \
static const uint8_t value_raw[] = value; \
static const uint8_t expected_raw[] = expected; \
uint8_t result_raw[ sizeof ( expected_raw ) ]; \
@@ -305,9 +305,9 @@ void bigint_mod_exp_sample ( const bigint_element_t *base0,
{} /* Fix emacs alignment */ \
\
bigint_init ( &value_temp, value_raw, sizeof ( value_raw ) ); \
- DBG ( "Rotate left:\n" ); \
+ DBG ( "Shift left:\n" ); \
DBG_HDA ( 0, &value_temp, sizeof ( value_temp ) ); \
- bigint_rol ( &value_temp ); \
+ bigint_shl ( &value_temp ); \
DBG_HDA ( 0, &value_temp, sizeof ( value_temp ) ); \
bigint_done ( &value_temp, result_raw, sizeof ( result_raw ) ); \
\
@@ -316,12 +316,12 @@ void bigint_mod_exp_sample ( const bigint_element_t *base0,
} while ( 0 )
/**
- * Report result of big integer right rotation test
+ * Report result of big integer right shift test
*
* @v value Big integer
* @v expected Big integer expected result
*/
-#define bigint_ror_ok( value, expected ) do { \
+#define bigint_shr_ok( value, expected ) do { \
static const uint8_t value_raw[] = value; \
static const uint8_t expected_raw[] = expected; \
uint8_t result_raw[ sizeof ( expected_raw ) ]; \
@@ -331,9 +331,9 @@ void bigint_mod_exp_sample ( const bigint_element_t *base0,
{} /* Fix emacs alignment */ \
\
bigint_init ( &value_temp, value_raw, sizeof ( value_raw ) ); \
- DBG ( "Rotate right:\n" ); \
+ DBG ( "Shift right:\n" ); \
DBG_HDA ( 0, &value_temp, sizeof ( value_temp ) ); \
- bigint_ror ( &value_temp ); \
+ bigint_shr ( &value_temp ); \
DBG_HDA ( 0, &value_temp, sizeof ( value_temp ) ); \
bigint_done ( &value_temp, result_raw, sizeof ( result_raw ) ); \
\
@@ -801,15 +801,15 @@ static void bigint_test_exec ( void ) {
0xda, 0xc8, 0x8c, 0x71, 0x86, 0x97,
0x7f, 0xcb, 0x94, 0x31, 0x1d, 0xbc,
0x44, 0x1a ) );
- bigint_rol_ok ( BIGINT ( 0xe0 ),
+ bigint_shl_ok ( BIGINT ( 0xe0 ),
BIGINT ( 0xc0 ) );
- bigint_rol_ok ( BIGINT ( 0x43, 0x1d ),
+ bigint_shl_ok ( BIGINT ( 0x43, 0x1d ),
BIGINT ( 0x86, 0x3a ) );
- bigint_rol_ok ( BIGINT ( 0xac, 0xed, 0x9b ),
+ bigint_shl_ok ( BIGINT ( 0xac, 0xed, 0x9b ),
BIGINT ( 0x59, 0xdb, 0x36 ) );
- bigint_rol_ok ( BIGINT ( 0x2c, 0xe8, 0x3a, 0x22 ),
+ bigint_shl_ok ( BIGINT ( 0x2c, 0xe8, 0x3a, 0x22 ),
BIGINT ( 0x59, 0xd0, 0x74, 0x44 ) );
- bigint_rol_ok ( BIGINT ( 0x4e, 0x88, 0x4a, 0x05, 0x5e, 0x10, 0xee,
+ bigint_shl_ok ( BIGINT ( 0x4e, 0x88, 0x4a, 0x05, 0x5e, 0x10, 0xee,
0x5b, 0xc6, 0x40, 0x0e, 0x03, 0xd7, 0x0d,
0x28, 0xa5, 0x55, 0xb2, 0x50, 0xef, 0x69,
0xd1, 0x1d ),
@@ -817,7 +817,7 @@ static void bigint_test_exec ( void ) {
0xb7, 0x8c, 0x80, 0x1c, 0x07, 0xae, 0x1a,
0x51, 0x4a, 0xab, 0x64, 0xa1, 0xde, 0xd3,
0xa2, 0x3a ) );
- bigint_rol_ok ( BIGINT ( 0x07, 0x62, 0x78, 0x70, 0x2e, 0xd4, 0x41,
+ bigint_shl_ok ( BIGINT ( 0x07, 0x62, 0x78, 0x70, 0x2e, 0xd4, 0x41,
0xaa, 0x9b, 0x50, 0xb1, 0x9a, 0x71, 0xf5,
0x1c, 0x2f, 0xe7, 0x0d, 0xf1, 0x46, 0x57,
0x04, 0x99, 0x78, 0x4e, 0x84, 0x78, 0xba,
@@ -855,15 +855,15 @@ static void bigint_test_exec ( void ) {
0x49, 0x7c, 0x1e, 0xdb, 0xc7, 0x65, 0xa6,
0x0e, 0xd1, 0xd2, 0x00, 0xb3, 0x41, 0xc9,
0x3c, 0xbc ) );
- bigint_ror_ok ( BIGINT ( 0x8f ),
+ bigint_shr_ok ( BIGINT ( 0x8f ),
BIGINT ( 0x47 ) );
- bigint_ror_ok ( BIGINT ( 0xaa, 0x1d ),
+ bigint_shr_ok ( BIGINT ( 0xaa, 0x1d ),
BIGINT ( 0x55, 0x0e ) );
- bigint_ror_ok ( BIGINT ( 0xf0, 0xbd, 0x68 ),
+ bigint_shr_ok ( BIGINT ( 0xf0, 0xbd, 0x68 ),
BIGINT ( 0x78, 0x5e, 0xb4 ) );
- bigint_ror_ok ( BIGINT ( 0x33, 0xa0, 0x3d, 0x95 ),
+ bigint_shr_ok ( BIGINT ( 0x33, 0xa0, 0x3d, 0x95 ),
BIGINT ( 0x19, 0xd0, 0x1e, 0xca ) );
- bigint_ror_ok ( BIGINT ( 0xa1, 0xf4, 0xb9, 0x64, 0x91, 0x99, 0xa1,
+ bigint_shr_ok ( BIGINT ( 0xa1, 0xf4, 0xb9, 0x64, 0x91, 0x99, 0xa1,
0xf4, 0xae, 0xeb, 0x71, 0x97, 0x1b, 0x71,
0x09, 0x38, 0x3f, 0x8f, 0xc5, 0x3a, 0xb9,
0x75, 0x94 ),
@@ -871,7 +871,7 @@ static void bigint_test_exec ( void ) {
0xfa, 0x57, 0x75, 0xb8, 0xcb, 0x8d, 0xb8,
0x84, 0x9c, 0x1f, 0xc7, 0xe2, 0x9d, 0x5c,
0xba, 0xca ) );
- bigint_ror_ok ( BIGINT ( 0xc0, 0xb3, 0x78, 0x46, 0x69, 0x6e, 0x35,
+ bigint_shr_ok ( BIGINT ( 0xc0, 0xb3, 0x78, 0x46, 0x69, 0x6e, 0x35,
0x94, 0xed, 0x28, 0xdc, 0xfd, 0xf6, 0xdb,
0x2d, 0x24, 0xcb, 0xa4, 0x6f, 0x0e, 0x58,
0x89, 0x04, 0xec, 0xc8, 0x0c, 0x2d, 0xb3,