Non-executable stack in asm.
[openssl.git] / crypto / aes / aes_ige.c
index aeb11db..c161351 100644 (file)
@@ -59,12 +59,14 @@ typedef struct {
         unsigned long data[N_WORDS];
 } aes_block_t;
 
-// XXX: probably some better way to do this
+/* XXX: probably some better way to do this */
 #if defined(__i386__) || defined(__x86_64__)
 #define UNALIGNED_MEMOPS_ARE_FAST 1
+#else
+#define UNALIGNED_MEMOPS_ARE_FAST 0
 #endif
 
-#ifdef UNALIGNED_MEMOPS_ARE_FAST
+#if UNALIGNED_MEMOPS_ARE_FAST
 #define load_block(d, s)        (d) = *(const aes_block_t *)(s)
 #define store_block(d, s)       *(aes_block_t *)(d) = (s)
 #else
@@ -75,11 +77,11 @@ typedef struct {
 /* N.B. The IV for this mode is _twice_ the block size */
 
 void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
-                                        const unsigned long length, const AES_KEY *key,
+                                        size_t length, const AES_KEY *key,
                                         unsigned char *ivec, const int enc)
        {
-       unsigned long n;
-       unsigned long len;
+       size_t n;
+       size_t len = length;
 
        OPENSSL_assert(in && out && key && ivec);
        OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
@@ -89,7 +91,8 @@ void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
 
        if (AES_ENCRYPT == enc)
                {
-               if (in != out)
+               if (in != out &&
+                   (UNALIGNED_MEMOPS_ARE_FAST || ((size_t)in|(size_t)out|(size_t)ivec)%sizeof(long)==0))
                        {
                        aes_block_t *ivp = (aes_block_t *)ivec;
                        aes_block_t *iv2p = (aes_block_t *)(ivec + AES_BLOCK_SIZE);
@@ -143,7 +146,8 @@ void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
                }
        else
                {
-               if(in != out)
+               if (in != out &&
+                   (UNALIGNED_MEMOPS_ARE_FAST || ((size_t)in|(size_t)out|(size_t)ivec)%sizeof(long)==0))
                        {
                        aes_block_t *ivp = (aes_block_t *)ivec;
                        aes_block_t *iv2p = (aes_block_t *)(ivec + AES_BLOCK_SIZE);
@@ -207,12 +211,12 @@ void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
 /* N.B. The IV for this mode is _four times_ the block size */
 
 void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
-                                               const unsigned long length, const AES_KEY *key,
+                                               size_t length, const AES_KEY *key,
                                                const AES_KEY *key2, const unsigned char *ivec,
                                                const int enc)
        {
-       unsigned long n;
-       unsigned long len = length;
+       size_t n;
+       size_t len = length;
        unsigned char tmp[AES_BLOCK_SIZE];
        unsigned char tmp2[AES_BLOCK_SIZE];
        unsigned char tmp3[AES_BLOCK_SIZE];