diff mbox series

[1/2] lib: fwts_tpm: move some tpm funcitons to lib

Message ID 20201016120113.29486-1-ivan.hu@canonical.com
State New
Headers show
Series [1/2] lib: fwts_tpm: move some tpm funcitons to lib | expand

Commit Message

ivanhu Oct. 16, 2020, 12:01 p.m. UTC
No function changed.``

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/lib/include/fwts_tpm.h          |  3 ++
 src/lib/src/Makefile.am             |  1 +
 src/lib/src/fwts_tpm.c              | 68 +++++++++++++++++++++++++++++
 src/tpm/tpmevlogdump/tpmevlogdump.c | 57 ++++--------------------
 4 files changed, 80 insertions(+), 49 deletions(-)
 create mode 100644 src/lib/src/fwts_tpm.c

Comments

Colin Ian King Oct. 16, 2020, 1:07 p.m. UTC | #1
On 16/10/2020 13:01, Ivan Hu wrote:
> No function changed.``
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/lib/include/fwts_tpm.h          |  3 ++
>  src/lib/src/Makefile.am             |  1 +
>  src/lib/src/fwts_tpm.c              | 68 +++++++++++++++++++++++++++++
>  src/tpm/tpmevlogdump/tpmevlogdump.c | 57 ++++--------------------
>  4 files changed, 80 insertions(+), 49 deletions(-)
>  create mode 100644 src/lib/src/fwts_tpm.c
> 
> diff --git a/src/lib/include/fwts_tpm.h b/src/lib/include/fwts_tpm.h
> index 6e32e334..07fdb40b 100644
> --- a/src/lib/include/fwts_tpm.h
> +++ b/src/lib/include/fwts_tpm.h
> @@ -167,6 +167,9 @@ typedef struct {
>  */
>  } __attribute__ ((packed)) fwts_tcg_pcr_event2;
>  
> +void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str);
> +uint8_t fwts_tpm_get_hash_size(TPM2_ALG_ID hash);
> +
>  PRAGMA_POP
>  
>  #endif
> diff --git a/src/lib/src/Makefile.am b/src/lib/src/Makefile.am
> index 4593bb82..2c3c1cb7 100644
> --- a/src/lib/src/Makefile.am
> +++ b/src/lib/src/Makefile.am
> @@ -107,6 +107,7 @@ libfwts_la_SOURCES = 		\
>  	fwts_stringextras.c 	\
>  	fwts_summary.c 		\
>  	fwts_text_list.c 	\
> +	fwts_tpm.c		\
>  	fwts_tty.c 		\
>  	fwts_uefi.c 		\
>  	fwts_wakealarm.c 	\
> diff --git a/src/lib/src/fwts_tpm.c b/src/lib/src/fwts_tpm.c
> new file mode 100644
> index 00000000..f196ff8c
> --- /dev/null
> +++ b/src/lib/src/fwts_tpm.c
> @@ -0,0 +1,68 @@
> +/*
> + * Copyright (C) 2020 Canonical
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> + *
> + */
> +
> +#include "fwts.h"
> +#include "fwts_tpm.h"
> +
> +/*
> + *  fwts_tpm_data_hexdump
> + *	hex dump of a tpm event log data
> + */
> +void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
> +{
> +	size_t i;
> +
> +	fwts_log_info_verbatim(fw, "%s: ", str);
> +	for (i = 0; i < size; i += 16) {
> +		char buffer[128];
> +		size_t left = size - i;
> +
> +		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
> +		fwts_log_info_verbatim(fw, "%s", buffer + 2);
> +	}
> +}
> +
> +/*
> + *  fwts_tpm_evlog_type_to_string
> + *	get hash size
> + */
> +uint8_t fwts_tpm_get_hash_size (TPM2_ALG_ID hash)
> +{
> +	uint8_t sz;
> +
> +	switch (hash) {
> +	case TPM2_ALG_SHA1:
> +		sz = TPM2_SHA1_DIGEST_SIZE;
> +		break;
> +	case TPM2_ALG_SHA256:
> +		sz = TPM2_SHA256_DIGEST_SIZE;
> +		break;
> +	case TPM2_ALG_SHA384:
> +		sz = TPM2_SHA384_DIGEST_SIZE;
> +		break;
> +	case TPM2_ALG_SHA512:
> +		sz = TPM2_SHA512_DIGEST_SIZE;
> +		break;
> +	default:
> +		sz = 0;
> +		break;
> +	}
> +
> +	return sz;
> +}
> diff --git a/src/tpm/tpmevlogdump/tpmevlogdump.c b/src/tpm/tpmevlogdump/tpmevlogdump.c
> index 94bb5cc1..8254554f 100644
> --- a/src/tpm/tpmevlogdump/tpmevlogdump.c
> +++ b/src/tpm/tpmevlogdump/tpmevlogdump.c
> @@ -26,22 +26,7 @@
>  
>  #include "fwts_tpm.h"
>  
> -#define FWTS_TPM_LOG_DIR_PATH		"/sys/kernel/security"
> -
> -
> -static void tpmevlogdump_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
> -{
> -	size_t i;
> -
> -	fwts_log_info_verbatim(fw, "%s: ", str);
> -	for (i = 0; i < size; i += 16) {
> -		char buffer[128];
> -		size_t left = size - i;
> -
> -		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
> -		fwts_log_info_verbatim(fw, "%s", buffer + 2);
> -	}
> -}
> +#define FWTS_TPM_LOG_DIR_PATH	"/sys/kernel/security"
>  
>  static char *tpmevlogdump_evtype_to_string (fwts_tpmlog_event_type event_type)
>  {
> @@ -172,32 +157,6 @@ static char *tpmevlogdump_hash_to_string (TPM2_ALG_ID hash)
>  
>  	return str;
>  }
> -
> -static uint8_t tpmevlogdump_get_hash_size (TPM2_ALG_ID hash)
> -{
> -	uint8_t sz;
> -
> -	switch (hash) {
> -	case TPM2_ALG_SHA1:
> -		sz = TPM2_SHA1_DIGEST_SIZE;
> -		break;
> -	case TPM2_ALG_SHA256:
> -		sz = TPM2_SHA256_DIGEST_SIZE;
> -		break;
> -	case TPM2_ALG_SHA384:
> -		sz = TPM2_SHA384_DIGEST_SIZE;
> -		break;
> -	case TPM2_ALG_SHA512:
> -		sz = TPM2_SHA512_DIGEST_SIZE;
> -		break;
> -	default:
> -		sz = 0;
> -		break;
> -	}
> -
> -	return sz;
> -}
> -
>  static char *tpmevlogdump_pcrindex_to_string (uint32_t pcr)
>  {
>  
> @@ -270,7 +229,7 @@ static size_t tpmevlogdump_specid_event_dump(fwts_framework *fw, uint8_t *data,
>  	fwts_log_info_verbatim(fw, "PCRIndex:                    0x%8.8" PRIx32 "(%s)", pc_event->pcr_index, str_info);
>  	str_info = tpmevlogdump_evtype_to_string(pc_event->event_type);
>  	fwts_log_info_verbatim(fw, "EventType:                   0x%8.8" PRIx32 "(%s)", pc_event->event_type, str_info);
> -	tpmevlogdump_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
> +	fwts_tpm_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
>  	fwts_log_info_verbatim(fw, "EventSize:                   0x%8.8" PRIx32, pc_event->event_data_size);
>  
>  	pdata += sizeof(fwts_pc_client_pcr_event);
> @@ -318,7 +277,7 @@ static size_t tpmevlogdump_specid_event_dump(fwts_framework *fw, uint8_t *data,
>  			fwts_log_info(fw, "Cannot get enough length for dumping data.");
>  			return 0;
>  		}
> -		tpmevlogdump_data_hexdump(fw, pdata, vendor_info_size, "  vendorInfo");
> +		fwts_tpm_data_hexdump(fw, pdata, vendor_info_size, "  vendorInfo");
>  		len_remain -= vendor_info_size;
>  	}
>  
> @@ -357,7 +316,7 @@ static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
>  		}
>  		str_info = tpmevlogdump_hash_to_string(alg_id);
>  		fwts_log_info_verbatim(fw, "  Digests[%d].AlgId: 0x%4.4" PRIx16 "(%s)", i, alg_id, str_info);
> -		hash_size = tpmevlogdump_get_hash_size(alg_id);
> +		hash_size = fwts_tpm_get_hash_size(alg_id);
>  		if (!hash_size) {
>  			fwts_log_info(fw, "Unknown hash algorithm. Aborted.");
>  			return 0;
> @@ -369,7 +328,7 @@ static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
>  			fwts_log_info(fw, "Cannot get enough length for dumping data.");
>  			return 0;
>  		}
> -		tpmevlogdump_data_hexdump(fw, pdata, hash_size, "  Digest");
> +		fwts_tpm_data_hexdump(fw, pdata, hash_size, "  Digest");
>  		pdata += hash_size;
>  		len_remain -= hash_size;
>  	}
> @@ -386,7 +345,7 @@ static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
>  
>  	fwts_log_info_verbatim(fw, "  EventSize:        %" PRIu32, event_size);
>  	if (event_size > 0) {
> -		tpmevlogdump_data_hexdump(fw, pdata, event_size, "  Event");
> +		fwts_tpm_data_hexdump(fw, pdata, event_size, "  Event");
>  		len_remain -= event_size;
>  	}
>  
> @@ -435,10 +394,10 @@ static void tpmevlogdump_event_dump(fwts_framework *fw, uint8_t *data, size_t le
>  		fwts_log_info_verbatim(fw, "PCRIndex:	0x%8.8" PRIx32 "(%s)", pc_event->pcr_index, str_info);
>  		str_info = tpmevlogdump_evtype_to_string(pc_event->event_type);
>  		fwts_log_info_verbatim(fw, "EventType:	0x%8.8" PRIx32 "(%s)", pc_event->event_type, str_info);
> -		tpmevlogdump_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
> +		fwts_tpm_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
>  		fwts_log_info_verbatim(fw, "EventSize:	0x%8.8" PRIx32, pc_event->event_data_size);
>  		if (pc_event->event_data_size > 0)
> -			tpmevlogdump_data_hexdump(fw, pc_event->event, pc_event->event_data_size, "Event");
> +			fwts_tpm_data_hexdump(fw, pc_event->event, pc_event->event_data_size, "Event");
>  		pdata += (sizeof(fwts_pc_client_pcr_event) + pc_event->event_data_size);
>  		len -= (sizeof(fwts_pc_client_pcr_event) + pc_event->event_data_size);
>  	}
> 
Acked-by: Colin Ian King <colin.king@canonical.com>
Alex Hung Oct. 16, 2020, 8:09 p.m. UTC | #2
On 2020-10-16 6:01 a.m., Ivan Hu wrote:
> No function changed.``
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/lib/include/fwts_tpm.h          |  3 ++
>  src/lib/src/Makefile.am             |  1 +
>  src/lib/src/fwts_tpm.c              | 68 +++++++++++++++++++++++++++++
>  src/tpm/tpmevlogdump/tpmevlogdump.c | 57 ++++--------------------
>  4 files changed, 80 insertions(+), 49 deletions(-)
>  create mode 100644 src/lib/src/fwts_tpm.c
> 
> diff --git a/src/lib/include/fwts_tpm.h b/src/lib/include/fwts_tpm.h
> index 6e32e334..07fdb40b 100644
> --- a/src/lib/include/fwts_tpm.h
> +++ b/src/lib/include/fwts_tpm.h
> @@ -167,6 +167,9 @@ typedef struct {
>  */
>  } __attribute__ ((packed)) fwts_tcg_pcr_event2;
>  
> +void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str);
> +uint8_t fwts_tpm_get_hash_size(TPM2_ALG_ID hash);
> +
>  PRAGMA_POP
>  
>  #endif
> diff --git a/src/lib/src/Makefile.am b/src/lib/src/Makefile.am
> index 4593bb82..2c3c1cb7 100644
> --- a/src/lib/src/Makefile.am
> +++ b/src/lib/src/Makefile.am
> @@ -107,6 +107,7 @@ libfwts_la_SOURCES = 		\
>  	fwts_stringextras.c 	\
>  	fwts_summary.c 		\
>  	fwts_text_list.c 	\
> +	fwts_tpm.c		\
>  	fwts_tty.c 		\
>  	fwts_uefi.c 		\
>  	fwts_wakealarm.c 	\
> diff --git a/src/lib/src/fwts_tpm.c b/src/lib/src/fwts_tpm.c
> new file mode 100644
> index 00000000..f196ff8c
> --- /dev/null
> +++ b/src/lib/src/fwts_tpm.c
> @@ -0,0 +1,68 @@
> +/*
> + * Copyright (C) 2020 Canonical
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> + *
> + */
> +
> +#include "fwts.h"
> +#include "fwts_tpm.h"
> +
> +/*
> + *  fwts_tpm_data_hexdump
> + *	hex dump of a tpm event log data
> + */
> +void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
> +{
> +	size_t i;
> +
> +	fwts_log_info_verbatim(fw, "%s: ", str);
> +	for (i = 0; i < size; i += 16) {
> +		char buffer[128];
> +		size_t left = size - i;
> +
> +		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
> +		fwts_log_info_verbatim(fw, "%s", buffer + 2);
> +	}
> +}
> +
> +/*
> + *  fwts_tpm_evlog_type_to_string
> + *	get hash size
> + */
> +uint8_t fwts_tpm_get_hash_size (TPM2_ALG_ID hash)
> +{
> +	uint8_t sz;
> +
> +	switch (hash) {
> +	case TPM2_ALG_SHA1:
> +		sz = TPM2_SHA1_DIGEST_SIZE;
> +		break;
> +	case TPM2_ALG_SHA256:
> +		sz = TPM2_SHA256_DIGEST_SIZE;
> +		break;
> +	case TPM2_ALG_SHA384:
> +		sz = TPM2_SHA384_DIGEST_SIZE;
> +		break;
> +	case TPM2_ALG_SHA512:
> +		sz = TPM2_SHA512_DIGEST_SIZE;
> +		break;
> +	default:
> +		sz = 0;
> +		break;
> +	}
> +
> +	return sz;
> +}
> diff --git a/src/tpm/tpmevlogdump/tpmevlogdump.c b/src/tpm/tpmevlogdump/tpmevlogdump.c
> index 94bb5cc1..8254554f 100644
> --- a/src/tpm/tpmevlogdump/tpmevlogdump.c
> +++ b/src/tpm/tpmevlogdump/tpmevlogdump.c
> @@ -26,22 +26,7 @@
>  
>  #include "fwts_tpm.h"
>  
> -#define FWTS_TPM_LOG_DIR_PATH		"/sys/kernel/security"
> -
> -
> -static void tpmevlogdump_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
> -{
> -	size_t i;
> -
> -	fwts_log_info_verbatim(fw, "%s: ", str);
> -	for (i = 0; i < size; i += 16) {
> -		char buffer[128];
> -		size_t left = size - i;
> -
> -		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
> -		fwts_log_info_verbatim(fw, "%s", buffer + 2);
> -	}
> -}
> +#define FWTS_TPM_LOG_DIR_PATH	"/sys/kernel/security"
>  
>  static char *tpmevlogdump_evtype_to_string (fwts_tpmlog_event_type event_type)
>  {
> @@ -172,32 +157,6 @@ static char *tpmevlogdump_hash_to_string (TPM2_ALG_ID hash)
>  
>  	return str;
>  }
> -
> -static uint8_t tpmevlogdump_get_hash_size (TPM2_ALG_ID hash)
> -{
> -	uint8_t sz;
> -
> -	switch (hash) {
> -	case TPM2_ALG_SHA1:
> -		sz = TPM2_SHA1_DIGEST_SIZE;
> -		break;
> -	case TPM2_ALG_SHA256:
> -		sz = TPM2_SHA256_DIGEST_SIZE;
> -		break;
> -	case TPM2_ALG_SHA384:
> -		sz = TPM2_SHA384_DIGEST_SIZE;
> -		break;
> -	case TPM2_ALG_SHA512:
> -		sz = TPM2_SHA512_DIGEST_SIZE;
> -		break;
> -	default:
> -		sz = 0;
> -		break;
> -	}
> -
> -	return sz;
> -}
> -
>  static char *tpmevlogdump_pcrindex_to_string (uint32_t pcr)
>  {
>  
> @@ -270,7 +229,7 @@ static size_t tpmevlogdump_specid_event_dump(fwts_framework *fw, uint8_t *data,
>  	fwts_log_info_verbatim(fw, "PCRIndex:                    0x%8.8" PRIx32 "(%s)", pc_event->pcr_index, str_info);
>  	str_info = tpmevlogdump_evtype_to_string(pc_event->event_type);
>  	fwts_log_info_verbatim(fw, "EventType:                   0x%8.8" PRIx32 "(%s)", pc_event->event_type, str_info);
> -	tpmevlogdump_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
> +	fwts_tpm_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
>  	fwts_log_info_verbatim(fw, "EventSize:                   0x%8.8" PRIx32, pc_event->event_data_size);
>  
>  	pdata += sizeof(fwts_pc_client_pcr_event);
> @@ -318,7 +277,7 @@ static size_t tpmevlogdump_specid_event_dump(fwts_framework *fw, uint8_t *data,
>  			fwts_log_info(fw, "Cannot get enough length for dumping data.");
>  			return 0;
>  		}
> -		tpmevlogdump_data_hexdump(fw, pdata, vendor_info_size, "  vendorInfo");
> +		fwts_tpm_data_hexdump(fw, pdata, vendor_info_size, "  vendorInfo");
>  		len_remain -= vendor_info_size;
>  	}
>  
> @@ -357,7 +316,7 @@ static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
>  		}
>  		str_info = tpmevlogdump_hash_to_string(alg_id);
>  		fwts_log_info_verbatim(fw, "  Digests[%d].AlgId: 0x%4.4" PRIx16 "(%s)", i, alg_id, str_info);
> -		hash_size = tpmevlogdump_get_hash_size(alg_id);
> +		hash_size = fwts_tpm_get_hash_size(alg_id);
>  		if (!hash_size) {
>  			fwts_log_info(fw, "Unknown hash algorithm. Aborted.");
>  			return 0;
> @@ -369,7 +328,7 @@ static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
>  			fwts_log_info(fw, "Cannot get enough length for dumping data.");
>  			return 0;
>  		}
> -		tpmevlogdump_data_hexdump(fw, pdata, hash_size, "  Digest");
> +		fwts_tpm_data_hexdump(fw, pdata, hash_size, "  Digest");
>  		pdata += hash_size;
>  		len_remain -= hash_size;
>  	}
> @@ -386,7 +345,7 @@ static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
>  
>  	fwts_log_info_verbatim(fw, "  EventSize:        %" PRIu32, event_size);
>  	if (event_size > 0) {
> -		tpmevlogdump_data_hexdump(fw, pdata, event_size, "  Event");
> +		fwts_tpm_data_hexdump(fw, pdata, event_size, "  Event");
>  		len_remain -= event_size;
>  	}
>  
> @@ -435,10 +394,10 @@ static void tpmevlogdump_event_dump(fwts_framework *fw, uint8_t *data, size_t le
>  		fwts_log_info_verbatim(fw, "PCRIndex:	0x%8.8" PRIx32 "(%s)", pc_event->pcr_index, str_info);
>  		str_info = tpmevlogdump_evtype_to_string(pc_event->event_type);
>  		fwts_log_info_verbatim(fw, "EventType:	0x%8.8" PRIx32 "(%s)", pc_event->event_type, str_info);
> -		tpmevlogdump_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
> +		fwts_tpm_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
>  		fwts_log_info_verbatim(fw, "EventSize:	0x%8.8" PRIx32, pc_event->event_data_size);
>  		if (pc_event->event_data_size > 0)
> -			tpmevlogdump_data_hexdump(fw, pc_event->event, pc_event->event_data_size, "Event");
> +			fwts_tpm_data_hexdump(fw, pc_event->event, pc_event->event_data_size, "Event");
>  		pdata += (sizeof(fwts_pc_client_pcr_event) + pc_event->event_data_size);
>  		len -= (sizeof(fwts_pc_client_pcr_event) + pc_event->event_data_size);
>  	}
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/include/fwts_tpm.h b/src/lib/include/fwts_tpm.h
index 6e32e334..07fdb40b 100644
--- a/src/lib/include/fwts_tpm.h
+++ b/src/lib/include/fwts_tpm.h
@@ -167,6 +167,9 @@  typedef struct {
 */
 } __attribute__ ((packed)) fwts_tcg_pcr_event2;
 
+void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str);
+uint8_t fwts_tpm_get_hash_size(TPM2_ALG_ID hash);
+
 PRAGMA_POP
 
 #endif
diff --git a/src/lib/src/Makefile.am b/src/lib/src/Makefile.am
index 4593bb82..2c3c1cb7 100644
--- a/src/lib/src/Makefile.am
+++ b/src/lib/src/Makefile.am
@@ -107,6 +107,7 @@  libfwts_la_SOURCES = 		\
 	fwts_stringextras.c 	\
 	fwts_summary.c 		\
 	fwts_text_list.c 	\
+	fwts_tpm.c		\
 	fwts_tty.c 		\
 	fwts_uefi.c 		\
 	fwts_wakealarm.c 	\
diff --git a/src/lib/src/fwts_tpm.c b/src/lib/src/fwts_tpm.c
new file mode 100644
index 00000000..f196ff8c
--- /dev/null
+++ b/src/lib/src/fwts_tpm.c
@@ -0,0 +1,68 @@ 
+/*
+ * Copyright (C) 2020 Canonical
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "fwts.h"
+#include "fwts_tpm.h"
+
+/*
+ *  fwts_tpm_data_hexdump
+ *	hex dump of a tpm event log data
+ */
+void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
+{
+	size_t i;
+
+	fwts_log_info_verbatim(fw, "%s: ", str);
+	for (i = 0; i < size; i += 16) {
+		char buffer[128];
+		size_t left = size - i;
+
+		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
+		fwts_log_info_verbatim(fw, "%s", buffer + 2);
+	}
+}
+
+/*
+ *  fwts_tpm_evlog_type_to_string
+ *	get hash size
+ */
+uint8_t fwts_tpm_get_hash_size (TPM2_ALG_ID hash)
+{
+	uint8_t sz;
+
+	switch (hash) {
+	case TPM2_ALG_SHA1:
+		sz = TPM2_SHA1_DIGEST_SIZE;
+		break;
+	case TPM2_ALG_SHA256:
+		sz = TPM2_SHA256_DIGEST_SIZE;
+		break;
+	case TPM2_ALG_SHA384:
+		sz = TPM2_SHA384_DIGEST_SIZE;
+		break;
+	case TPM2_ALG_SHA512:
+		sz = TPM2_SHA512_DIGEST_SIZE;
+		break;
+	default:
+		sz = 0;
+		break;
+	}
+
+	return sz;
+}
diff --git a/src/tpm/tpmevlogdump/tpmevlogdump.c b/src/tpm/tpmevlogdump/tpmevlogdump.c
index 94bb5cc1..8254554f 100644
--- a/src/tpm/tpmevlogdump/tpmevlogdump.c
+++ b/src/tpm/tpmevlogdump/tpmevlogdump.c
@@ -26,22 +26,7 @@ 
 
 #include "fwts_tpm.h"
 
-#define FWTS_TPM_LOG_DIR_PATH		"/sys/kernel/security"
-
-
-static void tpmevlogdump_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
-{
-	size_t i;
-
-	fwts_log_info_verbatim(fw, "%s: ", str);
-	for (i = 0; i < size; i += 16) {
-		char buffer[128];
-		size_t left = size - i;
-
-		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
-		fwts_log_info_verbatim(fw, "%s", buffer + 2);
-	}
-}
+#define FWTS_TPM_LOG_DIR_PATH	"/sys/kernel/security"
 
 static char *tpmevlogdump_evtype_to_string (fwts_tpmlog_event_type event_type)
 {
@@ -172,32 +157,6 @@  static char *tpmevlogdump_hash_to_string (TPM2_ALG_ID hash)
 
 	return str;
 }
-
-static uint8_t tpmevlogdump_get_hash_size (TPM2_ALG_ID hash)
-{
-	uint8_t sz;
-
-	switch (hash) {
-	case TPM2_ALG_SHA1:
-		sz = TPM2_SHA1_DIGEST_SIZE;
-		break;
-	case TPM2_ALG_SHA256:
-		sz = TPM2_SHA256_DIGEST_SIZE;
-		break;
-	case TPM2_ALG_SHA384:
-		sz = TPM2_SHA384_DIGEST_SIZE;
-		break;
-	case TPM2_ALG_SHA512:
-		sz = TPM2_SHA512_DIGEST_SIZE;
-		break;
-	default:
-		sz = 0;
-		break;
-	}
-
-	return sz;
-}
-
 static char *tpmevlogdump_pcrindex_to_string (uint32_t pcr)
 {
 
@@ -270,7 +229,7 @@  static size_t tpmevlogdump_specid_event_dump(fwts_framework *fw, uint8_t *data,
 	fwts_log_info_verbatim(fw, "PCRIndex:                    0x%8.8" PRIx32 "(%s)", pc_event->pcr_index, str_info);
 	str_info = tpmevlogdump_evtype_to_string(pc_event->event_type);
 	fwts_log_info_verbatim(fw, "EventType:                   0x%8.8" PRIx32 "(%s)", pc_event->event_type, str_info);
-	tpmevlogdump_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
+	fwts_tpm_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
 	fwts_log_info_verbatim(fw, "EventSize:                   0x%8.8" PRIx32, pc_event->event_data_size);
 
 	pdata += sizeof(fwts_pc_client_pcr_event);
@@ -318,7 +277,7 @@  static size_t tpmevlogdump_specid_event_dump(fwts_framework *fw, uint8_t *data,
 			fwts_log_info(fw, "Cannot get enough length for dumping data.");
 			return 0;
 		}
-		tpmevlogdump_data_hexdump(fw, pdata, vendor_info_size, "  vendorInfo");
+		fwts_tpm_data_hexdump(fw, pdata, vendor_info_size, "  vendorInfo");
 		len_remain -= vendor_info_size;
 	}
 
@@ -357,7 +316,7 @@  static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
 		}
 		str_info = tpmevlogdump_hash_to_string(alg_id);
 		fwts_log_info_verbatim(fw, "  Digests[%d].AlgId: 0x%4.4" PRIx16 "(%s)", i, alg_id, str_info);
-		hash_size = tpmevlogdump_get_hash_size(alg_id);
+		hash_size = fwts_tpm_get_hash_size(alg_id);
 		if (!hash_size) {
 			fwts_log_info(fw, "Unknown hash algorithm. Aborted.");
 			return 0;
@@ -369,7 +328,7 @@  static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
 			fwts_log_info(fw, "Cannot get enough length for dumping data.");
 			return 0;
 		}
-		tpmevlogdump_data_hexdump(fw, pdata, hash_size, "  Digest");
+		fwts_tpm_data_hexdump(fw, pdata, hash_size, "  Digest");
 		pdata += hash_size;
 		len_remain -= hash_size;
 	}
@@ -386,7 +345,7 @@  static size_t tpmevlogdump_event_v2_dump(fwts_framework *fw, uint8_t *data, size
 
 	fwts_log_info_verbatim(fw, "  EventSize:        %" PRIu32, event_size);
 	if (event_size > 0) {
-		tpmevlogdump_data_hexdump(fw, pdata, event_size, "  Event");
+		fwts_tpm_data_hexdump(fw, pdata, event_size, "  Event");
 		len_remain -= event_size;
 	}
 
@@ -435,10 +394,10 @@  static void tpmevlogdump_event_dump(fwts_framework *fw, uint8_t *data, size_t le
 		fwts_log_info_verbatim(fw, "PCRIndex:	0x%8.8" PRIx32 "(%s)", pc_event->pcr_index, str_info);
 		str_info = tpmevlogdump_evtype_to_string(pc_event->event_type);
 		fwts_log_info_verbatim(fw, "EventType:	0x%8.8" PRIx32 "(%s)", pc_event->event_type, str_info);
-		tpmevlogdump_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
+		fwts_tpm_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest");
 		fwts_log_info_verbatim(fw, "EventSize:	0x%8.8" PRIx32, pc_event->event_data_size);
 		if (pc_event->event_data_size > 0)
-			tpmevlogdump_data_hexdump(fw, pc_event->event, pc_event->event_data_size, "Event");
+			fwts_tpm_data_hexdump(fw, pc_event->event, pc_event->event_data_size, "Event");
 		pdata += (sizeof(fwts_pc_client_pcr_event) + pc_event->event_data_size);
 		len -= (sizeof(fwts_pc_client_pcr_event) + pc_event->event_data_size);
 	}