mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 02:05:39 +01:00
Improve documentation of mbedtls_mpi_write_string()
This commit is contained in:
parent
ae499753a2
commit
c1fa6cdab6
@ -582,15 +582,20 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
|
||||
if( radix < 2 || radix > 16 )
|
||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
|
||||
n = mbedtls_mpi_bitlen( X );
|
||||
if( radix >= 4 ) n >>= 1;
|
||||
if( radix >= 16 ) n >>= 1;
|
||||
/*
|
||||
* Round up the buffer length to an even value to ensure that there is
|
||||
* enough room for hexadecimal values that can be represented in an odd
|
||||
* number of digits.
|
||||
*/
|
||||
n += 3 + ( ( n + 1 ) & 1 );
|
||||
n = mbedtls_mpi_bitlen( X ); /* Number of bits necessary to present `n`. */
|
||||
if( radix >= 4 ) n >>= 1; /* Number of 4-adic digits necessary to present
|
||||
* `n`. If radix > 4, this might be a strict
|
||||
* overapproximation of the number of
|
||||
* radix-adic digits needed to present `n`. */
|
||||
if( radix >= 16 ) n >>= 1; /* Number of hexadecimal digits necessary to
|
||||
* present `n`. */
|
||||
|
||||
n += 1; /* NULL termination */
|
||||
n += 1; /* Compensate for the divisions above, which round down `n`
|
||||
* in case it's not even. */
|
||||
n += 1; /* Potential '-'-sign. */
|
||||
n += ( n & 1 ); /* Make n even to have enough space for hexadecimal writing,
|
||||
* which always uses an even number of hex-digits. */
|
||||
|
||||
if( buflen < n )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user