Browse Source

[crypto] Allow in-place CBC decryption

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
09d45ffd79
1 changed files with 3 additions and 1 deletions
  1. 3
    1
      src/crypto/cbc.c

+ 3
- 1
src/crypto/cbc.c View File

@@ -88,13 +88,15 @@ void cbc_encrypt ( void *ctx, const void *src, void *dst, size_t len,
88 88
 void cbc_decrypt ( void *ctx, const void *src, void *dst, size_t len,
89 89
 		   struct cipher_algorithm *raw_cipher, void *cbc_ctx ) {
90 90
 	size_t blocksize = raw_cipher->blocksize;
91
+	uint8_t next_cbc_ctx[blocksize];
91 92
 
92 93
 	assert ( ( len % blocksize ) == 0 );
93 94
 
94 95
 	while ( len ) {
96
+		memcpy ( next_cbc_ctx, src, blocksize );
95 97
 		cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
96 98
 		cbc_xor ( cbc_ctx, dst, blocksize );
97
-		memcpy ( cbc_ctx, src, blocksize );
99
+		memcpy ( cbc_ctx, next_cbc_ctx, blocksize );
98 100
 		dst += blocksize;
99 101
 		src += blocksize;
100 102
 		len -= blocksize;

Loading…
Cancel
Save