/* 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);
}