PK: use NULL for unimplemented operations
This commit is contained in:
parent
f73da02962
commit
fff80f8879
3 changed files with 10 additions and 28 deletions
|
@ -45,7 +45,7 @@
|
|||
#endif
|
||||
|
||||
#define POLARSSL_ERR_PK_MALLOC_FAILED -0x2F80 /**< Memory alloation failed. */
|
||||
#define POLARSSL_ERR_PK_TYPE_MISMATCH -0x2F00 /**< Type mismatch, eg attempt to use a RSA key as EC, or to modify key type. */
|
||||
#define POLARSSL_ERR_PK_TYPE_MISMATCH -0x2F00 /**< Type mismatch, eg attempt to encrypt with an ECDSA key */
|
||||
#define POLARSSL_ERR_PK_BAD_INPUT_DATA -0x2E80 /**< Bad input parameters to function. */
|
||||
|
||||
#if defined(POLARSSL_RSA_C)
|
||||
|
|
|
@ -127,6 +127,9 @@ int pk_verify( pk_context *ctx, md_type_t md_alg,
|
|||
if( ctx == NULL || ctx->pk_info == NULL )
|
||||
return( POLARSSL_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
if( ctx->pk_info->verify_func == NULL )
|
||||
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
|
||||
|
||||
return( ctx->pk_info->verify_func( ctx->pk_ctx, md_alg,
|
||||
hash, hash_len,
|
||||
sig, sig_len ) );
|
||||
|
|
|
@ -131,22 +131,11 @@ static size_t eckey_get_size( const void *ctx )
|
|||
static int ecdsa_verify_wrap( void *ctx, md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
const unsigned char *sig, size_t sig_len );
|
||||
#endif
|
||||
|
||||
static int eckey_verify_wrap( void *ctx, md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
const unsigned char *sig, size_t sig_len )
|
||||
{
|
||||
#if !defined(POLARSSL_ECDSA_C)
|
||||
((void) ctx);
|
||||
((void) md_alg);
|
||||
((void) hash);
|
||||
((void) hash_len);
|
||||
((void) sig);
|
||||
((void) sig_len);
|
||||
|
||||
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
|
||||
#else
|
||||
int ret;
|
||||
ecdsa_context ecdsa;
|
||||
|
||||
|
@ -158,8 +147,8 @@ static int eckey_verify_wrap( void *ctx, md_type_t md_alg,
|
|||
ecdsa_free( &ecdsa );
|
||||
|
||||
return( ret );
|
||||
#endif /* POLARSSL_ECDSA_C */
|
||||
}
|
||||
#endif /* POLARSSL_ECDSA_C */
|
||||
|
||||
static void *eckey_alloc_wrap( void )
|
||||
{
|
||||
|
@ -189,7 +178,11 @@ const pk_info_t eckey_info = {
|
|||
"EC",
|
||||
eckey_get_size,
|
||||
eckey_can_do,
|
||||
#if defined(POLARSSL_ECDSA_C)
|
||||
eckey_verify_wrap,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
eckey_alloc_wrap,
|
||||
eckey_free_wrap,
|
||||
eckey_debug,
|
||||
|
@ -204,26 +197,12 @@ static int eckeydh_can_do( pk_type_t type )
|
|||
type == POLARSSL_PK_ECKEY_DH );
|
||||
}
|
||||
|
||||
static int eckeydh_verify_wrap( void *ctx, md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
const unsigned char *sig, size_t sig_len )
|
||||
{
|
||||
((void) ctx);
|
||||
((void) md_alg);
|
||||
((void) hash);
|
||||
((void) hash_len);
|
||||
((void) sig);
|
||||
((void) sig_len);
|
||||
|
||||
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
|
||||
}
|
||||
|
||||
const pk_info_t eckeydh_info = {
|
||||
POLARSSL_PK_ECKEY_DH,
|
||||
"EC_DH",
|
||||
eckey_get_size, /* Same underlying key structure */
|
||||
eckeydh_can_do,
|
||||
eckeydh_verify_wrap,
|
||||
NULL,
|
||||
eckey_alloc_wrap, /* Same underlying key structure */
|
||||
eckey_free_wrap, /* Same underlying key structure */
|
||||
eckey_debug, /* Same underlying key structure */
|
||||
|
|
Loading…
Reference in a new issue