From 526b602ebd867c30f998125831325fc9bb5d788a Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Wed, 9 Nov 2016 16:25:12 -0700 Subject: [PATCH] AESNI support with EVP AES --- wolfcrypt/src/aes.c | 3 +++ wolfcrypt/test/test.c | 8 ++++---- wolfssl/openssl/evp.h | 10 ++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index d234924ac..cdd8d30fb 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -1959,6 +1959,9 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen, checkAESNI = 1; } if (haveAESNI) { + #ifdef WOLFSSL_AES_COUNTER + aes->left = 0; + #endif /* WOLFSSL_AES_COUNTER */ aes->use_aesni = 1; if (iv) XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE); diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 1f3054bc6..9deae33f0 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -7195,7 +7195,7 @@ int openssl_test(void) (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0) return -3316; printf("EVP_Cipher\n"); - if (EVP_Cipher(&en, (byte*)cipherBuff, (byte*)ctr192Plain, AES_BLOCK_SIZE*4) == 0) + if (EVP_Cipher(&en, (byte*)cipherBuff, (byte*)ctr192Plain, AES_BLOCK_SIZE) == 0) return -3317; EVP_CIPHER_CTX_init(&de); if (EVP_CipherInit(&de, EVP_aes_192_ctr(), @@ -7203,7 +7203,7 @@ int openssl_test(void) return -3318; XMEMSET(plainBuff, 0, sizeof(plainBuff)); - if (EVP_Cipher(&de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE*4) == 0) + if (EVP_Cipher(&de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE) == 0) return -3319; if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain))) @@ -7215,7 +7215,7 @@ int openssl_test(void) if (EVP_CipherInit(&en, EVP_aes_256_ctr(), (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0) return -3322; - if (EVP_Cipher(&en, (byte*)cipherBuff, (byte*)ctr256Plain, AES_BLOCK_SIZE*4) == 0) + if (EVP_Cipher(&en, (byte*)cipherBuff, (byte*)ctr256Plain, AES_BLOCK_SIZE) == 0) return -3323; EVP_CIPHER_CTX_init(&de); if (EVP_CipherInit(&de, EVP_aes_256_ctr(), @@ -7223,7 +7223,7 @@ int openssl_test(void) return -3324; XMEMSET(plainBuff, 0, sizeof(plainBuff)); - if (EVP_Cipher(&de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE*4) == 0) + if (EVP_Cipher(&de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE) == 0) return -3325; if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain))) diff --git a/wolfssl/openssl/evp.h b/wolfssl/openssl/evp.h index b5f85c4a7..90a14c07a 100644 --- a/wolfssl/openssl/evp.h +++ b/wolfssl/openssl/evp.h @@ -159,14 +159,16 @@ typedef struct WOLFSSL_EVP_CIPHER_CTX { unsigned char enc; /* if encrypt side, then true */ unsigned char cipherType; #ifndef NO_AES - unsigned char iv[AES_BLOCK_SIZE]; /* working iv pointer into cipher */ + /* working iv pointer into cipher */ + ALIGN16 unsigned char iv[AES_BLOCK_SIZE]; #elif !defined(NO_DES3) - unsigned char iv[DES_BLOCK_SIZE]; /* working iv pointer into cipher */ + /* working iv pointer into cipher */ + ALIGN16 unsigned char iv[DES_BLOCK_SIZE]; #endif WOLFSSL_Cipher cipher; - byte buf[WOLFSSL_EVP_BUF_SIZE]; + ALIGN16 byte buf[WOLFSSL_EVP_BUF_SIZE]; int bufUsed; - byte fin[WOLFSSL_EVP_BUF_SIZE]; + ALIGN16 byte fin[WOLFSSL_EVP_BUF_SIZE]; int finUsed; } WOLFSSL_EVP_CIPHER_CTX;