]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[crypto] Allow in-place CBC decryption
authorMichael Brown <mcb30@ipxe.org>
Thu, 27 Sep 2012 00:37:06 +0000 (01:37 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 27 Sep 2012 00:54:55 +0000 (01:54 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/cbc.c

index 28d38b2dbf249c8e1b8a0b359240edef6291d4f4..9bf0e8b49cb1bd53c4fff68727bd4e16e516837b 100644 (file)
@@ -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;