X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Faes%2Faes_cbc.c;h=d2ba6bcdb4659d1ed9c6a01a898b08e167e0f2ef;hb=90cc40911b031d9ae4597fd2b66c6fd24de2f9d9;hp=e43135e8a022440dd10d58bae06147f40992f515;hpb=131e064e4ae44288a5a84866deac2b19c88b7826;p=oweals%2Fopenssl.git diff --git a/crypto/aes/aes_cbc.c b/crypto/aes/aes_cbc.c index e43135e8a0..d2ba6bcdb4 100644 --- a/crypto/aes/aes_cbc.c +++ b/crypto/aes/aes_cbc.c @@ -65,7 +65,8 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, 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)); @@ -82,13 +83,12 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, } if (len) { for(n=0; n < len; ++n) - tmp[n] = in[n] ^ iv[n]; + out[n] = in[n] ^ iv[n]; for(n=len; n < AES_BLOCK_SIZE; ++n) - tmp[n] = iv[n]; - AES_encrypt(tmp, tmp, key); - memcpy(out, tmp, AES_BLOCK_SIZE); + 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) { @@ -120,10 +120,12 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, } if (len) { memcpy(tmp, in, AES_BLOCK_SIZE); - AES_decrypt(tmp, tmp, key); + AES_decrypt(tmp, out, key); 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); - } + } } }