Usage for -hack and -prexit -verify_return_error
[openssl.git] / crypto / camellia / cmll_cbc.c
index 421c33127bd574d638b3a47f53050bf7187170b3..4c8d455adef3d90d2d03c068b76980782dd90aab 100644 (file)
  *
  */
 
-#ifndef CAMELLIA_DEBUG
-# ifndef NDEBUG
-#  define NDEBUG
-# endif
-#endif
-#include <assert.h>
-#include <string.h>
-
 #include <openssl/camellia.h>
-#include "cmll_locl.h"
+#include <openssl/modes.h>
+
 void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
        size_t len, const CAMELLIA_KEY *key,
        unsigned char *ivec, const int enc) 
        {
 
-       size_t n;
-       unsigned char tmp[CAMELLIA_BLOCK_SIZE];
-       const unsigned char *iv = ivec;
-
-       assert(in && out && key && ivec);
-       assert((CAMELLIA_ENCRYPT == enc)||(CAMELLIA_DECRYPT == enc));
-
-       if (CAMELLIA_ENCRYPT == enc) 
-               {
-               while (len >= CAMELLIA_BLOCK_SIZE) 
-                       {
-                       for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
-                               out[n] = in[n] ^ iv[n];
-                       Camellia_encrypt(out, out, key);
-                       iv = out;
-                       len -= CAMELLIA_BLOCK_SIZE;
-                       in += CAMELLIA_BLOCK_SIZE;
-                       out += CAMELLIA_BLOCK_SIZE;
-                       }
-               if (len) 
-                       {
-                       for(n=0; n < len; ++n)
-                               out[n] = in[n] ^ iv[n];
-                       for(n=len; n < CAMELLIA_BLOCK_SIZE; ++n)
-                               out[n] = iv[n];
-                       Camellia_encrypt(out, out, key);
-                       iv = out;
-                       }
-               memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
-               } 
-       else if (in != out) 
-               {
-               while (len >= CAMELLIA_BLOCK_SIZE) 
-                       {
-                       Camellia_decrypt(in, out, key);
-                       for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
-                               out[n] ^= iv[n];
-                       iv = in;
-                       len -= CAMELLIA_BLOCK_SIZE;
-                       in  += CAMELLIA_BLOCK_SIZE;
-                       out += CAMELLIA_BLOCK_SIZE;
-                       }
-               if (len) 
-                       {
-                       Camellia_decrypt(in,tmp,key);
-                       for(n=0; n < len; ++n)
-                               out[n] = tmp[n] ^ iv[n];
-                       iv = in;
-                       }
-               memcpy(ivec,iv,CAMELLIA_BLOCK_SIZE);
-               } 
-       else 
-               {
-               while (len >= CAMELLIA_BLOCK_SIZE) 
-                       {
-                       memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
-                       Camellia_decrypt(in, out, key);
-                       for(n=0; n < CAMELLIA_BLOCK_SIZE; ++n)
-                               out[n] ^= ivec[n];
-                       memcpy(ivec, tmp, CAMELLIA_BLOCK_SIZE);
-                       len -= CAMELLIA_BLOCK_SIZE;
-                       in += CAMELLIA_BLOCK_SIZE;
-                       out += CAMELLIA_BLOCK_SIZE;
-                       }
-               if (len)
-                       {
-                       memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
-                       Camellia_decrypt(tmp, out, key);
-                       for(n=0; n < len; ++n)
-                               out[n] ^= ivec[n];
-                       for(n=len; n < CAMELLIA_BLOCK_SIZE; ++n)
-                               out[n] = tmp[n];
-                       memcpy(ivec, tmp, CAMELLIA_BLOCK_SIZE);
-                       }
-               }
+       if (enc)
+               CRYPTO_cbc128_encrypt(in,out,len,key,ivec,(block128_f)Camellia_encrypt);
+       else
+               CRYPTO_cbc128_decrypt(in,out,len,key,ivec,(block128_f)Camellia_decrypt);
        }