From a73b57774451017a0499e24b22c99ae850093471 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 19 Jul 2021 14:36:03 +0200 Subject: [PATCH] Make the fields of mbedtls_ecp_curve_info public The whole point of this structure is to provide information, both for the library's own sake and to applications. Signed-off-by: Gilles Peskine --- include/mbedtls/ecp.h | 12 ++++++++---- programs/pkey/gen_key.c | 12 ++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/mbedtls/ecp.h b/include/mbedtls/ecp.h index 384d0608a7..b2a2e32564 100644 --- a/include/mbedtls/ecp.h +++ b/include/mbedtls/ecp.h @@ -147,13 +147,17 @@ typedef enum /** * Curve information, for use by other modules. + * + * The fields of this structure are part of the public API and can be + * accessed directly by applications. Future versions of the library may + * add extra fields or reorder existing fields. */ typedef struct mbedtls_ecp_curve_info { - mbedtls_ecp_group_id MBEDTLS_PRIVATE(grp_id); /*!< An internal identifier. */ - uint16_t MBEDTLS_PRIVATE(tls_id); /*!< The TLS NamedCurve identifier. */ - uint16_t MBEDTLS_PRIVATE(bit_size); /*!< The curve size in bits. */ - const char *MBEDTLS_PRIVATE(name); /*!< A human-friendly name. */ + mbedtls_ecp_group_id grp_id; /*!< An internal identifier. */ + uint16_t tls_id; /*!< The TLS NamedCurve identifier. */ + uint16_t bit_size; /*!< The curve size in bits. */ + const char *name; /*!< A human-friendly name. */ } mbedtls_ecp_curve_info; /** diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c index 4043dfa6e0..7535eee3f3 100644 --- a/programs/pkey/gen_key.c +++ b/programs/pkey/gen_key.c @@ -86,7 +86,7 @@ int dev_random_entropy_poll( void *data, unsigned char *output, #endif #if defined(MBEDTLS_ECP_C) -#define DFL_EC_CURVE mbedtls_ecp_curve_list()->MBEDTLS_PRIVATE(grp_id) +#define DFL_EC_CURVE mbedtls_ecp_curve_list()->grp_id #else #define DFL_EC_CURVE 0 #endif @@ -219,9 +219,9 @@ int main( int argc, char *argv[] ) #if defined(MBEDTLS_ECP_C) mbedtls_printf( " available ec_curve values:\n" ); curve_info = mbedtls_ecp_curve_list(); - mbedtls_printf( " %s (default)\n", curve_info->MBEDTLS_PRIVATE(name) ); - while( ( ++curve_info )->MBEDTLS_PRIVATE(name) != NULL ) - mbedtls_printf( " %s\n", curve_info->MBEDTLS_PRIVATE(name) ); + mbedtls_printf( " %s (default)\n", curve_info->name ); + while( ( ++curve_info )->name != NULL ) + mbedtls_printf( " %s\n", curve_info->name ); #endif /* MBEDTLS_ECP_C */ goto exit; } @@ -270,7 +270,7 @@ int main( int argc, char *argv[] ) { if( ( curve_info = mbedtls_ecp_curve_info_from_name( q ) ) == NULL ) goto usage; - opt.ec_curve = curve_info->MBEDTLS_PRIVATE(grp_id); + opt.ec_curve = curve_info->grp_id; } #endif else if( strcmp( p, "filename" ) == 0 ) @@ -391,7 +391,7 @@ int main( int argc, char *argv[] ) { mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( key ); mbedtls_printf( "curve: %s\n", - mbedtls_ecp_curve_info_from_grp_id( ecp->MBEDTLS_PRIVATE(grp).id )->MBEDTLS_PRIVATE(name) ); + mbedtls_ecp_curve_info_from_grp_id( ecp->MBEDTLS_PRIVATE(grp).id )->name ); mbedtls_mpi_write_file( "X_Q: ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(X), 16, NULL ); mbedtls_mpi_write_file( "Y_Q: ", &ecp->MBEDTLS_PRIVATE(Q).MBEDTLS_PRIVATE(Y), 16, NULL ); mbedtls_mpi_write_file( "D: ", &ecp->MBEDTLS_PRIVATE(d) , 16, NULL );