Fix merge error
[openssl.git] / crypto / aes / aes_cbc.c
index 964a9780e4db459d5a97b21186b5096d1f89dd63..e39231f17cb8e4aed44053eeb37954d116d0039e 100644 (file)
@@ -1,13 +1,13 @@
 /* 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
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *
  */
 
-#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,
-                    unsigned char *ivec, const int enc) {
+                     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;
-               }
-       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;
-               }
+    if (enc)
+        CRYPTO_cbc128_encrypt(in, out, len, key, ivec,
+                              (block128_f) AES_encrypt);
+    else
+        CRYPTO_cbc128_decrypt(in, out, len, key, ivec,
+                              (block128_f) AES_decrypt);
 }