1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-08 17:42:09 +03:00

Add a PK can_do() method and simplify code

This commit is contained in:
Manuel Pégourié-Gonnard
2013-08-12 18:41:18 +02:00
parent d73b3c13be
commit f18c3e0378
4 changed files with 38 additions and 137 deletions

View File

@@ -89,6 +89,9 @@ typedef struct
/** Public key type */
pk_type_t type;
/** Tell if the context implements this type (eg ECKEY can do ECDSA) */
int (*can_do)( pk_type_t type );
/** Verify signature */
int (*verify_func)( void *ctx,
const unsigned char *hash, const md_info_t *md_info,
@@ -131,33 +134,6 @@ void pk_free( pk_context *ctx );
*/
int pk_set_type( pk_context *ctx, pk_type_t type );
#if defined(POLARSSL_ECDSA_C)
/**
* \brief Convert a generic EC key into an ECDSA context
*
* \param ctx Context to convert
*
* \return 0 on success, or
* POLARSSL_ERR_PK_MALLOC_FAILED or
* POLARSSL_ERR_PK_TYPE_MISMATCH.
*/
int pk_ec_to_ecdsa( pk_context *ctx );
/**
* \brief Tell if a PK context can be used for ECDSA
*
* \param ctx Context to check
*
* \return 0 if context cannot be used for ECDSA,
* 1 otherwise
*/
static inline int pk_can_ecdsa( pk_context ctx )
{
return( ctx.type == POLARSSL_PK_ECKEY ||
ctx.type == POLARSSL_PK_ECDSA );
}
#endif /* POLARSSL_ECDSA_C */
#if defined(POLARSSL_RSA_C)
/**
* \brief Wrap a RSA context in a PK context