From 15699380e59253223604ffa5183292dc03321aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 14 Aug 2013 19:22:48 +0200 Subject: [PATCH] Small PK cleanups - better error codes - rm now-useless include --- include/polarssl/error.h | 2 +- include/polarssl/pk.h | 3 ++- library/error.c | 2 ++ library/pk.c | 15 +++------------ 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/include/polarssl/error.h b/include/polarssl/error.h index 10e68f83b..889e4bebc 100644 --- a/include/polarssl/error.h +++ b/include/polarssl/error.h @@ -77,7 +77,7 @@ * PEM 1 9 * PKCS#12 1 4 (Started from top) * X509 2 25 - * PK 2 1 (Started from top) + * PK 2 3 (Started from top) * DHM 3 6 * PKCS5 3 4 (Started from top) * RSA 4 9 diff --git a/include/polarssl/pk.h b/include/polarssl/pk.h index 6a3d4b8a7..a39fadf7f 100644 --- a/include/polarssl/pk.h +++ b/include/polarssl/pk.h @@ -43,7 +43,8 @@ #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 use a RSA key as EC, or to modify key type. */ +#define POLARSSL_ERR_PK_BAD_INPUT_DATA -0x2E80 /**< Bad input parameters to function. */ #if defined(POLARSSL_RSA_C) /** diff --git a/library/error.c b/library/error.c index 333a8f850..0ea3c297c 100644 --- a/library/error.c +++ b/library/error.c @@ -252,6 +252,8 @@ void polarssl_strerror( int ret, char *buf, size_t buflen ) snprintf( buf, buflen, "PK - Memory alloation failed" ); if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) ) snprintf( buf, buflen, "PK - Type mismatch, eg attempt to use a RSA key as EC, or to modify key type" ); + if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) ) + snprintf( buf, buflen, "PK - Bad input parameters to function" ); #endif /* POLARSSL_PK_C */ #if defined(POLARSSL_PKCS12_C) diff --git a/library/pk.c b/library/pk.c index d8b4c8598..61544ebd4 100644 --- a/library/pk.c +++ b/library/pk.c @@ -38,15 +38,6 @@ #include "polarssl/ecdsa.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" -#else -#define polarssl_malloc malloc -#define polarssl_free free -#endif - -#include - /* * Initialise a pk_context */ @@ -114,7 +105,7 @@ int pk_set_type( pk_context *ctx, pk_type_t type ) } if( ( info = pk_info_from_type( type ) ) == NULL ) - return( POLARSSL_ERR_PK_TYPE_MISMATCH ); + return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) return( POLARSSL_ERR_PK_MALLOC_FAILED ); @@ -144,7 +135,7 @@ int pk_verify( pk_context *ctx, const unsigned char *sig, size_t sig_len ) { if( ctx == NULL || ctx->pk_info == NULL ) - return( POLARSSL_ERR_PK_TYPE_MISMATCH ); // TODO + return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); return( ctx->pk_info->verify_func( ctx->pk_ctx, hash, md_info, sig, sig_len ) ); } @@ -166,7 +157,7 @@ size_t pk_get_size( const pk_context *ctx ) int pk_debug( const pk_context *ctx, pk_debug_item *items ) { if( ctx == NULL || ctx->pk_info == NULL ) - return( POLARSSL_ERR_PK_TYPE_MISMATCH ); // TODO + return( POLARSSL_ERR_PK_BAD_INPUT_DATA ); ctx->pk_info->debug_func( ctx->pk_ctx, items ); return( 0 );