mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 22:58:18 +00:00
Fix some more ifdef's RSA/EC, in pk and debug
This commit is contained in:
parent
ab2d9836b4
commit
fd5164e283
3 changed files with 43 additions and 59 deletions
|
@ -44,7 +44,7 @@
|
||||||
* before using this macro!
|
* before using this macro!
|
||||||
*/
|
*/
|
||||||
#define pk_rsa( pk ) ( (rsa_context *) (pk).data )
|
#define pk_rsa( pk ) ( (rsa_context *) (pk).data )
|
||||||
#endif
|
#endif /* POLARSSL_RSA_C */
|
||||||
|
|
||||||
#if defined(POLARSSL_ECP_C)
|
#if defined(POLARSSL_ECP_C)
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
* before using this macro!
|
* before using this macro!
|
||||||
*/
|
*/
|
||||||
#define pk_ec( pk ) ( (ecp_keypair *) (pk).data )
|
#define pk_ec( pk ) ( (ecp_keypair *) (pk).data )
|
||||||
#endif
|
#endif /* POLARSSL_ECP_C */
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#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.
|
* POLARSSL_ERR_PK_TYPE_MISMATCH if ctx was not empty.
|
||||||
*/
|
*/
|
||||||
int pk_wrap_rsa( pk_context *ctx, const rsa_context *rsa);
|
int pk_wrap_rsa( pk_context *ctx, const rsa_context *rsa);
|
||||||
#endif
|
#endif /* POLARSSL_RSA_C */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,27 +250,25 @@ void debug_print_crt( const ssl_context *ssl, int level,
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
ssl->f_dbg( ssl->p_dbg, level, str );
|
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:
|
debug_print_mpi( ssl, level, file, line,
|
||||||
case POLARSSL_PK_ECDSA:
|
"crt->rsa.N", &pk_rsa( crt->pk )->N );
|
||||||
debug_print_msg( ssl, level, file, line,
|
debug_print_mpi( ssl, level, file, line,
|
||||||
"crt->pk.type is not valid" );
|
"crt->rsa.E", &pk_rsa( crt->pk )->E );
|
||||||
break;
|
} else
|
||||||
|
#endif /* POLARSSL_RSA_C */
|
||||||
case POLARSSL_PK_RSA:
|
#if defined(POLARSSL_ECP_C)
|
||||||
debug_print_mpi( ssl, level, file, line,
|
if( crt->pk.type == POLARSSL_PK_ECKEY ||
|
||||||
"crt->rsa.N", &pk_rsa( crt->pk )->N );
|
crt->pk.type == POLARSSL_PK_ECKEY_DH )
|
||||||
debug_print_mpi( ssl, level, file, line,
|
{
|
||||||
"crt->rsa.E", &pk_rsa( crt->pk )->E );
|
debug_print_ecp( ssl, level, file, line,
|
||||||
break;
|
"crt->eckey.Q", &pk_ec( crt->pk )->Q );
|
||||||
|
} else
|
||||||
case POLARSSL_PK_ECKEY:
|
#endif /* POLARSSL_ECP_C */
|
||||||
case POLARSSL_PK_ECKEY_DH:
|
debug_print_msg( ssl, level, file, line,
|
||||||
debug_print_ecp( ssl, level, file, line,
|
"crt->pk.type is not valid" );
|
||||||
"crt->eckey.Q", &pk_ec( crt->pk )->Q );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
crt = crt->next;
|
crt = crt->next;
|
||||||
}
|
}
|
||||||
|
|
58
library/pk.c
58
library/pk.c
|
@ -60,29 +60,23 @@ void pk_free( pk_context *ctx )
|
||||||
if( ctx == NULL )
|
if( ctx == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch( ctx->type )
|
|
||||||
{
|
|
||||||
case POLARSSL_PK_NONE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
#if defined(POLARSSL_RSA_C)
|
#if defined(POLARSSL_RSA_C)
|
||||||
case POLARSSL_PK_RSA:
|
if( ctx->type == POLARSSL_PK_RSA )
|
||||||
rsa_free( ctx->data );
|
rsa_free( ctx->data );
|
||||||
break;
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(POLARSSL_ECP_C)
|
#if defined(POLARSSL_ECP_C)
|
||||||
case POLARSSL_PK_ECKEY:
|
if( ctx->type == POLARSSL_PK_ECKEY || ctx->type == POLARSSL_PK_ECKEY_DH )
|
||||||
case POLARSSL_PK_ECKEY_DH:
|
ecp_keypair_free( ctx->data );
|
||||||
ecp_keypair_free( ctx->data );
|
else
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(POLARSSL_ECDSA_C)
|
#if defined(POLARSSL_ECDSA_C)
|
||||||
case POLARSSL_PK_ECDSA:
|
if( ctx->type == POLARSSL_PK_ECDSA )
|
||||||
ecdsa_free( ctx->data );
|
ecdsa_free( ctx->data );
|
||||||
break;
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
; /* guard for the else's above */
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! ctx->dont_free )
|
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 )
|
int pk_set_type( pk_context *ctx, pk_type_t type )
|
||||||
{
|
{
|
||||||
size_t size = 0;
|
size_t size;
|
||||||
|
|
||||||
if( ctx->type == type )
|
if( ctx->type == type )
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
@ -105,30 +99,22 @@ int pk_set_type( pk_context *ctx, pk_type_t type )
|
||||||
if( ctx->type != POLARSSL_PK_NONE )
|
if( ctx->type != POLARSSL_PK_NONE )
|
||||||
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
|
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
|
||||||
|
|
||||||
switch( type )
|
|
||||||
{
|
|
||||||
#if defined(POLARSSL_RSA_C)
|
#if defined(POLARSSL_RSA_C)
|
||||||
case POLARSSL_PK_RSA:
|
if( type == POLARSSL_PK_RSA )
|
||||||
size = sizeof( rsa_context );
|
size = sizeof( rsa_context );
|
||||||
break;
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(POLARSSL_ECP_C)
|
#if defined(POLARSSL_ECP_C)
|
||||||
case POLARSSL_PK_ECKEY:
|
if( type == POLARSSL_PK_ECKEY || type == POLARSSL_PK_ECKEY_DH )
|
||||||
case POLARSSL_PK_ECKEY_DH:
|
size = sizeof( ecp_keypair );
|
||||||
size = sizeof( ecp_keypair );
|
else
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(POLARSSL_ECDSA_C)
|
#if defined(POLARSSL_ECDSA_C)
|
||||||
case POLARSSL_PK_ECDSA:
|
if( type == POLARSSL_PK_ECDSA )
|
||||||
size = sizeof( ecdsa_context );
|
size = sizeof( ecdsa_context );
|
||||||
break;
|
else
|
||||||
#endif
|
#endif
|
||||||
|
size = 0; /* should never be executed */
|
||||||
case POLARSSL_PK_NONE:
|
|
||||||
; /* Cannot happen, but the compiler doesn't know */
|
|
||||||
}
|
|
||||||
|
|
||||||
if( ( ctx->data = malloc( size ) ) == NULL )
|
if( ( ctx->data = malloc( size ) ) == NULL )
|
||||||
return( POLARSSL_ERR_PK_MALLOC_FAILED );
|
return( POLARSSL_ERR_PK_MALLOC_FAILED );
|
||||||
|
|
Loading…
Reference in a new issue