pk_internal: pass context to can_do
In the mbedtls_pk_info_t method can_do, pass the context data. This
will be needed for opaque keys, where the info structure depends on
the method to access the opaque key and not on the key type.
diff --git a/include/mbedtls/pk_internal.h b/include/mbedtls/pk_internal.h
index aab3db7..592eb4b 100644
--- a/include/mbedtls/pk_internal.h
+++ b/include/mbedtls/pk_internal.h
@@ -41,10 +41,10 @@
const char *name;
/** Get key size in bits */
- size_t (*get_bitlen)( const void * );
+ size_t (*get_bitlen)( const void *ctx );
/** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
- int (*can_do)( mbedtls_pk_type_t type );
+ int (*can_do)( const void * ctx, mbedtls_pk_type_t type );
/** Verify signature */
int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
diff --git a/library/pk.c b/library/pk.c
index b52c73f..9037646 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -154,7 +154,7 @@
if( ctx == NULL || ctx->pk_info == NULL )
return( 0 );
- return( ctx->pk_info->can_do( type ) );
+ return( ctx->pk_info->can_do( ctx->pk_ctx, type ) );
}
/*
diff --git a/library/pk_wrap.c b/library/pk_wrap.c
index a4bb35f..55be595 100644
--- a/library/pk_wrap.c
+++ b/library/pk_wrap.c
@@ -60,8 +60,9 @@
#endif
#if defined(MBEDTLS_RSA_C)
-static int rsa_can_do( mbedtls_pk_type_t type )
+static int rsa_can_do( const void *ctx, mbedtls_pk_type_t type )
{
+ (void) ctx;
return( type == MBEDTLS_PK_RSA ||
type == MBEDTLS_PK_RSASSA_PSS );
}
@@ -201,8 +202,9 @@
/*
* Generic EC key
*/
-static int eckey_can_do( mbedtls_pk_type_t type )
+static int eckey_can_do( const void *ctx, mbedtls_pk_type_t type )
{
+ (void) ctx;
return( type == MBEDTLS_PK_ECKEY ||
type == MBEDTLS_PK_ECKEY_DH ||
type == MBEDTLS_PK_ECDSA );
@@ -314,8 +316,9 @@
/*
* EC key restricted to ECDH
*/
-static int eckeydh_can_do( mbedtls_pk_type_t type )
+static int eckeydh_can_do( const void *ctx, mbedtls_pk_type_t type )
{
+ (void) ctx;
return( type == MBEDTLS_PK_ECKEY ||
type == MBEDTLS_PK_ECKEY_DH );
}
@@ -337,8 +340,9 @@
#endif /* MBEDTLS_ECP_C */
#if defined(MBEDTLS_ECDSA_C)
-static int ecdsa_can_do( mbedtls_pk_type_t type )
+static int ecdsa_can_do( const void *ctx, mbedtls_pk_type_t type )
{
+ (void) ctx;
return( type == MBEDTLS_PK_ECDSA );
}
@@ -404,8 +408,9 @@
* Support for alternative RSA-private implementations
*/
-static int rsa_alt_can_do( mbedtls_pk_type_t type )
+static int rsa_alt_can_do( const void *ctx, mbedtls_pk_type_t type )
{
+ (void) ctx;
return( type == MBEDTLS_PK_RSA );
}