ARMv8 Crypto Extensions hooks for AES and GCM

This commit is contained in:
Markku-Juhani O. Saarinen 2017-11-20 14:59:12 +00:00 committed by Hanno Becker
parent dfb6015ca7
commit 63f213969c
2 changed files with 23 additions and 1 deletions

View file

@ -39,7 +39,9 @@
#if defined(MBEDTLS_AESNI_C) #if defined(MBEDTLS_AESNI_C)
#include "mbedtls/aesni.h" #include "mbedtls/aesni.h"
#endif #endif
#if defined(MBEDTLS_ARMV8CE_AES_C)
#include "mbedtls/armv8ce_aes.h"
#endif
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C) #if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
@ -1037,6 +1039,11 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
return( mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) ); return( mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) );
#endif #endif
#if defined(MBEDTLS_ARMV8CE_AES_C)
// We don't do runtime checking for ARMv8 Crypto Extensions
return mbedtls_armv8ce_aes_crypt_ecb( ctx, mode, input, output );
#endif
#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86) #if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86)
if( aes_padlock_ace ) if( aes_padlock_ace )
{ {

View file

@ -41,6 +41,10 @@
#include "mbedtls/aesni.h" #include "mbedtls/aesni.h"
#endif #endif
#if defined(MBEDTLS_ARMV8CE_AES_C)
#include "mbedtls/armv8ce_aes.h"
#endif
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
#include "mbedtls/aes.h" #include "mbedtls/aes.h"
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
@ -110,6 +114,12 @@ static int gcm_gen_table( mbedtls_gcm_context *ctx )
if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, h, 16, h, &olen ) ) != 0 ) if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, h, 16, h, &olen ) ) != 0 )
return( ret ); return( ret );
#if defined(MBEDTLS_ARMV8CE_AES_C)
// we don't do feature testing with ARMv8 cryptography extensions
memcpy( ctx ->HL, h, 16 ); // put H at the beginning of buffer
return( 0 ); // that's all we need
#endif
/* pack h as two 64-bits ints, big-endian */ /* pack h as two 64-bits ints, big-endian */
GET_UINT32_BE( hi, h, 0 ); GET_UINT32_BE( hi, h, 0 );
GET_UINT32_BE( lo, h, 4 ); GET_UINT32_BE( lo, h, 4 );
@ -219,6 +229,11 @@ 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_ARMV8CE_AES_C)
mbedtls_armv8ce_gcm_mult( output, x, (const unsigned char *) ctx->HL );
return;
#endif
#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) #if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
if( mbedtls_aesni_has_support( MBEDTLS_AESNI_CLMUL ) ) { if( mbedtls_aesni_has_support( MBEDTLS_AESNI_CLMUL ) ) {
unsigned char h[16]; unsigned char h[16];