From b2bb77c0eff3b6e9da3c2cd71a1d5265afc8819f Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Sat, 9 Aug 2025 18:18:33 +0200 Subject: [PATCH] Move common things for key files into a separate header file Instead of having the WAL key code include the headers for the SMGR keys we move the shared code into a separate header file. Additionally we clean up some minor header issues. --- contrib/pg_tde/src/access/pg_tde_tdemap.c | 1 + contrib/pg_tde/src/access/pg_tde_xlog_keys.c | 2 +- .../src/include/access/pg_tde_keys_common.h | 19 +++++++++++++++++++ .../pg_tde/src/include/access/pg_tde_tdemap.h | 16 +--------------- .../src/include/access/pg_tde_xlog_keys.h | 3 +-- 5 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 contrib/pg_tde/src/include/access/pg_tde_keys_common.h diff --git a/contrib/pg_tde/src/access/pg_tde_tdemap.c b/contrib/pg_tde/src/access/pg_tde_tdemap.c index 7f22120e45c..41984704f15 100644 --- a/contrib/pg_tde/src/access/pg_tde_tdemap.c +++ b/contrib/pg_tde/src/access/pg_tde_tdemap.c @@ -17,6 +17,7 @@ #include "access/pg_tde_xlog.h" #include "catalog/tde_global_space.h" #include "catalog/tde_principal_key.h" +#include "common/pg_tde_utils.h" #include "encryption/enc_aes.h" #include "encryption/enc_tde.h" #include "keyring/keyring_api.h" diff --git a/contrib/pg_tde/src/access/pg_tde_xlog_keys.c b/contrib/pg_tde/src/access/pg_tde_xlog_keys.c index 004d9bc99fa..460fced8026 100644 --- a/contrib/pg_tde/src/access/pg_tde_xlog_keys.c +++ b/contrib/pg_tde/src/access/pg_tde_xlog_keys.c @@ -9,11 +9,11 @@ #include "storage/fd.h" #include "utils/memutils.h" -#include "access/pg_tde_tdemap.h" #include "access/pg_tde_xlog_keys.h" #include "access/pg_tde_xlog.h" #include "catalog/tde_global_space.h" #include "catalog/tde_principal_key.h" +#include "common/pg_tde_utils.h" #include "encryption/enc_aes.h" #include "encryption/enc_tde.h" diff --git a/contrib/pg_tde/src/include/access/pg_tde_keys_common.h b/contrib/pg_tde/src/include/access/pg_tde_keys_common.h new file mode 100644 index 00000000000..91554f84474 --- /dev/null +++ b/contrib/pg_tde/src/include/access/pg_tde_keys_common.h @@ -0,0 +1,19 @@ +#ifndef PG_TDE_KEYS_COMMON_H +#define PG_TDE_KEYS_COMMON_H + +#include "catalog/tde_principal_key.h" + +#define INTERNAL_KEY_LEN 16 +#define INTERNAL_KEY_IV_LEN 16 + +#define MAP_ENTRY_IV_SIZE 16 +#define MAP_ENTRY_AEAD_TAG_SIZE 16 + +typedef struct +{ + TDEPrincipalKeyInfo data; + unsigned char sign_iv[MAP_ENTRY_IV_SIZE]; + unsigned char aead_tag[MAP_ENTRY_AEAD_TAG_SIZE]; +} TDESignedPrincipalKeyInfo; + +#endif /* PG_TDE_KEYS_COMMON_H */ diff --git a/contrib/pg_tde/src/include/access/pg_tde_tdemap.h b/contrib/pg_tde/src/include/access/pg_tde_tdemap.h index bd7d53fbcb1..241d0e7f732 100644 --- a/contrib/pg_tde/src/include/access/pg_tde_tdemap.h +++ b/contrib/pg_tde/src/include/access/pg_tde_tdemap.h @@ -1,13 +1,9 @@ #ifndef PG_TDE_MAP_H #define PG_TDE_MAP_H -#include "access/xlog_internal.h" #include "storage/relfilelocator.h" -#include "catalog/tde_principal_key.h" -#include "common/pg_tde_utils.h" -#define INTERNAL_KEY_LEN 16 -#define INTERNAL_KEY_IV_LEN 16 +#include "access/pg_tde_keys_common.h" typedef struct InternalKey { @@ -15,16 +11,6 @@ typedef struct InternalKey uint8 base_iv[INTERNAL_KEY_IV_LEN]; } InternalKey; -#define MAP_ENTRY_IV_SIZE 16 -#define MAP_ENTRY_AEAD_TAG_SIZE 16 - -typedef struct -{ - TDEPrincipalKeyInfo data; - unsigned char sign_iv[MAP_ENTRY_IV_SIZE]; - unsigned char aead_tag[MAP_ENTRY_AEAD_TAG_SIZE]; -} TDESignedPrincipalKeyInfo; - extern void pg_tde_save_smgr_key(RelFileLocator rel, const InternalKey *key); extern bool pg_tde_has_smgr_key(RelFileLocator rel); extern InternalKey *pg_tde_get_smgr_key(RelFileLocator rel); diff --git a/contrib/pg_tde/src/include/access/pg_tde_xlog_keys.h b/contrib/pg_tde/src/include/access/pg_tde_xlog_keys.h index b0fedb3bf8a..e36e7e59a85 100644 --- a/contrib/pg_tde/src/include/access/pg_tde_xlog_keys.h +++ b/contrib/pg_tde/src/include/access/pg_tde_xlog_keys.h @@ -3,8 +3,7 @@ #include "access/xlog_internal.h" -#include "access/pg_tde_tdemap.h" -#include "catalog/tde_principal_key.h" +#include "access/pg_tde_keys_common.h" typedef enum {