Skip to content

Commit f3329a8

Browse files
committed
fix
1 parent fdb514f commit f3329a8

File tree

1 file changed

+25
-2
lines changed
  • src/backend/storage/file

1 file changed

+25
-2
lines changed

src/backend/storage/file/cfs.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static void cfs_crypto_init(void)
276276
* For a file name like 'path/to/16384/16401[.123]' return part1 = 16384, part2 = 16401 and part3 = 123.
277277
* Returns 0 on success and negative value on error.
278278
*/
279-
static int extract_fname_parts(const char* fname, unsigned int* part1, unsigned int* part2, unsigned int* part3)
279+
static int extract_fname_parts(const char* fname, uint32* part1, uint32* part2, uint32* part3)
280280
{
281281
int idx = strlen(fname);
282282
if(idx == 0)
@@ -321,13 +321,36 @@ static int extract_fname_parts(const char* fname, unsigned int* part1, unsigned
321321
/* Encryption and decryption using AES in CTR mode */
322322
static void cfs_aes_crypt_block(const char* fname, void* block, uint32 offs, uint32 size)
323323
{
324-
unsigned int fname_part1, fname_part2, fname_part3;
324+
uint32 aes_in[4]; /* 16 bytes, 128 bits */
325+
uint32 aes_out[4];
326+
uint8* plaintext = (uint8*)block;
327+
uint8* pgamma = (uint8*)&aes_out;
328+
uint32 i, fname_part1, fname_part2, fname_part3;
329+
325330
if(extract_fname_parts(fname, &fname_part1, &fname_part2, &fname_part3) < 0)
326331
fname_part1 = fname_part2 = fname_part3 = 0;
327332

333+
// AALEKSEEV TODO MAKE DEBUG4
328334
elog(LOG, "cfs_aes_crypt_block, fname = %s, part1 = %d, part2 = %d, part3 = %d, offs = %d, size = %d",
329335
fname, fname_part1, fname_part2, fname_part3, offs, size);
330336

337+
aes_in[0] = fname_part1;
338+
aes_in[1] = fname_part2;
339+
aes_in[2] = fname_part3;
340+
aes_in[3] = offs & 0xFFFFFFF0;
341+
rijndael_encrypt(&cfs_state->aes_context, (u4byte*)&aes_in, (u4byte*)&aes_out);
342+
343+
for(i = 0; i < size; i++)
344+
{
345+
plaintext[i] ^= aes_out[offs & 0xF];
346+
offs++;
347+
if((offs & 0xF) == 0)
348+
{
349+
/* Prepare next gamma part */
350+
aes_in[3] = offs;
351+
rijndael_encrypt(&cfs_state->aes_context, (u4byte*)&aes_in, (u4byte*)&aes_out);
352+
}
353+
}
331354
}
332355

333356
void cfs_encrypt(const char* fname, void* block, uint32 offs, uint32 size)

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