Add ecp_curve_info_from_name()

This commit is contained in:
Manuel Pégourié-Gonnard 2013-11-30 15:10:14 +01:00
parent 49d738b50d
commit 0267e3dc9b
4 changed files with 83 additions and 3 deletions

View File

@ -204,6 +204,15 @@ const ecp_curve_info *ecp_curve_info_from_grp_id( ecp_group_id grp_id );
*/
const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id );
/**
* \brief Get curve information from a human-readable name
*
* \param name The name
*
* \return The associated curve information or NULL
*/
const ecp_curve_info *ecp_curve_info_from_name( const char *name );
/**
* \brief Initialize a point (as zero)
*/

View File

@ -58,6 +58,11 @@
#include <limits.h>
#include <stdlib.h>
#if defined(_MSC_VER) && !defined strcasecmp && !defined(EFIX64) && \
!defined(EFI32)
#define strcasecmp _stricmp
#endif
#if defined(_MSC_VER) && !defined(inline)
#define inline _inline
#else
@ -84,13 +89,13 @@ unsigned long add_count, dbl_count, mul_count;
const ecp_curve_info ecp_supported_curves[] =
{
#if defined(POLARSSL_ECP_DP_BP512R1_ENABLED)
{ POLARSSL_ECP_DP_BP512R1, 28, 512, "brainpool512r1" },
{ POLARSSL_ECP_DP_BP512R1, 28, 512, "brainpoolP512r1" },
#endif
#if defined(POLARSSL_ECP_DP_BP384R1_ENABLED)
{ POLARSSL_ECP_DP_BP384R1, 27, 384, "brainpool384r1" },
{ POLARSSL_ECP_DP_BP384R1, 27, 384, "brainpoolP384r1" },
#endif
#if defined(POLARSSL_ECP_DP_BP256R1_ENABLED)
{ POLARSSL_ECP_DP_BP256R1, 26, 256, "brainpool256r1" },
{ POLARSSL_ECP_DP_BP256R1, 26, 256, "brainpoolP256r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP521R1_ENABLED)
{ POLARSSL_ECP_DP_SECP521R1, 25, 521, "secp521r1" },
@ -154,6 +159,24 @@ const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id )
return( NULL );
}
/*
* Get the curve info from the name
*/
const ecp_curve_info *ecp_curve_info_from_name( const char *name )
{
const ecp_curve_info *curve_info;
for( curve_info = ecp_curve_list();
curve_info->grp_id != POLARSSL_ECP_DP_NONE;
curve_info++ )
{
if( strcasecmp( curve_info->name, name ) == 0 )
return( curve_info );
}
return( NULL );
}
/*
* Initialize (the components of) a point
*/

View File

@ -1,3 +1,35 @@
ECP curve info #1
depends_on:POLARSSL_ECP_DP_BP512R1_ENABLED
ecp_curve_info:POLARSSL_ECP_DP_BP512R1:28:512:"brainpoolP512r1"
ECP curve info #2
depends_on:POLARSSL_ECP_DP_BP384R1_ENABLED
ecp_curve_info:POLARSSL_ECP_DP_BP384R1:27:384:"brainpoolP384r1"
ECP curve info #3
depends_on:POLARSSL_ECP_DP_BP256R1_ENABLED
ecp_curve_info:POLARSSL_ECP_DP_BP256R1:26:256:"brainpoolP256r1"
ECP curve info #4
depends_on:POLARSSL_ECP_DP_SECP521R1_ENABLED
ecp_curve_info:POLARSSL_ECP_DP_SECP521R1:25:521:"secp521r1"
ECP curve info #5
depends_on:POLARSSL_ECP_DP_SECP384R1_ENABLED
ecp_curve_info:POLARSSL_ECP_DP_SECP384R1:24:384:"secp384r1"
ECP curve info #6
depends_on:POLARSSL_ECP_DP_SECP256R1_ENABLED
ecp_curve_info:POLARSSL_ECP_DP_SECP256R1:23:256:"secp256r1"
ECP curve info #7
depends_on:POLARSSL_ECP_DP_SECP224R1_ENABLED
ecp_curve_info:POLARSSL_ECP_DP_SECP224R1:21:224:"secp224r1"
ECP curve info #8
depends_on:POLARSSL_ECP_DP_SECP192R1_ENABLED
ecp_curve_info:POLARSSL_ECP_DP_SECP192R1:19:192:"secp192r1"
ECP small addition #1
ecp_small_add:1:"":"":1:"":"":1:0:0

View File

@ -9,6 +9,22 @@
* END_DEPENDENCIES
*/
/* BEGIN_CASE */
void ecp_curve_info( int id, int tls_id, int size, char *name )
{
const ecp_curve_info *by_id, *by_tls, *by_name;
TEST_ASSERT( ( by_id = ecp_curve_info_from_grp_id( id ) ) != NULL );
TEST_ASSERT( ( by_tls = ecp_curve_info_from_tls_id( tls_id ) ) != NULL );
TEST_ASSERT( ( by_name = ecp_curve_info_from_name( name ) ) != NULL );
TEST_ASSERT( by_id == by_tls );
TEST_ASSERT( by_id == by_name );
TEST_ASSERT( by_id->size == size );
}
/* END_CASE */
/* BEGIN_CASE */
void ecp_small_add( int a_zero, char *x_a, char *y_a, int b_zero, char *x_b,
char *y_b, int c_zero, int x_c, int y_c )