From 7f3f02dadf758a8fa81fcdb6ac9e82d4a13d0434 Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Wed, 1 May 2024 23:25:04 -0700 Subject: [PATCH] [common] Refactor Protected Files, part 1 This commit refactors PF code without changing functionality (part 1 in a series of commits). In particular, this commit removes unused functions, variables, fields, typedefs and macros. Signed-off-by: Dmitrii Kuvaiskii --- common/src/protected_files/protected_files.c | 8 -------- common/src/protected_files/protected_files.h | 15 --------------- .../src/protected_files/protected_files_format.h | 12 +++--------- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/common/src/protected_files/protected_files.c b/common/src/protected_files/protected_files.c index 40ad501c75..89f820a885 100644 --- a/common/src/protected_files/protected_files.c +++ b/common/src/protected_files/protected_files.c @@ -1356,11 +1356,3 @@ pf_status_t pf_flush(pf_context_t* pf) { return PF_STATUS_SUCCESS; } - -pf_status_t pf_get_handle(pf_context_t* pf, pf_handle_t* handle) { - if (!g_initialized) - return PF_STATUS_UNINITIALIZED; - - *handle = pf->file; - return PF_STATUS_SUCCESS; -} diff --git a/common/src/protected_files/protected_files.h b/common/src/protected_files/protected_files.h index 4354f3e6fe..ce46bdc9af 100644 --- a/common/src/protected_files/protected_files.h +++ b/common/src/protected_files/protected_files.h @@ -26,11 +26,6 @@ typedef uint8_t pf_mac_t[PF_MAC_SIZE]; typedef uint8_t pf_key_t[PF_KEY_SIZE]; typedef uint8_t pf_keyid_t[32]; /* key derivation material */ -extern pf_key_t g_pf_mrenclave_key; -extern pf_key_t g_pf_mrsigner_key; -extern pf_key_t g_pf_wrap_key; -extern bool g_pf_wrap_key_set; - typedef enum _pf_status_t { PF_STATUS_SUCCESS = 0, PF_STATUS_UNKNOWN_ERROR = -1, @@ -296,16 +291,6 @@ pf_status_t pf_set_size(pf_context_t* pf, uint64_t size); */ pf_status_t pf_rename(pf_context_t* pf, const char* new_path); -/*! - * \brief Get underlying handle of a PF. - * - * \param pf PF context. - * \param[out] handle Handle to the backing file. - * - * \returns PF status. - */ -pf_status_t pf_get_handle(pf_context_t* pf, pf_handle_t* handle); - /*! * \brief Flush any pending data of a protected file to disk. * diff --git a/common/src/protected_files/protected_files_format.h b/common/src/protected_files/protected_files_format.h index 4473dc9ae4..0e33a10bc2 100644 --- a/common/src/protected_files/protected_files_format.h +++ b/common/src/protected_files/protected_files_format.h @@ -14,7 +14,6 @@ #include -#include "list.h" #include "protected_files.h" #define PF_FILE_ID 0x46505f5346415247 /* GRAFS_PF */ @@ -53,9 +52,7 @@ typedef struct _metadata_encrypted { typedef uint8_t metadata_encrypted_blob_t[sizeof(metadata_encrypted_t)]; -#define METADATA_NODE_SIZE PF_NODE_SIZE - -typedef uint8_t metadata_padding_t[METADATA_NODE_SIZE - +typedef uint8_t metadata_padding_t[PF_NODE_SIZE - (sizeof(metadata_plain_t) + sizeof(metadata_encrypted_blob_t))]; typedef struct _metadata_node { @@ -102,18 +99,16 @@ static_assert(sizeof(encrypted_node_t) == PF_NODE_SIZE, "sizeof(encrypted_node_t #define MAX_PAGES_IN_CACHE 48 -typedef enum { +enum { FILE_MHT_NODE_TYPE = 1, FILE_DATA_NODE_TYPE = 2, -} mht_node_type_e; +}; // make sure these are the same size static_assert(sizeof(mht_node_t) == sizeof(data_node_t), "sizeof(mht_node_t) == sizeof(data_node_t)"); -DEFINE_LIST(_file_node); typedef struct _file_node { - LIST_TYPE(_file_node) list; uint8_t type; uint64_t node_number; struct _file_node* parent; @@ -127,7 +122,6 @@ typedef struct _file_node { data_node_t data; } decrypted; } file_node_t; -DEFINE_LISTP(_file_node); typedef struct { uint32_t index;