mirror of
https://github.com/yuzu-mirror/mbedtls.git
synced 2026-04-04 14:08:39 +00: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:
parent
85b1bc65a0
commit
487bbf6805
9 changed files with 58 additions and 26 deletions
|
|
@ -827,6 +827,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
mbedtls_dhm_context dhm;
|
||||
size_t olen;
|
||||
size_t n;
|
||||
for( i = 0; (size_t) i < sizeof( dhm_sizes ) / sizeof( dhm_sizes[0] ); i++ )
|
||||
{
|
||||
mbedtls_dhm_init( &dhm );
|
||||
|
|
@ -839,14 +840,14 @@ int main( int argc, char *argv[] )
|
|||
mbedtls_exit( 1 );
|
||||
}
|
||||
|
||||
dhm.len = mbedtls_mpi_size( &dhm.P );
|
||||
mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL );
|
||||
n = mbedtls_mpi_size( &dhm.P );
|
||||
mbedtls_dhm_make_public( &dhm, (int) n, buf, n, myrand, NULL );
|
||||
if( mbedtls_mpi_copy( &dhm.GY, &dhm.GX ) != 0 )
|
||||
mbedtls_exit( 1 );
|
||||
|
||||
mbedtls_snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] );
|
||||
TIME_PUBLIC( title, "handshake",
|
||||
ret |= mbedtls_dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len,
|
||||
ret |= mbedtls_dhm_make_public( &dhm, (int) n, buf, n,
|
||||
myrand, NULL );
|
||||
ret |= mbedtls_dhm_calc_secret( &dhm, buf, sizeof( buf ), &olen, myrand, NULL ) );
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue