From fff80f8879dbbafc8e0ee7c007f85bf90d8dc3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Sat, 17 Aug 2013 15:20:06 +0200 Subject: [PATCH] PK: use NULL for unimplemented operations --- include/polarssl/pk.h | 2 +- library/pk.c | 3 +++ library/pk_wrap.c | 33 ++++++--------------------------- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/include/polarssl/pk.h b/include/polarssl/pk.h index 5104bc020..fb0e92ec5 100644 --- a/include/polarssl/pk.h +++ b/include/polarssl/pk.h @@ -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) diff --git a/library/pk.c b/library/pk.c index 62302b050..3711794e1 100644 --- a/library/pk.c +++ b/library/pk.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 ) ); diff --git a/library/pk_wrap.c b/library/pk_wrap.c index beaa3fd4b..c2a4c7fce 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -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 */