1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

DHM: new functions to query the length of the modulus

Add two functions mbedtls_dhm_get_len() and mbedtls_dhm_get_bitlen() to
query the length of the modulus in bytes or bits.

Remove the len field: the cost of calling mbedtls_dhm_get_len() each time
it's needed is negligible, and this improves the abstraction of the DHM
module.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2021-05-27 22:17:07 +02:00
parent 85b1bc65a0
commit 487bbf6805
9 changed files with 58 additions and 26 deletions

View File

@ -192,7 +192,8 @@ int main( void )
goto exit;
}
if( dhm.MBEDTLS_PRIVATE(len) < 64 || dhm.MBEDTLS_PRIVATE(len) > 512 )
n = mbedtls_dhm_get_len( &dhm );
if( n < 64 || n > 512 )
{
mbedtls_printf( " failed\n ! Invalid DHM modulus size\n\n" );
goto exit;
@ -232,8 +233,8 @@ int main( void )
mbedtls_printf( "\n . Sending own public value to server" );
fflush( stdout );
n = dhm.MBEDTLS_PRIVATE(len);
if( ( ret = mbedtls_dhm_make_public( &dhm, (int) dhm.MBEDTLS_PRIVATE(len), buf, n,
n = mbedtls_dhm_get_len( &dhm );
if( ( ret = mbedtls_dhm_make_public( &dhm, (int) n, buf, n,
mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_dhm_make_public returned %d\n\n", ret );