@@ -321,34 +321,50 @@ static int extract_fname_parts(const char* fname, uint32* part1, uint32* part2,
321
321
/* Encryption and decryption using AES in CTR mode */
322
322
static void cfs_aes_crypt_block (const char * fname , void * block , uint32 offs , uint32 size )
323
323
{
324
+ #define AES_DEBUG 1
324
325
uint32 aes_in [4 ]; /* 16 bytes, 128 bits */
325
326
uint32 aes_out [4 ];
326
327
uint8 * plaintext = (uint8 * )block ;
327
328
uint8 * pgamma = (uint8 * )& aes_out ;
329
+ rijndael_ctx temp_ctx = cfs_state -> aes_context ;
328
330
uint32 i , fname_part1 , fname_part2 , fname_part3 ;
329
331
330
332
if (extract_fname_parts (fname , & fname_part1 , & fname_part2 , & fname_part3 ) < 0 )
331
333
fname_part1 = fname_part2 = fname_part3 = 0 ;
332
334
333
- // AALEKSEEV TODO MAKE DEBUG4
335
+ #ifdef AES_DEBUG
334
336
elog (LOG , "cfs_aes_crypt_block, fname = %s, part1 = %d, part2 = %d, part3 = %d, offs = %d, size = %d" ,
335
337
fname , fname_part1 , fname_part2 , fname_part3 , offs , size );
338
+ #endif
336
339
337
- aes_in [0 ] = fname_part1 ;
338
- aes_in [1 ] = fname_part2 ;
339
- aes_in [2 ] = fname_part3 ;
340
+ aes_in [0 ] = 0 ; // fname_part1;
341
+ aes_in [1 ] = 0 ; // fname_part2;
342
+ aes_in [2 ] = 0 ; // fname_part3;
340
343
aes_in [3 ] = offs & 0xFFFFFFF0 ;
341
- rijndael_encrypt (& cfs_state -> aes_context , (u4byte * )& aes_in , (u4byte * )& aes_out );
344
+ rijndael_encrypt (& temp_ctx , (u4byte * )& aes_in , (u4byte * )& aes_out );
345
+
346
+ #ifdef AES_DEBUG
347
+ elog (LOG , "cfs_aes_crypt_block, in = %08X %08X %08X %08X, out = %08X %08X %08X %08X" ,
348
+ aes_in [0 ], aes_in [1 ], aes_in [2 ], aes_in [3 ],
349
+ aes_out [0 ], aes_out [1 ], aes_out [2 ], aes_out [3 ]);
350
+ #endif
342
351
343
352
for (i = 0 ; i < size ; i ++ )
344
353
{
345
- plaintext [i ] ^= aes_out [offs & 0xF ];
354
+ plaintext [i ] ^= pgamma [offs & 0xF ];
346
355
offs ++ ;
347
356
if ((offs & 0xF ) == 0 )
348
357
{
349
358
/* Prepare next gamma part */
350
359
aes_in [3 ] = offs ;
351
- rijndael_encrypt (& cfs_state -> aes_context , (u4byte * )& aes_in , (u4byte * )& aes_out );
360
+ temp_ctx = cfs_state -> aes_context ;
361
+ rijndael_encrypt (& temp_ctx , (u4byte * )& aes_in , (u4byte * )& aes_out );
362
+
363
+ #ifdef AES_DEBUG
364
+ elog (LOG , "cfs_aes_crypt_block, in = %08X %08X %08X %08X, out = %08X %08X %08X %08X" ,
365
+ aes_in [0 ], aes_in [1 ], aes_in [2 ], aes_in [3 ],
366
+ aes_out [0 ], aes_out [1 ], aes_out [2 ], aes_out [3 ]);
367
+ #endif
352
368
}
353
369
}
354
370
}
0 commit comments