oops, reinstate correct prototype
[openssl.git] / crypto / engine / eng_aesni.c
index 67074186149afaa7a484a1e1153eab8cd8d323c7..2a997cae36dc0cf1daf44901d200af0bc2ff3f27 100644 (file)
 #if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_AES_NI) && !defined(OPENSSL_NO_AES)
 
 #include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <openssl/crypto.h>
+#include "cryptlib.h"
 #include <openssl/dso.h>
 #include <openssl/engine.h>
 #include <openssl/evp.h>
 #include <openssl/aes.h>
 #include <openssl/err.h>
-#include <cryptlib.h>
 #include <openssl/modes.h>
 
 /* AES-NI is available *ONLY* on some x86 CPUs.  Not only that it
@@ -114,9 +111,9 @@ void ENGINE_load_aesni (void)
 }
 
 #ifdef COMPILE_HW_AESNI
-int aesni_set_encrypt_key(const unsigned char *userKey, const int bits,
+int aesni_set_encrypt_key(const unsigned char *userKey, int bits,
                              AES_KEY *key);
-int aesni_set_decrypt_key(const unsigned char *userKey, const int bits,
+int aesni_set_decrypt_key(const unsigned char *userKey, int bits,
                              AES_KEY *key);
 
 void aesni_encrypt(const unsigned char *in, unsigned char *out,
@@ -126,14 +123,14 @@ void aesni_decrypt(const unsigned char *in, unsigned char *out,
 
 void aesni_ecb_encrypt(const unsigned char *in,
                           unsigned char *out,
-                          const unsigned long length,
+                          size_t length,
                           const AES_KEY *key,
-                          const int enc);
+                          int enc);
 void aesni_cbc_encrypt(const unsigned char *in,
                           unsigned char *out,
-                          const unsigned long length,
+                          size_t length,
                           const AES_KEY *key,
-                          unsigned char *ivec, const int enc);
+                          unsigned char *ivec, int enc);
 
 /* Function for ENGINE detection and control */
 static int aesni_init(ENGINE *e);
@@ -147,8 +144,9 @@ static int aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
        ((void *)(((unsigned long)(x)+AESNI_MIN_ALIGN-1)&~(AESNI_MIN_ALIGN-1)))
 
 /* Engine names */
-static const char *aesni_id = "aesni";
-static const char *aesni_name = "Intel AES-NI engine";
+static const char   aesni_id[] = "aesni",
+                   aesni_name[] = "Intel AES-NI engine",
+                   no_aesni_name[] = "Intel AES-NI engine (no-aesni)";
 
 /* ===== Engine "management" functions ===== */
 
@@ -156,15 +154,15 @@ static const char *aesni_name = "Intel AES-NI engine";
 static int
 aesni_bind_helper(ENGINE *e)
 {
-       if (!(OPENSSL_ia32cap_P[1] & (1UL << (57-32))))
-               return 0;
+       int engage = (OPENSSL_ia32cap_P[1] & (1 << (57-32))) != 0;
 
        /* Register everything or return with an error */
        if (!ENGINE_set_id(e, aesni_id) ||
-           !ENGINE_set_name(e, aesni_name) ||
+           !ENGINE_set_name(e, engage ? aesni_name : no_aesni_name) ||
 
            !ENGINE_set_init_function(e, aesni_init) ||
-           !ENGINE_set_ciphers (e, aesni_ciphers))
+           (engage && !ENGINE_set_ciphers (e, aesni_ciphers))
+           )
                return 0;
 
        /* Everything looks good */
@@ -247,7 +245,7 @@ typedef struct
 } AESNI_KEY;
 
 static int
-aesni_init_key (EVP_CIPHER_CTX *ctx, const unsigned char *user_key,
+aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *user_key,
                    const unsigned char *iv, int enc)
 {
        int ret;
@@ -261,7 +259,7 @@ aesni_init_key (EVP_CIPHER_CTX *ctx, const unsigned char *user_key,
                ret=aesni_set_decrypt_key(user_key, ctx->key_len * 8, key);
 
        if(ret < 0) {
-               EVPerr(EVP_F_AES_INIT_KEY,EVP_R_AES_KEY_SETUP_FAILED);
+               EVPerr(EVP_F_AESNI_INIT_KEY,EVP_R_AES_KEY_SETUP_FAILED);
                return 0;
        }
 
@@ -286,14 +284,14 @@ static int aesni_cipher_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
 {      AES_KEY *key = AESNI_ALIGN(ctx->cipher_data);
        CRYPTO_cfb128_encrypt(in, out, inl, key, ctx->iv,
                                &ctx->num, ctx->encrypt,
-                               aesni_encrypt);
+                               (block128_f)aesni_encrypt);
        return 1;
 }
 static int aesni_cipher_ofb(EVP_CIPHER_CTX *ctx, unsigned char *out,
                 const unsigned char *in, size_t inl)
 {      AES_KEY *key = AESNI_ALIGN(ctx->cipher_data);
        CRYPTO_ofb128_encrypt(in, out, inl, key, ctx->iv,
-                               &ctx->num, aesni_encrypt);
+                               &ctx->num, (block128_f)aesni_encrypt);
        return 1;
 }