bsaes-armv7.pl: remove byte order dependency and minor optimization.
[openssl.git] / crypto / aes / aes_cbc.c
index 964a9780e4db459d5a97b21186b5096d1f89dd63..227f75625dba917eda4823f6533ff6c41abd437b 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/aes/aes_cbc.c -*- mode:C; c-file-style: "eay" -*- */
 /* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  */
 
-#include <assert.h>
 #include <openssl/aes.h>
-#include "aes_locl.h"
+#include <openssl/modes.h>
 
 void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
-                    const unsigned long length, const AES_KEY *key,
+                    size_t len, const AES_KEY *key,
                     unsigned char *ivec, const int enc) {
 
-       int n;
-       unsigned long len = length;
-       unsigned char tmp[16];
-
-       assert(in && out && key && ivec);
-       assert(length % AES_BLOCK_SIZE == 0);
-       assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
-
-       if (AES_ENCRYPT == enc)
-               while (len > 0) {
-                       for(n=0; n < 16; ++n)
-                               tmp[n] = in[n] ^ ivec[n];
-                       AES_encrypt(tmp, out, key);
-                       memcpy(ivec, out, 16);
-                       len -= 16;
-                       in += 16;
-                       out += 16;
-               }
+       if (enc)
+               CRYPTO_cbc128_encrypt(in,out,len,key,ivec,(block128_f)AES_encrypt);
        else
-               while (len > 0) {
-                       memcpy(tmp, in, 16);
-                       AES_decrypt(in, out, key);
-                       for(n=0; n < 16; ++n)
-                               out[n] ^= ivec[n];
-                       memcpy(ivec, tmp, 16);
-                       len -= 16;
-                       in += 16;
-                       out += 16;
-               }
+               CRYPTO_cbc128_decrypt(in,out,len,key,ivec,(block128_f)AES_decrypt);
 }