Make sure we get the definition of OPENSSL_NO_AES.
[openssl.git] / crypto / evp / e_aes.c
index 9d91533..bf7c45f 100644 (file)
@@ -48,6 +48,7 @@
  *
  */
 
+#include <openssl/opensslconf.h>
 #ifndef OPENSSL_NO_AES
 #include <openssl/evp.h>
 #include <openssl/err.h>
@@ -66,39 +67,31 @@ typedef struct
 
 #define data(ctx)      EVP_C_DATA(EVP_AES_KEY,ctx)
 
-#define IMPLEMENT_BLOCK_CIPHER_def_ecb_cbc(cname, ksched, cprefix, kstruct, \
-                         nid, block_size, key_len, iv_len, flags, \
-                         init_key, cleanup, set_asn1, get_asn1, ctrl) \
-BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
-BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
-BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
-                    init_key, cleanup, set_asn1, get_asn1, ctrl) \
-BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, 0, flags, \
-                    init_key, cleanup, set_asn1, get_asn1, ctrl)
-
-IMPLEMENT_BLOCK_CIPHER_def_ecb_cbc(aes_128, ks, AES, EVP_AES_KEY,
-                                  NID_aes_128, 16, 16, 16,
-                                  0, aes_init_key, NULL, 
-                                  EVP_CIPHER_set_asn1_iv,
-                                  EVP_CIPHER_get_asn1_iv,
-                                  NULL)
-IMPLEMENT_BLOCK_CIPHER_def_ecb_cbc(aes_192, ks, AES, EVP_AES_KEY,
-                                  NID_aes_192, 16, 24, 16,
-                                  0, aes_init_key, NULL, 
-                                  EVP_CIPHER_set_asn1_iv,
-                                  EVP_CIPHER_get_asn1_iv,
-                                  NULL)
-IMPLEMENT_BLOCK_CIPHER_def_ecb_cbc(aes_256, ks, AES, EVP_AES_KEY,
-                                  NID_aes_256, 16, 32, 16,
-                                  0, aes_init_key, NULL, 
-                                  EVP_CIPHER_set_asn1_iv,
-                                  EVP_CIPHER_get_asn1_iv,
-                                  NULL)
+IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
+                      NID_aes_128, 16, 16, 16, 128,
+                      0, aes_init_key, NULL, 
+                      EVP_CIPHER_set_asn1_iv,
+                      EVP_CIPHER_get_asn1_iv,
+                      NULL)
+IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
+                      NID_aes_192, 16, 24, 16, 128,
+                      0, aes_init_key, NULL, 
+                      EVP_CIPHER_set_asn1_iv,
+                      EVP_CIPHER_get_asn1_iv,
+                      NULL)
+IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
+                      NID_aes_256, 16, 32, 16, 128,
+                      0, aes_init_key, NULL, 
+                      EVP_CIPHER_set_asn1_iv,
+                      EVP_CIPHER_get_asn1_iv,
+                      NULL)
 
 static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                   const unsigned char *iv, int enc) {
 
-       if (enc) 
+       if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE
+           || (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE
+           || enc) 
                AES_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
        else
                AES_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);