Skip to content

Commit 1ba7cc9

Browse files
committed
fix
1 parent a5d7f9b commit 1ba7cc9

File tree

2 files changed

+3
-65
lines changed

2 files changed

+3
-65
lines changed

src/backend/storage/file/cfs.c

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -194,47 +194,11 @@ char const* cfs_algorithm()
194194

195195
#endif
196196

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-
227197
static void cfs_crypto_init(void)
228198
{
229-
int index1 = 0;
230-
int index2 = 0;
231-
int i;
232-
uint8 temp;
233199
int key_length;
234-
int x = 0, y = 0;
235200
char* cipher_key;
236201
uint8 aes_key[32] = {0}; /* at most 256 bits */
237-
uint8* rc4_init_state = cfs_state->rc4_init_state;
238202

239203
cipher_key = getenv("PG_CIPHER_KEY");
240204
if (cipher_key == NULL) {
@@ -243,26 +207,6 @@ static void cfs_crypto_init(void)
243207
unsetenv("PG_CIPHER_KEY"); /* make it not possible to inspect this environment variable through plperl */
244208
key_length = strlen(cipher_key);
245209

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-
266210
memcpy(&aes_key, cipher_key, key_length > sizeof(aes_key) ? sizeof(aes_key) : key_length);
267211
rijndael_set_key(
268212
&cfs_state->aes_context, /* context */
@@ -321,11 +265,11 @@ static int extract_fname_parts(const char* fname, uint32* part1, uint32* part2,
321265
/* Encryption and decryption using AES in CTR mode */
322266
static void cfs_aes_crypt_block(const char* fname, void* block, uint32 offs, uint32 size)
323267
{
324-
#define AES_DEBUG 1
268+
#define AES_DEBUG 1 // AALEKSEEV TODO: 0
325269
uint32 aes_in[4]; /* 16 bytes, 128 bits */
326270
uint32 aes_out[4];
327271
uint8* plaintext = (uint8*)block;
328-
uint8* pgamma = (uint8*)&aes_out;
272+
uint8* gamma = (uint8*)&aes_out;
329273
uint32 i, fname_part1, fname_part2, fname_part3;
330274

331275
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
350294

351295
for(i = 0; i < size; i++)
352296
{
353-
plaintext[i] ^= pgamma[offs & 0xF];
297+
plaintext[i] ^= gamma[offs & 0xF];
354298
offs++;
355299
if((offs & 0xF) == 0)
356300
{
@@ -371,7 +315,6 @@ void cfs_encrypt(const char* fname, void* block, uint32 offs, uint32 size)
371315
{
372316
if (cfs_encryption)
373317
{
374-
cfs_rc4_encrypt_block(block, offs, size); // AALEKSEEV TODO DELETE
375318
cfs_aes_crypt_block(fname, block, offs, size);
376319
}
377320
}
@@ -380,7 +323,6 @@ void cfs_decrypt(const char* fname, void* block, uint32 offs, uint32 size)
380323
{
381324
if (cfs_encryption)
382325
{
383-
cfs_rc4_encrypt_block(block, offs, size); // AALEKSEEV TODO DELETE
384326
cfs_aes_crypt_block(fname, block, offs, size);
385327
}
386328
}

src/include/storage/cfs.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
#define CFS_COMPRESSOR ZLIB_COMPRESSOR
3030
#endif
3131

32-
#define CFS_RC4_DROP_N 3072 // AALEKSEEV TODO GET RID OF THIS
33-
#define CFS_CIPHER_KEY_SIZE 256 // AALEKSEEV TODO GET RID OF THIS
34-
3532
typedef uint64 inode_t;
3633

3734
#define CFS_INODE_SIZE(inode) ((uint32)((inode) >> 32))
@@ -63,7 +60,6 @@ typedef struct
6360
int max_iterations;
6461
bool gc_enabled;
6562
CfsStatistic gc_stat;
66-
uint8 rc4_init_state[CFS_CIPHER_KEY_SIZE];
6763
rijndael_ctx aes_context;
6864
} CfsState;
6965

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy