]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[crypto] Rename bigint_rol()/bigint_ror() to bigint_shl()/bigint_shr()
authorMichael Brown <mcb30@ipxe.org>
Mon, 7 Oct 2024 11:13:42 +0000 (12:13 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 7 Oct 2024 12:13:43 +0000 (13:13 +0100)
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>
src/arch/arm32/include/bits/bigint.h
src/arch/arm64/include/bits/bigint.h
src/arch/loong64/include/bits/bigint.h
src/arch/riscv/include/bits/bigint.h
src/arch/x86/include/bits/bigint.h
src/crypto/bigint.c
src/include/ipxe/bigint.h
src/tests/bigint_test.c

index c148d6be22ae36d8d8c74f3ee92a1917b9087fc1..f11ec906bfe118cb5c932908a74fde016a3a572a 100644 (file)
@@ -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;
index 6b62c809ec641abb1e27744ec8f22c75d8153c18..05095413b5b4dd9fe208ccff098e50233fbc02b8 100644 (file)
@@ -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;
index 23edaeea59e92ea5fe79cecbdab0070d834b08dc..2372758513e0f3a48244603ad63baa1588ec3142 100644 (file)
@@ -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;
index 13fd1675923bac089ef7a26d2907ee0f210f9f10..58351ac0757925ccdca8a0cb314d7c70715094dc 100644 (file)
@@ -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 );
index 320d49498895c4107b43e482f5bd429b9d02e695..512b2724d240ff1b1a3513c52d7ed05a7334b649 100644 (file)
@@ -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;
index b63f7ccc1ce17469138fa672f33d14fa784203f8..c7b6dafc9a4bd3279825481a9316c44f8a35f7fc 100644 (file)
@@ -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 );
        }
index bcb7af5ec6a2f855a4858114bdc2a63b738df440..19cd4e3ddff177da15a60a40fb4968e68966ed55 100644 (file)
@@ -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,
index 76aca1059e3d943cd07444f7d33ad98c080e68d7..65f124f249e332e48da9d0cb1bb6c953ee70ab18 100644 (file)
@@ -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,