diff --git a/include/mbedtls/pk.h b/include/mbedtls/pk.h index 476bce15f..64cd7b5e6 100644 --- a/include/mbedtls/pk.h +++ b/include/mbedtls/pk.h @@ -126,9 +126,16 @@ typedef struct mbedtls_pk_debug_item /** * \brief Public key information and operations */ +#if defined(MBEDTLS_PK_SINGLE_TYPE) +typedef enum { + MBEDTLS_PK_INVALID_HANDLE, + MBEDTLS_PK_UNIQUE_VALID_HANDLE, +} mbedtls_pk_handle_t; +#else /* MBEDTLS_PK_SINGLE_TYPE */ typedef struct mbedtls_pk_info_t mbedtls_pk_info_t; typedef const mbedtls_pk_info_t *mbedtls_pk_handle_t; #define MBEDTLS_PK_INVALID_HANDLE ( (mbedtls_pk_handle_t) NULL ) +#endif /* MBEDTLS_PK_SINGLE_TYPE */ /** * \brief Public key container diff --git a/include/mbedtls/pk_internal.h b/include/mbedtls/pk_internal.h index 65bd8e93b..fcf488717 100644 --- a/include/mbedtls/pk_internal.h +++ b/include/mbedtls/pk_internal.h @@ -242,6 +242,7 @@ typedef struct } mbedtls_rsa_alt_context; #endif +#if !defined(MBEDTLS_PK_SINGLE_TYPE) #if defined(MBEDTLS_RSA_C) extern const mbedtls_pk_info_t mbedtls_rsa_info; #endif @@ -262,5 +263,6 @@ extern const mbedtls_pk_info_t mbedtls_uecc_eckey_info; #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; #endif +#endif /* MBEDTLS_PK_SINGLE_TYPE */ #endif /* MBEDTLS_PK_WRAP_H */ diff --git a/library/pk.c b/library/pk.c index 9621e9e81..79ae8f683 100644 --- a/library/pk.c +++ b/library/pk.c @@ -745,8 +745,10 @@ static void uecc_eckey_free_wrap( void *ctx ) mbedtls_free( ctx ); } +#if !defined(MBEDTLS_PK_SINGLE_TYPE) const mbedtls_pk_info_t mbedtls_uecc_eckey_info = MBEDTLS_PK_INFO( MBEDTLS_PK_INFO_ECKEY ); +#endif #endif /* MBEDTLS_USE_TINYCRYPT */ /* @@ -1349,6 +1351,14 @@ void mbedtls_pk_restart_free( mbedtls_pk_restart_ctx *ctx ) */ mbedtls_pk_handle_t mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type ) { +#if defined(MBEDTLS_PK_SINGLE_TYPE) + if( pk_type == MBEDTLS_PK_INFO_TYPE( MBEDTLS_PK_SINGLE_TYPE ) ) + return( MBEDTLS_PK_UNIQUE_VALID_HANDLE ); + + return( MBEDTLS_PK_INVALID_HANDLE ); + +#else /* MBEDTLS_PK_SINGLE_TYPE */ + switch( pk_type ) { #if defined(MBEDTLS_RSA_C) case MBEDTLS_PK_RSA: @@ -1375,6 +1385,7 @@ mbedtls_pk_handle_t mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type ) default: return( NULL ); } +#endif /* MBEDTLS_PK_SINGLE_TYPE */ } /*