mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-18 05:42:35 +00:00
New preprocessor symbol indicating that AESNI support is present
The configuration symbol MBEDTLS_AESNI_C requests AESNI support, but it is ignored if the platform doesn't have AESNI. This allows keeping MBEDTLS_AESNI_C enabled (as it is in the default build) when building for platforms other than x86_64, or when MBEDTLS_HAVE_ASM is disabled. To facilitate maintenance, always use the symbol MBEDTLS_AESNI_HAVE_CODE to answer the question "can I call mbedtls_aesni_xxx functions?", rather than repeating the check `defined(MBEDTLS_AESNI_C) && ...`. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
4e20144882
commit
9af58cd7f8
@ -541,7 +541,7 @@ int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
|
|||||||
#endif
|
#endif
|
||||||
RK = ctx->buf + ctx->rk_offset;
|
RK = ctx->buf + ctx->rk_offset;
|
||||||
|
|
||||||
#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
|
#if defined(MBEDTLS_AESNI_HAVE_CODE)
|
||||||
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
|
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
|
||||||
return mbedtls_aesni_setkey_enc((unsigned char *) RK, key, keybits);
|
return mbedtls_aesni_setkey_enc((unsigned char *) RK, key, keybits);
|
||||||
}
|
}
|
||||||
@ -653,7 +653,7 @@ int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
|
|||||||
|
|
||||||
ctx->nr = cty.nr;
|
ctx->nr = cty.nr;
|
||||||
|
|
||||||
#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
|
#if defined(MBEDTLS_AESNI_HAVE_CODE)
|
||||||
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
|
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
|
||||||
mbedtls_aesni_inverse_key((unsigned char *) RK,
|
mbedtls_aesni_inverse_key((unsigned char *) RK,
|
||||||
(const unsigned char *) (cty.buf + cty.rk_offset), ctx->nr);
|
(const unsigned char *) (cty.buf + cty.rk_offset), ctx->nr);
|
||||||
@ -957,7 +957,7 @@ int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
|
|||||||
return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
|
return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
|
#if defined(MBEDTLS_AESNI_HAVE_CODE)
|
||||||
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
|
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
|
||||||
return mbedtls_aesni_crypt_ecb(ctx, mode, input, output);
|
return mbedtls_aesni_crypt_ecb(ctx, mode, input, output);
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,30 @@
|
|||||||
#define MBEDTLS_AESNI_AES 0x02000000u
|
#define MBEDTLS_AESNI_AES 0x02000000u
|
||||||
#define MBEDTLS_AESNI_CLMUL 0x00000002u
|
#define MBEDTLS_AESNI_CLMUL 0x00000002u
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
|
#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
|
||||||
(defined(__amd64__) || defined(__x86_64__)) && \
|
(defined(__amd64__) || defined(__x86_64__)) && \
|
||||||
!defined(MBEDTLS_HAVE_X86_64)
|
!defined(MBEDTLS_HAVE_X86_64)
|
||||||
#define MBEDTLS_HAVE_X86_64
|
#define MBEDTLS_HAVE_X86_64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_AESNI_C)
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_X86_64)
|
#if defined(MBEDTLS_HAVE_X86_64)
|
||||||
|
#define MBEDTLS_AESNI_HAVE_CODE // via assembly
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define MBEDTLS_HAVE_AESNI_INTRINSICS
|
||||||
|
#endif
|
||||||
|
#if defined(__GNUC__) && defined(__AES__)
|
||||||
|
#define MBEDTLS_HAVE_AESNI_INTRINSICS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_HAVE_AESNI_INTRINSICS)
|
||||||
|
#define MBEDTLS_AESNI_HAVE_CODE // via intrinsics
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_AESNI_HAVE_CODE)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -127,6 +144,7 @@ int mbedtls_aesni_setkey_enc(unsigned char *rk,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* MBEDTLS_HAVE_X86_64 */
|
#endif /* MBEDTLS_AESNI_HAVE_CODE */
|
||||||
|
#endif /* MBEDTLS_AESNI_C */
|
||||||
|
|
||||||
#endif /* MBEDTLS_AESNI_H */
|
#endif /* MBEDTLS_AESNI_H */
|
||||||
|
@ -86,7 +86,7 @@ static int gcm_gen_table(mbedtls_gcm_context *ctx)
|
|||||||
ctx->HL[8] = vl;
|
ctx->HL[8] = vl;
|
||||||
ctx->HH[8] = vh;
|
ctx->HH[8] = vh;
|
||||||
|
|
||||||
#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
|
#if defined(MBEDTLS_AESNI_HAVE_CODE)
|
||||||
/* With CLMUL support, we need only h, not the rest of the table */
|
/* With CLMUL support, we need only h, not the rest of the table */
|
||||||
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_CLMUL)) {
|
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_CLMUL)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -183,7 +183,7 @@ static void gcm_mult(mbedtls_gcm_context *ctx, const unsigned char x[16],
|
|||||||
unsigned char lo, hi, rem;
|
unsigned char lo, hi, rem;
|
||||||
uint64_t zh, zl;
|
uint64_t zh, zl;
|
||||||
|
|
||||||
#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
|
#if defined(MBEDTLS_AESNI_HAVE_CODE)
|
||||||
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_CLMUL)) {
|
if (mbedtls_aesni_has_support(MBEDTLS_AESNI_CLMUL)) {
|
||||||
unsigned char h[16];
|
unsigned char h[16];
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ static void gcm_mult(mbedtls_gcm_context *ctx, const unsigned char x[16],
|
|||||||
mbedtls_aesni_gcm_mult(output, x, h);
|
mbedtls_aesni_gcm_mult(output, x, h);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_AESNI_C && MBEDTLS_HAVE_X86_64 */
|
#endif /* MBEDTLS_AESNI_HAVE_CODE */
|
||||||
|
|
||||||
lo = x[15] & 0xf;
|
lo = x[15] & 0xf;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user