Engage AES for UltraSPARC in sparcv9 targets.
[openssl.git] / crypto / aes / aes_cbc.c
index 41d538f..d2ba6bc 100644 (file)
@@ -65,7 +65,8 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
 
        unsigned long n;
        unsigned long len = length;
 
        unsigned long n;
        unsigned long len = length;
-       unsigned char tmp[AES_BLOCK_SIZE], *iv = ivec;
+       unsigned char tmp[AES_BLOCK_SIZE];
+       const unsigned char *iv = ivec;
 
        assert(in && out && key && ivec);
        assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
 
        assert(in && out && key && ivec);
        assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
@@ -87,7 +88,7 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
                                out[n] = iv[n];
                        AES_encrypt(out, out, key);
                        iv = out;
                                out[n] = iv[n];
                        AES_encrypt(out, out, key);
                        iv = out;
-               }                       
+               }
                memcpy(ivec,iv,AES_BLOCK_SIZE);
        } else if (in != out) {
                while (len >= AES_BLOCK_SIZE) {
                memcpy(ivec,iv,AES_BLOCK_SIZE);
        } else if (in != out) {
                while (len >= AES_BLOCK_SIZE) {
@@ -119,10 +120,12 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
                }
                if (len) {
                        memcpy(tmp, in, AES_BLOCK_SIZE);
                }
                if (len) {
                        memcpy(tmp, in, AES_BLOCK_SIZE);
-                       AES_decrypt(tmp, tmp, key);
+                       AES_decrypt(tmp, out, key);
                        for(n=0; n < len; ++n)
                        for(n=0; n < len; ++n)
-                               out[n] = tmp[n] ^ ivec[n];
+                               out[n] ^= ivec[n];
+                       for(n=len; n < AES_BLOCK_SIZE; ++n)
+                               out[n] = tmp[n];
                        memcpy(ivec, tmp, AES_BLOCK_SIZE);
                        memcpy(ivec, tmp, AES_BLOCK_SIZE);
-               }                       
+               }
        }
 }
        }
 }