Commit fd5164e2 authored by Manuel Pégourié-Gonnard's avatar Manuel Pégourié-Gonnard Committed by Paul Bakker
Browse files

Fix some more ifdef's RSA/EC, in pk and debug

parent ab2d9836
......@@ -44,7 +44,7 @@
* before using this macro!
*/
#define pk_rsa( pk ) ( (rsa_context *) (pk).data )
#endif
#endif /* POLARSSL_RSA_C */
#if defined(POLARSSL_ECP_C)
/**
......@@ -54,7 +54,7 @@
* before using this macro!
*/
#define pk_ec( pk ) ( (ecp_keypair *) (pk).data )
#endif
#endif /* POLARSSL_ECP_C */
#ifdef __cplusplus
......@@ -120,7 +120,7 @@ int pk_set_type( pk_context *ctx, pk_type_t type );
* POLARSSL_ERR_PK_TYPE_MISMATCH if ctx was not empty.
*/
int pk_wrap_rsa( pk_context *ctx, const rsa_context *rsa);
#endif
#endif /* POLARSSL_RSA_C */
#ifdef __cplusplus
}
......
......@@ -250,27 +250,25 @@ void debug_print_crt( const ssl_context *ssl, int level,
str[maxlen] = '\0';
ssl->f_dbg( ssl->p_dbg, level, str );
switch( crt->pk.type )
#if defined(POLARSSL_RSA_C)
if( crt->pk.type == POLARSSL_PK_RSA )
{
case POLARSSL_PK_NONE:
case POLARSSL_PK_ECDSA:
debug_print_msg( ssl, level, file, line,
"crt->pk.type is not valid" );
break;
case POLARSSL_PK_RSA:
debug_print_mpi( ssl, level, file, line,
"crt->rsa.N", &pk_rsa( crt->pk )->N );
debug_print_mpi( ssl, level, file, line,
"crt->rsa.E", &pk_rsa( crt->pk )->E );
break;
case POLARSSL_PK_ECKEY:
case POLARSSL_PK_ECKEY_DH:
debug_print_ecp( ssl, level, file, line,
"crt->eckey.Q", &pk_ec( crt->pk )->Q );
break;
}
debug_print_mpi( ssl, level, file, line,
"crt->rsa.N", &pk_rsa( crt->pk )->N );
debug_print_mpi( ssl, level, file, line,
"crt->rsa.E", &pk_rsa( crt->pk )->E );
} else
#endif /* POLARSSL_RSA_C */
#if defined(POLARSSL_ECP_C)
if( crt->pk.type == POLARSSL_PK_ECKEY ||
crt->pk.type == POLARSSL_PK_ECKEY_DH )
{
debug_print_ecp( ssl, level, file, line,
"crt->eckey.Q", &pk_ec( crt->pk )->Q );
} else
#endif /* POLARSSL_ECP_C */
debug_print_msg( ssl, level, file, line,
"crt->pk.type is not valid" );
crt = crt->next;
}
......
......@@ -60,29 +60,23 @@ void pk_free( pk_context *ctx )
if( ctx == NULL )
return;
switch( ctx->type )
{
case POLARSSL_PK_NONE:
break;
#if defined(POLARSSL_RSA_C)
case POLARSSL_PK_RSA:
rsa_free( ctx->data );
break;
if( ctx->type == POLARSSL_PK_RSA )
rsa_free( ctx->data );
else
#endif
#if defined(POLARSSL_ECP_C)
case POLARSSL_PK_ECKEY:
case POLARSSL_PK_ECKEY_DH:
ecp_keypair_free( ctx->data );
break;
if( ctx->type == POLARSSL_PK_ECKEY || ctx->type == POLARSSL_PK_ECKEY_DH )
ecp_keypair_free( ctx->data );
else
#endif
#if defined(POLARSSL_ECDSA_C)
case POLARSSL_PK_ECDSA:
ecdsa_free( ctx->data );
break;
if( ctx->type == POLARSSL_PK_ECDSA )
ecdsa_free( ctx->data );
else
#endif
{
; /* guard for the else's above */
}
if( ! ctx->dont_free )
......@@ -97,7 +91,7 @@ void pk_free( pk_context *ctx )
*/
int pk_set_type( pk_context *ctx, pk_type_t type )
{
size_t size = 0;
size_t size;
if( ctx->type == type )
return( 0 );
......@@ -105,30 +99,22 @@ int pk_set_type( pk_context *ctx, pk_type_t type )
if( ctx->type != POLARSSL_PK_NONE )
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
switch( type )
{
#if defined(POLARSSL_RSA_C)
case POLARSSL_PK_RSA:
size = sizeof( rsa_context );
break;
if( type == POLARSSL_PK_RSA )
size = sizeof( rsa_context );
else
#endif
#if defined(POLARSSL_ECP_C)
case POLARSSL_PK_ECKEY:
case POLARSSL_PK_ECKEY_DH:
size = sizeof( ecp_keypair );
break;
if( type == POLARSSL_PK_ECKEY || type == POLARSSL_PK_ECKEY_DH )
size = sizeof( ecp_keypair );
else
#endif
#if defined(POLARSSL_ECDSA_C)
case POLARSSL_PK_ECDSA:
size = sizeof( ecdsa_context );
break;
if( type == POLARSSL_PK_ECDSA )
size = sizeof( ecdsa_context );
else
#endif
case POLARSSL_PK_NONE:
; /* Cannot happen, but the compiler doesn't know */
}
size = 0; /* should never be executed */
if( ( ctx->data = malloc( size ) ) == NULL )
return( POLARSSL_ERR_PK_MALLOC_FAILED );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment