diff --git a/include/mbedtls/gcm.h b/include/mbedtls/gcm.h index 390ed4c6d0..7dbc3f9be7 100644 --- a/include/mbedtls/gcm.h +++ b/include/mbedtls/gcm.h @@ -44,7 +44,17 @@ extern "C" { #endif -#if !defined(MBEDTLS_GCM_ALT) +#if defined(MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK) +#define SOFT(name) name##_soft +#else +#define SOFT(name) name +#endif /* MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK */ + +#if defined(MBEDTLS_GCM_ALT) +#include "gcm_alt.h" +#endif /* !MBEDTLS_GCM_ALT */ + +#if !defined(MBEDTLS_GCM_ALT) || defined(MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK) #if defined(MBEDTLS_GCM_LARGE_TABLE) #define MBEDTLS_GCM_HTABLE_SIZE 256 @@ -55,7 +65,8 @@ extern "C" { /** * \brief The GCM context structure. */ -typedef struct mbedtls_gcm_context { +typedef struct SOFT(mbedtls_gcm_context) { + #if defined(MBEDTLS_BLOCK_CIPHER_C) mbedtls_block_cipher_context_t MBEDTLS_PRIVATE(block_cipher_ctx); /*!< The cipher context used. */ #else @@ -72,11 +83,7 @@ typedef struct mbedtls_gcm_context { #MBEDTLS_GCM_DECRYPT. */ unsigned char MBEDTLS_PRIVATE(acceleration); /*!< The acceleration to use. */ } -mbedtls_gcm_context; - -#else /* !MBEDTLS_GCM_ALT */ -#include "gcm_alt.h" -#endif /* !MBEDTLS_GCM_ALT */ +SOFT(mbedtls_gcm_context); /** * \brief This function initializes the specified GCM context, @@ -367,6 +374,9 @@ int mbedtls_gcm_finish(mbedtls_gcm_context *ctx, */ void mbedtls_gcm_free(mbedtls_gcm_context *ctx); +#endif /* !defined(MBEDTLS_GCM_ALT) || defined(MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK) */ + + #if defined(MBEDTLS_SELF_TEST) /** diff --git a/library/gcm.c b/library/gcm.c index 5dfac2349c..58f68de770 100644 --- a/library/gcm.c +++ b/library/gcm.c @@ -39,7 +39,33 @@ #include "aesce.h" #endif -#if !defined(MBEDTLS_GCM_ALT) +#if defined(MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK) + +#undef mbedtls_gcm_context +#undef mbedtls_gcm_init +#undef mbedtls_gcm_setkey +#undef mbedtls_gcm_starts +#undef mbedtls_gcm_update_ad +#undef mbedtls_gcm_update +#undef mbedtls_gcm_finish +#undef mbedtls_gcm_crypt_and_tag +#undef mbedtls_gcm_auth_decrypt +#undef mbedtls_gcm_free + +#define mbedtls_gcm_context mbedtls_gcm_context_soft +#define mbedtls_gcm_init mbedtls_gcm_init_soft +#define mbedtls_gcm_setkey mbedtls_gcm_setkey_soft +#define mbedtls_gcm_starts mbedtls_gcm_starts_soft +#define mbedtls_gcm_update_ad mbedtls_gcm_update_ad_soft +#define mbedtls_gcm_update mbedtls_gcm_update_soft +#define mbedtls_gcm_finish mbedtls_gcm_finish_soft +#define mbedtls_gcm_crypt_and_tag mbedtls_gcm_crypt_and_tag_soft +#define mbedtls_gcm_auth_decrypt mbedtls_gcm_auth_decrypt_soft +#define mbedtls_gcm_free mbedtls_gcm_free_soft + +#endif + +#if !defined(MBEDTLS_GCM_ALT) || defined(MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK) /* Used to select the acceleration mechanism */ #define MBEDTLS_GCM_ACC_SMALLTABLE 0 @@ -780,7 +806,7 @@ void mbedtls_gcm_free(mbedtls_gcm_context *ctx) mbedtls_platform_zeroize(ctx, sizeof(mbedtls_gcm_context)); } -#endif /* !MBEDTLS_GCM_ALT */ +#endif /* !defined(MBEDTLS_GCM_ALT) || defined(MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK) */ #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_CCM_GCM_CAN_AES) /*