aboutsummaryrefslogtreecommitdiff
path: root/programs/pkey
diff options
context:
space:
mode:
authorGilles Peskine <Gilles.Peskine@arm.com>2021-05-27 22:17:07 +0200
committerGilles Peskine <Gilles.Peskine@arm.com>2021-06-15 00:12:37 +0200
commit487bbf68053143cdcb27cc60a91caf7738d86b68 (patch)
treeecad368d220314fbe6134c3bf3cfc6664096a7bd /programs/pkey
parent85b1bc65a0f84aa6e453f316ce73e778b2cf8717 (diff)
downloadmbedtls-487bbf68053143cdcb27cc60a91caf7738d86b68.zip
mbedtls-487bbf68053143cdcb27cc60a91caf7738d86b68.tar.gz
mbedtls-487bbf68053143cdcb27cc60a91caf7738d86b68.tar.bz2
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>
Diffstat (limited to 'programs/pkey')
-rw-r--r--programs/pkey/dh_client.c7
-rw-r--r--programs/pkey/dh_server.c4
2 files changed, 6 insertions, 5 deletions
diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c
index 101b0bb..d68dc24 100644
--- a/programs/pkey/dh_client.c
+++ b/programs/pkey/dh_client.c
@@ -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 );
diff --git a/programs/pkey/dh_server.c b/programs/pkey/dh_server.c
index 745e68a..9d51c14 100644
--- a/programs/pkey/dh_server.c
+++ b/programs/pkey/dh_server.c
@@ -254,14 +254,14 @@ int main( void )
memset( buf, 0, sizeof( buf ) );
- n = dhm.MBEDTLS_PRIVATE(len);
+ n = mbedtls_dhm_get_len( &dhm );
if( ( ret = mbedtls_net_recv( &client_fd, buf, n ) ) != (int) n )
{
mbedtls_printf( " failed\n ! mbedtls_net_recv returned %d\n\n", ret );
goto exit;
}
- if( ( ret = mbedtls_dhm_read_public( &dhm, buf, dhm.MBEDTLS_PRIVATE(len) ) ) != 0 )
+ if( ( ret = mbedtls_dhm_read_public( &dhm, buf, n ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_dhm_read_public returned %d\n\n", ret );
goto exit;