Pārlūkot izejas kodu

[crypto] Allow in-place CBC decryption

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 gadus atpakaļ
vecāks
revīzija
09d45ffd79
1 mainītis faili ar 3 papildinājumiem un 1 dzēšanām
  1. 3
    1
      src/crypto/cbc.c

+ 3
- 1
src/crypto/cbc.c Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt