mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-05-11 22:42:23 +02:00
Implement static dispatch with SINGLE_PK_TYPE
For optional functions, we introduce an extra macro to tell if the function is omitted. As the C preprocessor doesn't directly support comparing strings, testing if the _FUNC macro is defined to NULL isn't obvious. One could probably play tricks to avoid the need for _OMIT macros, but the small amount of (entirely local) duplication here is probably a lesser evil than extra preprocessor complexity.
This commit is contained in:
@@ -41,6 +41,9 @@
|
||||
* Each PK type that can be used with MBEDTLS_PK_SINGLE_TYPE needs to have
|
||||
* the following MBEDTLS_PK_INFO_{FIELD} definitions, plus a dummy one for the
|
||||
* base name. For now, only ECKEY with MBEDTLS_USE_TINYCRYPT is defined.
|
||||
*
|
||||
* For optional functions that are omitted, we need both the _FUNC field
|
||||
* defined to NULL, and an extra macro _OMIT defined to 1.
|
||||
*/
|
||||
|
||||
#if defined(MBEDTLS_USE_TINYCRYPT)
|
||||
@@ -54,11 +57,14 @@
|
||||
#define MBEDTLS_PK_INFO_ECKEY_VERIFY_FUNC uecc_eckey_verify_wrap
|
||||
#define MBEDTLS_PK_INFO_ECKEY_SIGN_FUNC uecc_eckey_sign_wrap
|
||||
#define MBEDTLS_PK_INFO_ECKEY_DECRYPT_FUNC NULL
|
||||
#define MBEDTLS_PK_INFO_ECKEY_DECRYPT_OMIT 1
|
||||
#define MBEDTLS_PK_INFO_ECKEY_ENCRYPT_FUNC NULL
|
||||
#define MBEDTLS_PK_INFO_ECKEY_ENCRYPT_OMIT 1
|
||||
#define MBEDTLS_PK_INFO_ECKEY_CHECK_PAIR_FUNC uecc_eckey_check_pair
|
||||
#define MBEDTLS_PK_INFO_ECKEY_CTX_ALLOC_FUNC uecc_eckey_alloc_wrap
|
||||
#define MBEDTLS_PK_INFO_ECKEY_CTX_FREE_FUNC uecc_eckey_free_wrap
|
||||
#define MBEDTLS_PK_INFO_ECKEY_DEBUG_FUNC NULL
|
||||
#define MBEDTLS_PK_INFO_ECKEY_DEBUG_OMIT 1
|
||||
#endif /* MBEDTLS_USE_TINYCRYPT */
|
||||
|
||||
/*
|
||||
@@ -69,13 +75,19 @@
|
||||
#define MBEDTLS_PK_INFO_GET_BITLEN_T( PK ) PK ## _GET_BITLEN
|
||||
#define MBEDTLS_PK_INFO_CAN_DO_T( PK ) PK ## _CAN_DO
|
||||
#define MBEDTLS_PK_INFO_VERIFY_FUNC_T( PK ) PK ## _VERIFY_FUNC
|
||||
#define MBEDTLS_PK_INFO_VERIFY_OMIT_T( PK ) PK ## _VERIFY_OMIT
|
||||
#define MBEDTLS_PK_INFO_SIGN_FUNC_T( PK ) PK ## _SIGN_FUNC
|
||||
#define MBEDTLS_PK_INFO_SIGN_OMIT_T( PK ) PK ## _SIGN_OMIT
|
||||
#define MBEDTLS_PK_INFO_DECRYPT_FUNC_T( PK ) PK ## _DECRYPT_FUNC
|
||||
#define MBEDTLS_PK_INFO_DECRYPT_OMIT_T( PK ) PK ## _DECRYPT_OMIT
|
||||
#define MBEDTLS_PK_INFO_ENCRYPT_FUNC_T( PK ) PK ## _ENCRYPT_FUNC
|
||||
#define MBEDTLS_PK_INFO_ENCRYPT_OMIT_T( PK ) PK ## _ENCRYPT_OMIT
|
||||
#define MBEDTLS_PK_INFO_CHECK_PAIR_FUNC_T( PK ) PK ## _CHECK_PAIR_FUNC
|
||||
#define MBEDTLS_PK_INFO_CHECK_PAIR_OMIT_T( PK ) PK ## _CHECK_PAIR_OMIT
|
||||
#define MBEDTLS_PK_INFO_CTX_ALLOC_FUNC_T( PK ) PK ## _CTX_ALLOC_FUNC
|
||||
#define MBEDTLS_PK_INFO_CTX_FREE_FUNC_T( PK ) PK ## _CTX_FREE_FUNC
|
||||
#define MBEDTLS_PK_INFO_DEBUG_FUNC_T( PK ) PK ## _DEBUG_FUNC
|
||||
#define MBEDTLS_PK_INFO_DEBUG_OMIT_T( PK ) PK ## _DEBUG_OMIT
|
||||
|
||||
/* Wrappers around MBEDTLS_PK_INFO_{FIELD}_T() which makes sure that
|
||||
* the argument is macro-expanded before concatenated with the
|
||||
@@ -87,13 +99,19 @@
|
||||
#define MBEDTLS_PK_INFO_GET_BITLEN( PK ) MBEDTLS_PK_INFO_GET_BITLEN_T( PK )
|
||||
#define MBEDTLS_PK_INFO_CAN_DO( PK ) MBEDTLS_PK_INFO_CAN_DO_T( PK )
|
||||
#define MBEDTLS_PK_INFO_VERIFY_FUNC( PK ) MBEDTLS_PK_INFO_VERIFY_FUNC_T( PK )
|
||||
#define MBEDTLS_PK_INFO_VERIFY_OMIT( PK ) MBEDTLS_PK_INFO_VERIFY_OMIT_T( PK )
|
||||
#define MBEDTLS_PK_INFO_SIGN_FUNC( PK ) MBEDTLS_PK_INFO_SIGN_FUNC_T( PK )
|
||||
#define MBEDTLS_PK_INFO_SIGN_OMIT( PK ) MBEDTLS_PK_INFO_SIGN_OMIT_T( PK )
|
||||
#define MBEDTLS_PK_INFO_DECRYPT_FUNC( PK ) MBEDTLS_PK_INFO_DECRYPT_FUNC_T( PK )
|
||||
#define MBEDTLS_PK_INFO_DECRYPT_OMIT( PK ) MBEDTLS_PK_INFO_DECRYPT_OMIT_T( PK )
|
||||
#define MBEDTLS_PK_INFO_ENCRYPT_FUNC( PK ) MBEDTLS_PK_INFO_ENCRYPT_FUNC_T( PK )
|
||||
#define MBEDTLS_PK_INFO_ENCRYPT_OMIT( PK ) MBEDTLS_PK_INFO_ENCRYPT_OMIT_T( PK )
|
||||
#define MBEDTLS_PK_INFO_CHECK_PAIR_FUNC( PK ) MBEDTLS_PK_INFO_CHECK_PAIR_FUNC_T( PK )
|
||||
#define MBEDTLS_PK_INFO_CHECK_PAIR_OMIT( PK ) MBEDTLS_PK_INFO_CHECK_PAIR_OMIT_T( PK )
|
||||
#define MBEDTLS_PK_INFO_CTX_ALLOC_FUNC( PK ) MBEDTLS_PK_INFO_CTX_ALLOC_FUNC_T( PK )
|
||||
#define MBEDTLS_PK_INFO_CTX_FREE_FUNC( PK ) MBEDTLS_PK_INFO_CTX_FREE_FUNC_T( PK )
|
||||
#define MBEDTLS_PK_INFO_DEBUG_FUNC( PK ) MBEDTLS_PK_INFO_DEBUG_FUNC_T( PK )
|
||||
#define MBEDTLS_PK_INFO_DEBUG_OMIT( PK ) MBEDTLS_PK_INFO_DEBUG_OMIT_T( PK )
|
||||
|
||||
struct mbedtls_pk_info_t
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user