@@ -194,47 +194,11 @@ char const* cfs_algorithm()
194
194
195
195
#endif
196
196
197
-
198
- static void cfs_rc4_encrypt_block (void * block , uint32 offs , uint32 block_size ) // AALEKSEEV TODO: DELETE THIS
199
- {
200
- uint32 i ;
201
- uint8 temp ;
202
- uint8 * dst = (uint8 * )block ;
203
- int next_state ;
204
- uint8 state [CFS_CIPHER_KEY_SIZE ];
205
- int x = 0 , y = 0 ;
206
- uint32 skip = (offs / BLCKSZ + block_size ) % CFS_CIPHER_KEY_SIZE ;
207
-
208
- memcpy (state , cfs_state -> rc4_init_state , CFS_CIPHER_KEY_SIZE );
209
- for (i = 0 ; i < skip ; i ++ ) {
210
- x = (x + 1 ) % CFS_CIPHER_KEY_SIZE ;
211
- y = (y + state [x ]) % CFS_CIPHER_KEY_SIZE ;
212
- temp = state [x ];
213
- state [x ] = state [y ];
214
- state [y ] = temp ;
215
- }
216
- for (i = 0 ; i < block_size ; i ++ ) {
217
- x = (x + 1 ) % CFS_CIPHER_KEY_SIZE ;
218
- y = (y + state [x ]) % CFS_CIPHER_KEY_SIZE ;
219
- temp = state [x ];
220
- state [x ] = state [y ];
221
- state [y ] = temp ;
222
- next_state = (state [x ] + state [y ]) % CFS_CIPHER_KEY_SIZE ;
223
- dst [i ] ^= state [next_state ];
224
- }
225
- }
226
-
227
197
static void cfs_crypto_init (void )
228
198
{
229
- int index1 = 0 ;
230
- int index2 = 0 ;
231
- int i ;
232
- uint8 temp ;
233
199
int key_length ;
234
- int x = 0 , y = 0 ;
235
200
char * cipher_key ;
236
201
uint8 aes_key [32 ] = {0 }; /* at most 256 bits */
237
- uint8 * rc4_init_state = cfs_state -> rc4_init_state ;
238
202
239
203
cipher_key = getenv ("PG_CIPHER_KEY" );
240
204
if (cipher_key == NULL ) {
@@ -243,26 +207,6 @@ static void cfs_crypto_init(void)
243
207
unsetenv ("PG_CIPHER_KEY" ); /* make it not possible to inspect this environment variable through plperl */
244
208
key_length = strlen (cipher_key );
245
209
246
- ////// AALEKSEEV TODO GET RID OF THIS
247
- for (i = 0 ; i < CFS_CIPHER_KEY_SIZE ; ++ i ) {
248
- rc4_init_state [i ] = (uint8 )i ;
249
- }
250
- for (i = 0 ; i < CFS_CIPHER_KEY_SIZE ; ++ i ) {
251
- index2 = (cipher_key [index1 ] + rc4_init_state [i ] + index2 ) % CFS_CIPHER_KEY_SIZE ;
252
- temp = rc4_init_state [i ];
253
- rc4_init_state [i ] = rc4_init_state [index2 ];
254
- rc4_init_state [index2 ] = temp ;
255
- index1 = (index1 + 1 ) % key_length ;
256
- }
257
- for (i = 0 ; i < CFS_RC4_DROP_N ; i ++ ) {
258
- x = (x + 1 ) % CFS_CIPHER_KEY_SIZE ;
259
- y = (y + rc4_init_state [x ]) % CFS_CIPHER_KEY_SIZE ;
260
- temp = rc4_init_state [x ];
261
- rc4_init_state [x ] = rc4_init_state [y ];
262
- rc4_init_state [y ] = temp ;
263
- }
264
- //////
265
-
266
210
memcpy (& aes_key , cipher_key , key_length > sizeof (aes_key ) ? sizeof (aes_key ) : key_length );
267
211
rijndael_set_key (
268
212
& cfs_state -> aes_context , /* context */
@@ -321,11 +265,11 @@ static int extract_fname_parts(const char* fname, uint32* part1, uint32* part2,
321
265
/* Encryption and decryption using AES in CTR mode */
322
266
static void cfs_aes_crypt_block (const char * fname , void * block , uint32 offs , uint32 size )
323
267
{
324
- #define AES_DEBUG 1
268
+ #define AES_DEBUG 1 // AALEKSEEV TODO: 0
325
269
uint32 aes_in [4 ]; /* 16 bytes, 128 bits */
326
270
uint32 aes_out [4 ];
327
271
uint8 * plaintext = (uint8 * )block ;
328
- uint8 * pgamma = (uint8 * )& aes_out ;
272
+ uint8 * gamma = (uint8 * )& aes_out ;
329
273
uint32 i , fname_part1 , fname_part2 , fname_part3 ;
330
274
331
275
if (extract_fname_parts (fname , & fname_part1 , & fname_part2 , & fname_part3 ) < 0 )
@@ -350,7 +294,7 @@ static void cfs_aes_crypt_block(const char* fname, void* block, uint32 offs, uin
350
294
351
295
for (i = 0 ; i < size ; i ++ )
352
296
{
353
- plaintext [i ] ^= pgamma [offs & 0xF ];
297
+ plaintext [i ] ^= gamma [offs & 0xF ];
354
298
offs ++ ;
355
299
if ((offs & 0xF ) == 0 )
356
300
{
@@ -371,7 +315,6 @@ void cfs_encrypt(const char* fname, void* block, uint32 offs, uint32 size)
371
315
{
372
316
if (cfs_encryption )
373
317
{
374
- cfs_rc4_encrypt_block (block , offs , size ); // AALEKSEEV TODO DELETE
375
318
cfs_aes_crypt_block (fname , block , offs , size );
376
319
}
377
320
}
@@ -380,7 +323,6 @@ void cfs_decrypt(const char* fname, void* block, uint32 offs, uint32 size)
380
323
{
381
324
if (cfs_encryption )
382
325
{
383
- cfs_rc4_encrypt_block (block , offs , size ); // AALEKSEEV TODO DELETE
384
326
cfs_aes_crypt_block (fname , block , offs , size );
385
327
}
386
328
}
0 commit comments