diff --git a/include/polarssl/pk_wrap.h b/include/polarssl/pk_wrap.h index 7d2c3dd8c..a24fbd1d1 100644 --- a/include/polarssl/pk_wrap.h +++ b/include/polarssl/pk_wrap.h @@ -38,6 +38,7 @@ extern const pk_info_t rsa_info; #if defined(POLARSSL_ECP_C) extern const pk_info_t eckey_info; +extern const pk_info_t eckeydh_info; #endif #if defined(POLARSSL_ECDSA_C) diff --git a/library/pk.c b/library/pk.c index 6cfc16bbd..c83d02bdd 100644 --- a/library/pk.c +++ b/library/pk.c @@ -119,11 +119,16 @@ int pk_set_type( pk_context *ctx, pk_type_t type ) else #endif #if defined(POLARSSL_ECP_C) - if( type == POLARSSL_PK_ECKEY || type == POLARSSL_PK_ECKEY_DH ) + if( type == POLARSSL_PK_ECKEY ) { size = sizeof( ecp_keypair ); info = &eckey_info; } + else if( type == POLARSSL_PK_ECKEY_DH ) + { + size = sizeof( ecp_keypair ); + info = &eckeydh_info; + } else #endif #if defined(POLARSSL_ECDSA_C) diff --git a/library/pk_wrap.c b/library/pk_wrap.c index f7b0833eb..9a8979604 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -84,6 +84,9 @@ const pk_info_t ecdsa_info = { #endif /* POLARSSL_ECDSA_C */ #if defined(POLARSSL_ECP_C) +/* + * Generic EC key + */ static int eckey_can_do( pk_type_t type ) { return( type == POLARSSL_PK_ECKEY || @@ -123,4 +126,32 @@ const pk_info_t eckey_info = { eckey_can_do, eckey_verify_wrap, }; + +/* + * EC key resticted to ECDH + */ +static int eckeydh_can_do( pk_type_t type ) +{ + return( type == POLARSSL_PK_ECKEY || + type == POLARSSL_PK_ECKEY_DH ); +} + +static int eckeydh_verify_wrap( void *ctx, + const unsigned char *hash, const md_info_t *md_info, + const unsigned char *sig, size_t sig_len ) +{ + ((void) ctx); + ((void) hash); + ((void) md_info); + ((void) sig); + ((void) sig_len); + + return( POLARSSL_ERR_PK_TYPE_MISMATCH ); +} + +const pk_info_t eckeydh_info = { + POLARSSL_PK_ECKEY_DH, + eckeydh_can_do, + eckeydh_verify_wrap, +}; #endif /* POLARSSL_ECP_C */