From 81c313ccc6a732771d6121eeb6962060dd379548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 9 Jul 2013 10:35:54 +0200 Subject: [PATCH] Add #ifdef's on RSA and EC in PK --- include/polarssl/pk.h | 4 ++++ library/pk.c | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/polarssl/pk.h b/include/polarssl/pk.h index 3806027b4..00f8cfcb1 100644 --- a/include/polarssl/pk.h +++ b/include/polarssl/pk.h @@ -38,9 +38,13 @@ extern "C" { */ typedef enum { POLARSSL_PK_NONE=0, +#if defined(POLARSSL_RSA_C) POLARSSL_PK_RSA, +#endif +#if defined(POLARSSL_ECP_C) POLARSSL_PK_ECKEY, POLARSSL_PK_ECKEY_DH, +#endif } pk_type_t; /** diff --git a/library/pk.c b/library/pk.c index edbbf5037..71505ed2e 100644 --- a/library/pk.c +++ b/library/pk.c @@ -25,10 +25,15 @@ #include "polarssl/config.h" -#include "polarssl/rsa.h" -#include "polarssl/ecp.h" #include "polarssl/pk.h" +#if defined(POLARSSL_RSA_C) +#include "polarssl/rsa.h" +#endif +#if defined(POLARSSL_ECP_C) +#include "polarssl/ecp.h" +#endif + #include /* @@ -56,14 +61,18 @@ void pk_free( pk_context *ctx ) case POLARSSL_PK_NONE: break; +#if defined(POLARSSL_RSA_C) case POLARSSL_PK_RSA: rsa_free( ctx->data ); break; +#endif +#if defined(POLARSSL_ECP_C) case POLARSSL_PK_ECKEY: case POLARSSL_PK_ECKEY_DH: ecp_keypair_free( ctx->data ); break; +#endif } free( ctx-> data ); @@ -77,13 +86,26 @@ void pk_free( pk_context *ctx ) */ int pk_set_type( pk_context *ctx, pk_type_t type ) { - size_t size = type == POLARSSL_PK_RSA ? sizeof( rsa_context ) - : type == POLARSSL_PK_ECKEY ? sizeof( ecp_keypair ) - : type == POLARSSL_PK_ECKEY_DH ? sizeof( ecp_keypair ) - : 0; + size_t size = 0; - if( size == 0 ) - return( 0 ); + switch( type ) + { +#if defined(POLARSSL_RSA_C) + case POLARSSL_PK_RSA: + size = sizeof( rsa_context ); + break; +#endif + +#if defined(POLARSSL_ECP_C) + case POLARSSL_PK_ECKEY: + case POLARSSL_PK_ECKEY_DH: + size = sizeof( ecp_keypair ); + break; +#endif + + case POLARSSL_PK_NONE: + ; /* Should not happen */ + } if( ( ctx->data = malloc( size ) ) == NULL ) return( POLARSSL_ERR_PK_MALLOC_FAILED );