mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Merge pull request #140 from yanesca/everest_integration
Everest integration
This commit is contained in:
@@ -11,6 +11,9 @@ LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I../include -D_FILE_OFFSET_BITS=64
|
||||
LOCAL_LDFLAGS = -L../library \
|
||||
-lmbedcrypto$(SHARED_SUFFIX)
|
||||
|
||||
include ../3rdparty/Makefile.inc
|
||||
LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
|
||||
|
||||
ifndef SHARED
|
||||
DEP=../library/libmbedcrypto.a
|
||||
else
|
||||
|
@@ -25,18 +25,13 @@
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#if !defined(MBEDTLS_PLATFORM_C)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_exit exit
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_snprintf snprintf
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_exit exit
|
||||
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
|
||||
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_TIMING_C)
|
||||
@@ -97,7 +92,7 @@ int main( void )
|
||||
/*
|
||||
* Size to use for the alloc buffer if MEMORY_BUFFER_ALLOC_C is defined.
|
||||
*/
|
||||
#define HEAP_SIZE (1u << 16) // 64k
|
||||
#define HEAP_SIZE (1u << 16) /* 64k */
|
||||
|
||||
#define BUFSIZE 1024
|
||||
#define HEADER_FORMAT " %-24s : "
|
||||
@@ -190,7 +185,12 @@ do { \
|
||||
CODE; \
|
||||
} \
|
||||
\
|
||||
if( ret != 0 ) \
|
||||
if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ) \
|
||||
{ \
|
||||
mbedtls_printf( "Feature Not Supported. Skipping.\n" ); \
|
||||
ret = 0; \
|
||||
} \
|
||||
else if( ret != 0 ) \
|
||||
{ \
|
||||
PRINT_ERROR; \
|
||||
} \
|
||||
@@ -225,6 +225,18 @@ static int myrand( void *rng_state, unsigned char *output, size_t len )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define CHECK_AND_CONTINUE( R ) \
|
||||
{ \
|
||||
int CHECK_AND_CONTINUE_ret = ( R ); \
|
||||
if( CHECK_AND_CONTINUE_ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ) { \
|
||||
mbedtls_printf( "Feature not supported. Skipping.\n" ); \
|
||||
continue; \
|
||||
} \
|
||||
else if( CHECK_AND_CONTINUE_ret != 0 ) { \
|
||||
mbedtls_exit( 1 ); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear some memory that was used to prepare the context
|
||||
*/
|
||||
@@ -827,6 +839,9 @@ int main( int argc, char *argv[] )
|
||||
curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
|
||||
curve_info++ )
|
||||
{
|
||||
if( ! mbedtls_ecdsa_can_do( curve_info->grp_id ) )
|
||||
continue;
|
||||
|
||||
mbedtls_ecdsa_init( &ecdsa );
|
||||
|
||||
if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 )
|
||||
@@ -846,6 +861,9 @@ int main( int argc, char *argv[] )
|
||||
curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
|
||||
curve_info++ )
|
||||
{
|
||||
if( ! mbedtls_ecdsa_can_do( curve_info->grp_id ) )
|
||||
continue;
|
||||
|
||||
mbedtls_ecdsa_init( &ecdsa );
|
||||
|
||||
if( mbedtls_ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 ||
|
||||
@@ -888,24 +906,24 @@ 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 );
|
||||
|
||||
if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 ||
|
||||
mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
|
||||
myrand, NULL ) != 0 ||
|
||||
mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 )
|
||||
{
|
||||
mbedtls_exit( 1 );
|
||||
}
|
||||
CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
|
||||
myrand, NULL ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) );
|
||||
ecp_clear_precomputed( &ecdh.grp );
|
||||
|
||||
mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s",
|
||||
curve_info->name );
|
||||
TIME_PUBLIC( title, "handshake",
|
||||
ret |= mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
|
||||
myrand, NULL );
|
||||
ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
|
||||
myrand, NULL ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
|
||||
myrand, NULL ) ) );
|
||||
mbedtls_ecdh_free( &ecdh );
|
||||
}
|
||||
|
||||
@@ -917,19 +935,16 @@ int main( int argc, char *argv[] )
|
||||
mbedtls_ecdh_init( &ecdh );
|
||||
mbedtls_mpi_init( &z );
|
||||
|
||||
if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 ||
|
||||
mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, myrand, NULL ) != 0 )
|
||||
{
|
||||
mbedtls_exit( 1 );
|
||||
}
|
||||
CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp, myrand, NULL ) );
|
||||
|
||||
mbedtls_snprintf( title, sizeof(title), "ECDHE-%s",
|
||||
curve_info->name );
|
||||
TIME_PUBLIC( title, "handshake",
|
||||
ret |= mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q,
|
||||
myrand, NULL );
|
||||
ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
|
||||
myrand, NULL ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q,
|
||||
myrand, NULL ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
|
||||
myrand, NULL ) ) );
|
||||
|
||||
mbedtls_ecdh_free( &ecdh );
|
||||
mbedtls_mpi_free( &z );
|
||||
@@ -939,24 +954,24 @@ 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 );
|
||||
|
||||
if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 ||
|
||||
mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
|
||||
myrand, NULL ) != 0 ||
|
||||
mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 ||
|
||||
mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
|
||||
myrand, NULL ) != 0 )
|
||||
{
|
||||
mbedtls_exit( 1 );
|
||||
}
|
||||
CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
|
||||
myrand, NULL ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecp_copy( &ecdh.Qp, &ecdh.Q ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
|
||||
myrand, NULL ) );
|
||||
ecp_clear_precomputed( &ecdh.grp );
|
||||
|
||||
mbedtls_snprintf( title, sizeof( title ), "ECDH-%s",
|
||||
curve_info->name );
|
||||
TIME_PUBLIC( title, "handshake",
|
||||
ret |= mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
|
||||
myrand, NULL ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
|
||||
myrand, NULL ) ) );
|
||||
mbedtls_ecdh_free( &ecdh );
|
||||
}
|
||||
|
||||
@@ -968,19 +983,16 @@ int main( int argc, char *argv[] )
|
||||
mbedtls_ecdh_init( &ecdh );
|
||||
mbedtls_mpi_init( &z );
|
||||
|
||||
if( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) != 0 ||
|
||||
mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp,
|
||||
myrand, NULL ) != 0 ||
|
||||
mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL ) != 0 )
|
||||
{
|
||||
mbedtls_exit( 1 );
|
||||
}
|
||||
CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh.grp, curve_info->grp_id ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Qp,
|
||||
myrand, NULL ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh.grp, &ecdh.d, &ecdh.Q, myrand, NULL ) );
|
||||
|
||||
mbedtls_snprintf( title, sizeof(title), "ECDH-%s",
|
||||
curve_info->name );
|
||||
TIME_PUBLIC( title, "handshake",
|
||||
ret |= mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
|
||||
myrand, NULL ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_compute_shared( &ecdh.grp, &z, &ecdh.Qp, &ecdh.d,
|
||||
myrand, NULL ) ) );
|
||||
|
||||
mbedtls_ecdh_free( &ecdh );
|
||||
mbedtls_mpi_free( &z );
|
||||
@@ -988,6 +1000,48 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
if( todo.ecdh )
|
||||
{
|
||||
mbedtls_ecdh_context ecdh_srv, ecdh_cli;
|
||||
unsigned char buf_srv[BUFSIZE], buf_cli[BUFSIZE];
|
||||
const mbedtls_ecp_curve_info * curve_list = mbedtls_ecp_curve_list();
|
||||
const mbedtls_ecp_curve_info *curve_info;
|
||||
size_t olen;
|
||||
|
||||
for( curve_info = curve_list;
|
||||
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 );
|
||||
|
||||
mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", curve_info->name );
|
||||
TIME_PUBLIC( title, "full handshake",
|
||||
const unsigned char * p_srv = buf_srv;
|
||||
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_setup( &ecdh_srv, curve_info->grp_id ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_make_params( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ) );
|
||||
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_read_params( &ecdh_cli, &p_srv, p_srv + olen ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_make_public( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ) );
|
||||
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_read_public( &ecdh_srv, buf_cli, olen ) );
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_calc_secret( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ) );
|
||||
|
||||
CHECK_AND_CONTINUE( mbedtls_ecdh_calc_secret( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ) );
|
||||
mbedtls_ecdh_free( &ecdh_cli );
|
||||
|
||||
mbedtls_ecdh_free( &ecdh_srv );
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
mbedtls_printf( "\n" );
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
|
@@ -1972,6 +1972,14 @@ int query_config( const char *config )
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_GMTIME_R_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
|
||||
if( strcmp( "MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED", config ) == 0 )
|
||||
{
|
||||
MACRO_EXPANSION_TO_STR( MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED */
|
||||
|
||||
/* If the symbol is not found, return an error */
|
||||
return( 1 );
|
||||
}
|
||||
|
Reference in New Issue
Block a user