mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Add mbedtls_ecdh_can_do
All curves can currently do ECDH, but to make the API symmetric and future-proof, add mbedtls_ecdh_can_do() to go with mbedtls_ecdsa_can_do().
This commit is contained in:
		
							parent
							
								
									1fdf2c2d1c
								
							
						
					
					
						commit
						20b3ef3cad
					
				@ -144,6 +144,15 @@ typedef struct mbedtls_ecdh_context
 | 
			
		||||
}
 | 
			
		||||
mbedtls_ecdh_context;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief          Check whether a given group can be used for ECDH.
 | 
			
		||||
 *
 | 
			
		||||
 * \param gid      The ECP group ID to check.
 | 
			
		||||
 *
 | 
			
		||||
 * \return         \c 1 if the group can be used, \c 0 otherwise
 | 
			
		||||
 */
 | 
			
		||||
int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid );
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief           This function generates an ECDH keypair on an elliptic
 | 
			
		||||
 *                  curve.
 | 
			
		||||
 | 
			
		||||
@ -63,6 +63,13 @@ static mbedtls_ecp_group_id mbedtls_ecdh_grp_id(
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid )
 | 
			
		||||
{
 | 
			
		||||
    /* At this time, all groups support ECDH. */
 | 
			
		||||
    (void) gid;
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if !defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT)
 | 
			
		||||
/*
 | 
			
		||||
 * Generate public key (restartable version)
 | 
			
		||||
 | 
			
		||||
@ -911,6 +911,9 @@ int main( int argc, char *argv[] )
 | 
			
		||||
             curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
 | 
			
		||||
             curve_info++ )
 | 
			
		||||
        {
 | 
			
		||||
            if( ! mbedtls_ecdh_can_do( curve_info->grp_id ) )
 | 
			
		||||
                continue;
 | 
			
		||||
 | 
			
		||||
            mbedtls_ecdh_init( &ecdh );
 | 
			
		||||
 | 
			
		||||
            CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
 | 
			
		||||
@ -956,6 +959,9 @@ int main( int argc, char *argv[] )
 | 
			
		||||
             curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
 | 
			
		||||
             curve_info++ )
 | 
			
		||||
        {
 | 
			
		||||
            if( ! mbedtls_ecdh_can_do( curve_info->grp_id ) )
 | 
			
		||||
                continue;
 | 
			
		||||
 | 
			
		||||
            mbedtls_ecdh_init( &ecdh );
 | 
			
		||||
 | 
			
		||||
            CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
 | 
			
		||||
@ -1012,6 +1018,9 @@ int main( int argc, char *argv[] )
 | 
			
		||||
            curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
 | 
			
		||||
            curve_info++ )
 | 
			
		||||
        {
 | 
			
		||||
            if( ! mbedtls_ecdh_can_do( curve_info->grp_id ) )
 | 
			
		||||
                continue;
 | 
			
		||||
 | 
			
		||||
            mbedtls_ecdh_init( &ecdh_srv );
 | 
			
		||||
            mbedtls_ecdh_init( &ecdh_cli );
 | 
			
		||||
            CHECK_AND_CONTINUE( mbedtls_ecdh_setup( &ecdh_srv, curve_info->grp_id ) );
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user