Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PG-980: Using proper IV with tde_heap (full) #276

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/smgr/pg_tde_smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

#ifdef PERCONA_EXT

// TODO: implement proper IV
// iv should be based on blocknum + relfile, available in the API
static unsigned char iv[16] = {0,};

static RelKeyData*
tde_smgr_get_key(SMgrRelation reln)
{
Expand Down Expand Up @@ -98,6 +94,11 @@ tde_mdwritev(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
{
int out_len = BLCKSZ;
local_buffers[i] = &local_blocks_aligned[i * BLCKSZ];

BlockNumber bn = blocknum + i;
unsigned char iv[16] = {0,}
memcpy(iv+4, &bn, sizeof(BlockNumber));
dAdAbird marked this conversation as resolved.
Show resolved Hide resolved

AesEncrypt(rkd->internal_key.key, iv, ((char**)buffers)[i], BLCKSZ, local_buffers[i], &out_len);
}

Expand Down Expand Up @@ -131,6 +132,10 @@ tde_mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
char *local_blocks = palloc(BLCKSZ * (1 + 1));
char *local_blocks_aligned = (char *)TYPEALIGN(PG_IO_ALIGN_SIZE, local_blocks);
int out_len = BLCKSZ;

unsigned char iv[16] = {0,}
memcpy(iv+4, &blocknum, sizeof(BlockNumber));

AesEncrypt(rkd->internal_key.key, iv, ((char*)buffer), BLCKSZ, local_blocks_aligned, &out_len);

mdextend(reln, forknum, blocknum, local_blocks_aligned, skipFsync);
Expand Down Expand Up @@ -173,6 +178,11 @@ tde_mdreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
}
if(allZero)
continue;

BlockNumber bn = blocknum + i;
unsigned char iv[16] = {0,}
memcpy(iv+4, &bn, sizeof(BlockNumber));

AesDecrypt(rkd->internal_key.key, iv, ((char **)buffers)[i], BLCKSZ, ((char **)buffers)[i], &out_len);
}
}
Expand Down
Loading