mirror of
https://github.com/ipxe/ipxe
synced 2026-02-06 21:29:29 +03:00
[crypto] Add bigint_ntoa() for transcribing big integers
In debug messages, big integers are currently printed as hex dumps. This is quite verbose and cumbersome to check against external sources. Add bigint_ntoa() to transcribe big integers into a static buffer (following the model of inet_ntoa(), eth_ntoa(), uuid_ntoa(), etc). Abbreviate big integers that will not fit within the static buffer, showing both the most significant and least significant digits in the transcription. This is generally the most useful form when visually comparing against external sources (such as test vectors, or results produced by high-level languages). Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -40,6 +40,17 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#define bigint_size( bigint ) \
|
||||
( sizeof ( *(bigint) ) / sizeof ( (bigint)->element[0] ) )
|
||||
|
||||
/**
|
||||
* Transcribe big integer (for debugging)
|
||||
*
|
||||
* @v value Big integer to be transcribed
|
||||
* @ret string Big integer in string form (may be abbreviated)
|
||||
*/
|
||||
#define bigint_ntoa( value ) ( { \
|
||||
unsigned int size = bigint_size (value); \
|
||||
bigint_ntoa_raw ( (value)->element, size ); \
|
||||
} )
|
||||
|
||||
/**
|
||||
* Initialise big integer
|
||||
*
|
||||
@@ -360,6 +371,8 @@ bigint_msb_is_set_raw ( const bigint_element_t *value0, unsigned int size ) {
|
||||
return ( !! ( value->element[index] & ( 1UL << subindex ) ) );
|
||||
}
|
||||
|
||||
const char * bigint_ntoa_raw ( const bigint_element_t *value0,
|
||||
unsigned int size );
|
||||
void bigint_init_raw ( bigint_element_t *value0, unsigned int size,
|
||||
const void *data, size_t len );
|
||||
void bigint_done_raw ( const bigint_element_t *value0, unsigned int size,
|
||||
|
||||
Reference in New Issue
Block a user