Skip to content

Commit

Permalink
Change aes_ce detection function and macros
Browse files Browse the repository at this point in the history
Signed-off-by: Jerry Yu <[email protected]>
  • Loading branch information
yuhaoth committed Apr 3, 2023
1 parent 7a02bfd commit 4196260
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
8 changes: 4 additions & 4 deletions library/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
}
#endif

#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_HAVE_ARM64)
#if MBEDTLS_AES_HAVE_AESCE
if (mbedtls_aesce_has_support()) {
return mbedtls_aesce_setkey_enc((unsigned char *) RK, key, keybits);
}
Expand Down Expand Up @@ -689,7 +689,7 @@ int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
}
#endif

#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_HAVE_ARM64)
#if MBEDTLS_AES_HAVE_AESCE
if (mbedtls_aesce_has_support()) {
mbedtls_aesce_inverse_key(
(unsigned char *) RK,
Expand Down Expand Up @@ -1015,7 +1015,7 @@ int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
}
#endif

#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_HAVE_ARM64)
#if MBEDTLS_AES_HAVE_AESCE
if (mbedtls_aesce_has_support()) {
return mbedtls_aesce_crypt_ecb(ctx, mode, input, output);
}
Expand Down Expand Up @@ -1789,7 +1789,7 @@ int mbedtls_aes_self_test(int verbose)
mbedtls_printf(" AES note: using AESNI.\n");
} else
#endif
#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_HAVE_ARM64)
#if MBEDTLS_AES_HAVE_AESCE
if (mbedtls_aesce_has_support()) {
mbedtls_printf(" AES note: using AESCE.\n");
} else
Expand Down
20 changes: 9 additions & 11 deletions library/aesce.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@
#define MBEDTLS_AESCE_H

#include "mbedtls/build_info.h"

#include "mbedtls/aes.h"

#include "runtime_internal.h"

#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
defined(__aarch64__) && !defined(MBEDTLS_HAVE_ARM64)
#define MBEDTLS_HAVE_ARM64
#endif

#if defined(MBEDTLS_HAVE_ARM64)
#if MBEDTLS_AES_HAVE_AESCE

#ifdef __cplusplus
extern "C" {
Expand All @@ -47,10 +42,13 @@ extern "C" {
*
* \return 1 if CPU has support for the feature, 0 otherwise
*/
#if !defined(MBEDTLS_AES_HAS_NO_BUILTIN)
int mbedtls_aesce_has_support(void);
#if MBEDTLS_AES_ACCELERATOR_NUM > 1
static inline int mbedtls_aesce_has_support(void)
{
return mbedtls_cpu_has_features(MBEDTLS_HWCAP_AES | MBEDTLS_HWCAP_PMULL, 0);
}
#else
#define /* no-check-names */ mbedtls_aesce_has_support() 1
#define /* no-check-names */ mbedtls_aesce_has_support() true
#endif


Expand Down Expand Up @@ -116,6 +114,6 @@ int mbedtls_aesce_setkey_enc(unsigned char *rk,
}
#endif

#endif /* MBEDTLS_HAVE_ARM64 */
#endif /* MBEDTLS_AES_HAVE_AESCE */

#endif /* MBEDTLS_AESCE_H */
6 changes: 3 additions & 3 deletions library/gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int gcm_gen_table(mbedtls_gcm_context *ctx)
}
#endif

#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_HAVE_ARM64)
#if MBEDTLS_AES_HAVE_AESCE
if (mbedtls_aesce_has_support()) {
return 0;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ static void gcm_mult(mbedtls_gcm_context *ctx, const unsigned char x[16],
}
#endif /* MBEDTLS_AESNI_HAVE_CODE */

#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_HAVE_ARM64)
#if MBEDTLS_AES_HAVE_AESCE
if (mbedtls_aesce_has_support()) {
unsigned char h[16];

Expand Down Expand Up @@ -881,7 +881,7 @@ int mbedtls_gcm_self_test(int verbose)
} else
#endif

#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_HAVE_ARM64)
#if MBEDTLS_AES_HAVE_AESCE
if (mbedtls_aesce_has_support()) {
mbedtls_printf(" GCM note: using AESCE.\n");
} else
Expand Down

0 comments on commit 4196260

Please sign in to comment.