PK: fix support for ECKEY_DH
diff --git a/include/polarssl/pk_wrap.h b/include/polarssl/pk_wrap.h
index 7d2c3dd..a24fbd1 100644
--- a/include/polarssl/pk_wrap.h
+++ b/include/polarssl/pk_wrap.h
@@ -38,6 +38,7 @@
#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 6cfc16b..c83d02b 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -119,11 +119,16 @@
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 f7b0833..9a89796 100644
--- a/library/pk_wrap.c
+++ b/library/pk_wrap.c
@@ -84,6 +84,9 @@
#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 @@
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 */