From: Michael Brown Date: Thu, 27 Sep 2012 00:37:06 +0000 (+0100) Subject: [crypto] Allow in-place CBC decryption X-Git-Tag: v1.20.1~1639 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09d45ffd7991e6b64a76d86f338a2f0973527be6;p=thirdparty%2Fipxe.git [crypto] Allow in-place CBC decryption Signed-off-by: Michael Brown --- diff --git a/src/crypto/cbc.c b/src/crypto/cbc.c index 28d38b2db..9bf0e8b49 100644 --- a/src/crypto/cbc.c +++ b/src/crypto/cbc.c @@ -88,13 +88,15 @@ void cbc_encrypt ( void *ctx, const void *src, void *dst, size_t len, void cbc_decrypt ( void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher, void *cbc_ctx ) { size_t blocksize = raw_cipher->blocksize; + uint8_t next_cbc_ctx[blocksize]; assert ( ( len % blocksize ) == 0 ); while ( len ) { + memcpy ( next_cbc_ctx, src, blocksize ); cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize ); cbc_xor ( cbc_ctx, dst, blocksize ); - memcpy ( cbc_ctx, src, blocksize ); + memcpy ( cbc_ctx, next_cbc_ctx, blocksize ); dst += blocksize; src += blocksize; len -= blocksize;