Rework framework for assembler support for AES counter mode and add
[openssl.git] / crypto / evp / e_aes.c
index 20963996313f342d9725bff592b6d6c953d8cd1e..3dc85762a2b78de6e9da8a4a82bedfbaad25c636 100644 (file)
@@ -55,6 +55,7 @@
 #include <string.h>
 #include <assert.h>
 #include <openssl/aes.h>
+#include <openssl/modes.h>
 #include "evp_locl.h"
 
 static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
@@ -101,9 +102,19 @@ static int aes_counter (EVP_CIPHER_CTX *ctx, unsigned char *out,
 {
        unsigned int num;
        num = ctx->num;
-       AES_ctr128_encrypt (in,out,len,
+#ifdef AES_CTR_ASM
+       void AES_ctr32_encrypt(const unsigned char *in, unsigned char *out,
+                       size_t blocks, const AES_KEY *key,
+                       const unsigned char ivec[AES_BLOCK_SIZE]);
+
+       CRYPTO_ctr128_encrypt_ctr32(in,out,len,
+               &((EVP_AES_KEY *)ctx->cipher_data)->ks,
+               ctx->iv,ctx->buf,&num,(ctr128_f)AES_ctr32_encrypt);
+#else
+       CRYPTO_ctr128_encrypt(in,out,len,
                &((EVP_AES_KEY *)ctx->cipher_data)->ks,
-               ctx->iv,ctx->buf,&num);
+               ctx->iv,ctx->buf,&num,(block128_f)AES_encrypt);
+#endif
        ctx->num = (size_t)num;
        return 1;
 }
@@ -111,7 +122,7 @@ static int aes_counter (EVP_CIPHER_CTX *ctx, unsigned char *out,
 static const EVP_CIPHER aes_128_ctr_cipher=
        {
        NID_aes_128_ctr,1,16,16,
-       EVP_CIPH_VARIABLE_LENGTH|EVP_CIPH_CUSTOM_IV,
+       EVP_CIPH_CUSTOM_IV,
        aes_init_key,
        aes_counter,
        NULL,
@@ -128,7 +139,7 @@ const EVP_CIPHER *EVP_aes_128_ctr (void)
 static const EVP_CIPHER aes_192_ctr_cipher=
        {
        NID_aes_192_ctr,1,24,16,
-       EVP_CIPH_VARIABLE_LENGTH|EVP_CIPH_CUSTOM_IV,
+       EVP_CIPH_CUSTOM_IV,
        aes_init_key,
        aes_counter,
        NULL,
@@ -145,7 +156,7 @@ const EVP_CIPHER *EVP_aes_192_ctr (void)
 static const EVP_CIPHER aes_256_ctr_cipher=
        {
        NID_aes_256_ctr,1,32,16,
-       EVP_CIPH_VARIABLE_LENGTH|EVP_CIPH_CUSTOM_IV,
+       EVP_CIPH_CUSTOM_IV,
        aes_init_key,
        aes_counter,
        NULL,