Skip to content

Commit

Permalink
[crypto] Allow in-place CBC decryption
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Sep 27, 2012
1 parent c1adf7d commit 09d45ff
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/crypto/cbc.c
Expand Up @@ -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;
Expand Down

0 comments on commit 09d45ff

Please sign in to comment.